Indicator Catalog

Indicator catalog article aims to summarize and describe usage of indicators used in JForex API. For an overview of indicator usage from a strategy please refer to Indicators overview.

We assume the following values for the indicator calls in the examples below:

Instrument instrument = Instrument.EURUSD;
Period period = Period.ONE_MIN;
IBar prevBar = history.getBar(instrument, period, OfferSide.BID, 1); //previous bar/candle
int candlesBefore = 1;
int candleAfter = 0;
int shift = 1;

Alligator

Alligator indicator helps to determine the presence and absence of a trend as well as its direction.

indicator_catalog_1

You can call the alligator indicator using a special method alligator()or the universal method calculateIndicator() declared in IIndicators interface: Assume that we have an instrument and a period variable already defined. We need to calculate Alligator values for a Jaw Time Period: 13, a Teeth Time Period: 8 and a Lips Time Period: 5

  • Calculate indicator values using a shift. A result is a double array which contains 3 double values (Alligator Jaw, Alligator Teeth and Alligator Lips) for the last bar(shift =1):
double[] alligator = indicators.alligator(instrument, period, OfferSide.BID, AppliedPrice.CLOSE,
    13, 8, 5, 
    1);
  • Calculate indicator values for a bar range between a candle before and a candle after parameters. Return result is array of array with Aligator values for each candle from the specified candle before a parameter:
double[][] alligator = indicators.alligator( 
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE,
    13, 8, 5, 
    Filter.NO_FILTER, candleBefore, prevBar.getTime(), candleAfter);
  • Calculate indicator values between the specified bar range. In this example value just previous bar values will be calculated:
double[][] alligator = indicators.alligator(
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE,
    13, 8, 5, 
    prevBar.getTime(), prevBar.getTime());

In these methods 5, 6 and 7 parameters mean:
Jaw Time Period: 13
Teeth Time Period: 8
Lips Time Period: 5

  • Calculate indicator values using the universal method and specifying a shift. Return result: an array of objects which contains double values :
int shift = 1;
Object[] alligatorUniversal =  indicators.calculateIndicator(
    instrument, period, new OfferSide[] {OfferSide.BID},
    "ALLIGATOR", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
    new Object[]{13, 8, 5},
    shift);

All these 4 methods return same alligator result for the last candle

Please see the Indicator calculation parameters for more details about indicators methods parameters.

Average Price

The Average Price indicator shows an average bar price.

indicator_catalog_2

Below is an example how to get the previous bar average price value using 3 special avgPrice methods and one universal calculateIndicator method:

  • shift parameter defines candle shift, if it is set to 1 then we will get indicator value for the previous candle. The returned result is the previous bar average double value.
double avgPrice = indicators.avgPrice(instrument, period, OfferSide.BID,  shift);
  • Parameters number 4 and 5 prevBar.getTime() describe bars' time range where indicator values will be found. The returned result is double array with one element, because time range is limited to a single bar (namely, the previous bar).
double[] avgPrice = indicators.avgPrice(
    instrument, period, OfferSide.BID, 
    prevBar.getTime(), prevBar.getTime());
  • candlesBefore defines the candle starting from which the indicator value will be calculated

    prevBar.getTime() defines the candle's start time from which candleBefore and candleAfter parameters will be shifted

    candleAfter defines candle count after the specified bar for which indicator value will be calculated.

double[] avgPrice = indicators.avgPrice(
    instrument, period, OfferSide.BID,  Filter.NO_FILTER, 
    candlesBefore, prevBar.getTime(), candleAfter);

Example1. candlesBefore = 2; candleAfter = 1; time is set in parameter #6 for last closed bar. The average value will be calculated for current, previous and next-to-last candles:

indicator_catalog_4

Example2. candlesBefore = 2; candleAfter = 1; time is set in parameter #6 for next-to-last bar. The average value will be calculated for previous, second before current and third before current candles:

  • Calculate indicator values using the universal method and specifying a shift. The returned result: array of objects which contains one double value. Please see the Indicator calculation parameters for more details about indicators methods parameters.
Object[] avgPriceUniversal = indicators.calculateIndicator(
    instrument, period, new OfferSide[] {OfferSide.BID},
    "AVGPRICE", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
    new Object[] {}, 
    shift);

Awesome

Indicator preview on the chart:

indicator_catalog_5

Initializing necessary variables:

int fasterMaTimePeriod = 5;
MaType fasterMaType = MaType.SMA;
int slowerMaTimePeriod = 34;
MaType slowerMaType = MaType.SMA;

Let's give examples how to get a previous bar awesome values using 3 special awesome methods and one universal calculateIndicator method.

  • To get awesome indicator values for previous candle specifying shift equals to 1. Return result are array of double containing 3 values.
double[] awesome = indicators.awesome(
    instrument, period, OfferSide.BID, appliedPrice,
    fasterMaTimePeriod, fasterMaType, slowerMaTimePeriod, slowerMaType,
    shift);
  • To get awesome indicator values for previous candle specifying previous bar start time as time range. Return result are array of double arrays containing 3 values.
double[][] awesome = indicators.awesome(
    instrument, period, OfferSide.BID, appliedPrice,
    fasterMaTimePeriod, fasterMaType, slowerMaTimePeriod, slowerMaType, 
    prevBar.getTime(), prevBar.getTime());
  • To get awesome values for 2 previous bars from and to bar time must be changed and then passed to the awesome method:
IBar lastBar = history.getBar(instrument, Period.ONE_MIN, OfferSide.BID,1);
IBar nextToLastBar = history.getBar(instrument, Period.ONE_MIN, OfferSide.BID, 2);
double[][] awesome = indicators.awesome(
    instrument, period, OfferSide.BID, appliedPrice,
    fasterMaTimePeriod, fasterMaType, slowerMaTimePeriod, slowerMaType, 
    nextToLastBar.getTime(), lastBar.getTime());
  • To get awesome indicator values for previous candle specifying bar start time prevBar.getTime() and candle count before this bar candlesBefore and after candleAfter:
double[][] awesome = indicators.awesome(
    instrument, period, OfferSide.BID, appliedPrice,
    fasterMaTimePeriod, fasterMaType, slowerMaTimePeriod, slowerMaType,
    Filter.NO_FILTER, candlesBefore, prevBar.getTime(), candleAfter);
  • And last example shows how to get last bar awesome indicator values using universal method:
Object[] awesomeUniversal = indicators.calculateIndicator(
    instrument, period, new OfferSide[] {OfferSide.BID},
    "AWESOME", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, 
    new Object[]{ fasterMaTimePeriod, MaType.SMA.ordinal(), slowerMaTimePeriod, MaType.SMA.ordinal()},
    1);

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Beta

Shows discrepancy between specified prices

indicator_catalog_6

First we need to initialize necessary fields (time period, two prices and two applied price):

int timePeriod = 5;
OfferSide side1 = OfferSide.BID;
OfferSide side2 = OfferSide.BID;
AppliedPrice appliedPrice1 = AppliedPrice.OPEN;
AppliedPrice appliedPrice2 = AppliedPrice.CLOSE;
  • To get beta indicator value for previous candle specifying shift:
double beta = indicators.beta(
    instrument, period, side1, appliedPrice1, side2, appliedPrice2,
    timePeriod,
    shift);

The example above returns double beta indicator value.

  • To get beta indicator value for previous candle specifying previous bar start time as time range:
double[] beta = indicators.beta(
    instrument, period, side1, appliedPrice1, side2, appliedPrice2,
    timePeriod,
    prevBar.getTime(), prevBar.getTime());

The example above returns array of double containing 1 value.

  • To get beta indicator value for previous candle specifying bar start time prevBar.getTime() and candle count before this bar candlesBefore and after candleAfter:
double[] beta = indicators.beta(
    instrument, period, side1, appliedPrice1, side2, appliedPrice2, 
    timePeriod, 
    Filter.NO_FILTER, candlesBefore, prevBar.getTime(), candleAfter);

The example above returns array of double containing 1 value.

  • And last example shows how to get last bar beta indicator values using universal method:
Object[] betaUniversal = indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {side1, side2},
    "BETA", new IIndicators.AppliedPrice[] {appliedPrice1, appliedPrice2},
    new Object[]{timePeriod},
    1);

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Bollinger Bands

This indicator displays whether the market is quiet or whether the market is loud. When the market is quiet, the bands squeeze; and when the market is loud, the bands expand.

indicator_catalog_7

Let's give examples how to get a previous bar awesome values using 3 special bband methods and one universal calculateIndicator method. First we need to initialize necessary fields:

int timePeriod = 5;
MaType maType = MaType.EMA;
double nbDevDn = 2;
double nbDevUp = 2;
  • To get bollinger bands indicator values for previous candle specifying shift equals to 1. Return result are array of double containing 3 values.
 double[] bbands = indicators.bbands(
    instrument, period, OfferSide.BID, appliedPrice,
    timePeriod, nbDevUp, nbDevDn, maType,
    shift);
  • To get bollinger bands indicator values for previous candle specifying previous bar start time as time range. Return result are array of double arrays containing 3 values:
double[][] bbands = indicators.bbands(
    instrument, period, OfferSide.BID, appliedPrice,
    timePeriod, nbDevUp,nbDevDn, maType,
    prevBar.getTime(), prevBar.getTime());
  • To get bollinger bands indicator values for previous candle specifying bar start time prevBar.getTime() and candle count before this bar candlesBefore and after candleAfter. Return result are array of double arrays containing 3 values.
double[][] bbands = indicators.bbands(
    instrument, period, OfferSide.BID, appliedPrice,
    timePeriod, nbDevUp, nbDevDn, maType,
    Filter.NO_FILTER, candlesBefore, prevBar.getTime(), candleAfter);
  • And last example shows how to get last bar bollinger bands indicator values using universal method:
Object[] bbandsUniversal = indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {OfferSide.BID},
    "BBANDS", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, 
    new Object[]{timePeriod, nbDevUp, nbDevDn, MaType.EMA.ordinal()}
    1);

All above bollinger bands methods result array contains following values sequence:

  • 0 - Upper Band
  • 1 - Middle Band
  • 2 - Lower Band

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Butterworth

indicator_catalog_8

First we need to initialize time period:

int timePeriod = 34;
  • To get butterworth filter value for previous candle specifying shift:
double butterworth = indicators.butterworthFilter(
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE,
    timePeriod,
    shift);

The example above returns double value.

  • To get butterworth filter value for previous candle using time range:
double[] butterworth = indicators.butterworthFilter(
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE,
    timePeriod, 
    lastBarTime, lastBarTime);

The example above returns double array containing 1 value.

  • To get butterworth filter value for previous candle specifying bar start time prevBar.getTime() and candle count before this bar candlesBefore and after candleAfter:
double[] butterworth = indicators.butterworthFilter(
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 
    imePeriod,
    Filter.NO_FILTER, candlesBefore, prevBar.getTime(), candleAfter);

The example above returns double array containing 1 value.

  • The last example shows how to get last bar butterworth filter value using universal method
Object[] butterworthUniversal =  indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {OfferSide.BID},
    "BUTTERWORTH", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, 
    new Object[]{timePeriod},
    shift);

The example above returns array of object containing 1 double value.

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Channel Up

indicator_catalog_9

Channel Up indicator is the pattern indicator, and it can be called only by using a calculateIndicator method in the API. Let's create a channel up indicator usage example

First, we need to initialize necessary variables:

int x1 = 10; // Start Count of Bars on Sides 
int x2 = 20; // Bars on Sides Increment Count
double x3 = 50; // Centering Inaccuracy
double x4 = 10; // Equality Inaccuracy 
Period period = Period.FIVE_MINS;
Instrumentinstrument = Instrument.EURUSD;

The method below returns abstract indicator outputs for previous 2,000 bars (we pass the start time of 2,000 bar and start time of the last bar to the calculateIndicator method). We use such big range, because channel up indicator rarely appears on the chart. This indicator provides 3 outp

  • prices for the upper asymptote,
  • prices for bottom asymptote,
  • and prices for the pattern indicator body line.////
Object[] channelOutputs  =  indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {OfferSide.BID}, 
    "CHANNEL_UP", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, 
    new Object[]{x1, x2, x3, x4}, 
    history.getBar(instrument, period, OfferSide.BID, 2000).getTime(),
    history.getBar(instrument, period, OfferSide.BID,1).getTime());

Cast each abstract indicator output to the object array:

for (int i = 0; i < channelOutputs.length; i++) {
        if (channelOutputs != null) {
                Object[] channelOutput = (Object[])channelOutputs[i];
        }
}

Then, it is necessary to cast object to the PatternIndicatorOutput instance which contains pattern objects:

                for (Object object : channelOutput) {
                        PatternIndicatorOutput output = (PatternIndicatorOutput)object;
                        List<PatternObject> patterObjects = output.getPatternObjects();         
                }

Last step is to iterate through pattern objects and display them. Pattern objects are stored in the IndexValue collection:

if (patterObjects != null) {
    for (PatternObject patterObject : patterObjects) {
        if (patterObject.getPattern() != null) {
            for (IndexValue indexValue : patterObject.getPattern()) {
                console.getOut().println(indexValue.getIndex() + " " + indexValue.getValue());
            }
        }
    }
}

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Hilbert Transform - Instantaneous Trendline

indicator_catalog_10

  • To get ht_trendline indicator values for previous candle specifying shift:
double htTrend = indicators.ht_trendline(instrument, period, OfferSide.BID, AppliedPrice.CLOSE, shift);

The example above returns double value.

  • To get ht_trendline indicator value for previous candle using time range:
double[] htTrend = indicators.ht_trendline(
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 
    prevBar.getTime(), prevBar.getTime());

The example above returns array of double arrays containing 1 value

  • To get ht_trendline indicator value for previous candle specifying bar start time prevBar.getTime() and candle count before this bar candlesBefore and after candleAfter:
double[] htTrend = indicators.ht_trendline(
    instrument, period, OfferSide.BID, AppliedPrice.CLOSE, Filter.NO_FILTER, 
    candlesBefore, prevBar.getTime(), candleAfter);

The example above returns array of double arrays containing 1 value

  • The last example shows how to get last bar ht_trendline indicator values using universal method:
Object[] htTrendUniversal =  indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {OfferSide.BID},
    "HT_TRENDLINE", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
    new Object[]{},
    shift);

The example above returns array of object containing 1 double value.

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

MinMax

Indicator MINMAX calculates the lowest and the highest prices for the specified period respectively.

indicator_catalog_12

3 methods are provided for the MINMAX indicator by the IIndicators interface. The following example demonstrates the use of these methods.

Define instrument, period and shift:

Instrument instrument = Instrument.EURUSD;
Period period = Period.ONE_HOUR;
int shift = 1;
  • Calculate indicator values for the previous bar:
double[] minMax = indicators.minMax(instrument, period, OfferSide.ASK, AppliedPrice.CLOSE, 5, shift);
  • Calculate indicator values for the specified range:
long prevBarTime = history.getBar(instrument, period, OfferSide.ASK, shift).getTime();
ouble[][] minMax = indicators.minMax(
    instrument, period, OfferSide.ASK, AppliedPrice.CLOSE,
    5,
    prevBarTime, prevBarTime);
  • Calculate indicator values for the specified range using a filter:
int candlesBefore = 1, candlesAfter = 0;
double[][] minMax = indicators.minMax(
    instrument, period, OfferSide.ASK, AppliedPrice.CLOSE, 
    5,
    Filter.NO_FILTER, candlesBefore, prevBarTime, candlesAfter);     
  • Also, you can use universal methods to calculate the MINMAX indicator values:
Object[] minMax = indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {OfferSide.ASK},
    "MINMAX", new AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, 
    new Object[]{5}, 
    shift);

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Standard Deviation

Indicator "stddev" calculates the standard deviation of specified prices.

indicator_catalog_13

This indicator has two specific input parameters:

  • nbDev - each output of stddev is multiplied by nbDev, this allows to stretch or squeeze the indicator output vertically.
  • timePeriod - the number of candles used to compute stddev

To initialize the parameters:

int timePeriod = 5;
double nbDev = 1;
  • To get stddev indicator values for a candle specifying shift:
double stddev = indicators.stdDev(
    instrument, period, OfferSide.ASK, AppliedPrice.CLOSE, timePeriod, nbDev, shift);

The example above returns standard deviation for a ask candle (specified by shift) calculated from previous candle close prices.

  • To get stddev indicator values for previous candle using time range:
double[] stddev = indicators.stdDev(
    instrument, period, OfferSide.ASK, AppliedPrice.CLOSE, timePeriod,
    nbDev, askBar.getTime(), askBar.getTime());
  • To get stddev values for 2 previous bars, from and to bar time must be changed and then passed to the stddev method:
long lastBarTime = history.getBar(instrument, Period.ONE_MIN, OfferSide.BID,1).getTime();
long nextToLastBarTime = history.getBar(instrument, Period.ONE_MIN, OfferSide.BID, 2).getTime();
double[] stddev = indicators.stdDev(
    instrument, period, OfferSide.ASK, AppliedPrice.CLOSE,
    timePeriod, nbDev,
    nextToLastBarTime, lastBarTime);
  • To get stddev indicator values for previous candle specifying bar start time askBar.getTime() and candle count before this bar candlesBefore and after candlesAfter:
double[] stddev = indicators.stdDev(
    instrument, period, OfferSide.ASK, AppliedPrice.CLOSE,
    timePeriod, nbDev,
    Filter.NO_FILTER, candlesBefore, askBar.getTime(), candlesAfter);
  • The last example shows how to get last bar stddev indicator values using universal method:
Object[] stddev = indicators.calculateIndicator(
    instrument, period, new  OfferSide[] {OfferSide.BID},
    "STDDEV", new IIndicators.AppliedPrice[] {AppliedPrice.CLOSE}, 
    new Object[]{timePeriod, nbDev},
    shift);
double result = (Double) stddev[0];

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

Stochastic

The stochastics indicator shows instrument overbought and oversold in the market. When two stochastics lines are above 80, then it means that the instrument is overbought and when two stochastics lines are below 20, it means that the instrument is oversold.

indicator_catalog_14

First we need to initialize necessary fields(periods and moving average types)

int fastKPeriod = 5;
int slowKPeriod = 3;
MaType slowKMaType = MaType.SMA;
int slowDPeriod = 3;
MaType slowDMaType = MaType.SMA;
  • To get stochastics indicator values for previous candle specifying shift:
double[] stoch = indicators.stoch(
    instrument, period, OfferSide.BID,
    fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType,
    shift);

The example above returns array of double containing 2 values: stoch[0] - slow % K value and stoch[1] - slow %D value.

  • To get stochastics indicator values for previous candle using time range:
double[][] stoch = indicators.stoch(
    instrument, period, OfferSide.BID, 
    fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType, 
    prevBar.getTime(), prevBar.getTime());

The example above returns array of double arrays containing 2 values: stoch[0][0] - slow % K value; stoch[1][0] - slow %D value.

  • To get stochastics values for 2 previous bars, from and to bar time must be changed and then passed to the stoch method:
long lastBarTime = history.getBar(instrument, Period.ONE_MIN, OfferSide.BID,1).getTime();
long nextToLastBarTime = history.getBar(instrument, Period.ONE_MIN, OfferSide.BID, 2).getTime();
double[][] stoch = indicators.stoch(
    instrument, period, OfferSide.BID,
    fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType,
    nextToLastBarTime, lastBarTime);

This example returns array of double arrays containing 4 values:

 stoch[0][1] - last candle slow % K value.

 stoch[1][1] - last candle slow %D value.

 stoch[0][0] - next-to-last candle slow % K value.

 stoch[1][0] - next-to-last candle slow %D value.
  • To get stochastics indicator values for previous candle specifying bar start timeВ prevBar.getTime()В and candle count before this bar candlesBeforeВ and afterВ candleAfter:
double[][] stoch = indicators.stoch(
    instrument, period, OfferSide.BID, 
    fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType, 
    Filter.NO_FILTER, candlesBefore, prevBar.getTime(), candlesAfter);

The example above returns array of double arrays containing 2 values.

  • The last example shows how to get last bar stochastics indicator values using universal method:
Object[] stochUniversal = indicators.calculateIndicator(
    instrument, period, new OfferSide[] {OfferSide.BID}, 
    "STOCH", new IIndicators.AppliedPrice[] {AppliedPrice.CLOSE}, 
    new Object[]{ fastKPeriod, slowKPeriod, slowKMaType.ordinal(), slowDPeriod, slowDMaType.ordinal()}, 
    shift);

Please see the Indicator calculation parameters page for more details about indicators methods parameters.

The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.