IIndicator Methods

Indicators are intended for mathematical calculations based on candle prices (OHLC).

The IIndicator interface defines minimum requirements for indicator implementation. It contains:

  • an initialization function, which is called every time when a new indicator instance is created
  • methods for retrieving meta information
  • methods used by JForex for setting input and output arrays
  • a calculating method for the calculation logic

Method onStart

The method initializes an indicator. It will be called upon the indicator attaching to the chart or when a strategy is calculating indicator values. IIndicatorContext is passed as a parameter to the method. It provides access to the subsystems, which can be necessary for indicator functioning:

  • IConsole provides writing a message in the messages tab
  • IIndicatorsProvider provides an access to the registered indicators

onStart method is used for creating and filling objects, such as IndicatorInfo, InputParameterInfo, OptInputParameterInfo, and OutputParameterInfo. When the system stops proceeding the onStart method, the descriptor objects must not be changed, excepting shift parameter in OutputParameterInfo.

Method getXXXInfo

The group contains 4 methods:

  • getIndocatorInfo returns objects describing common indicator parameters, such as indicator name or number of outputs.
  • getInputParameterInfo returns objects describing indicator input parameters. Should it be one of the candle prices or all of the prices or maybe some average value.
  • getOptInputParameterInfo returns optional input parameter description. Optional inputs are modifiable values that are used for indicator calculation.
  • getOutputParameterInfo returns objects describing indicator output. The objects contain the output and the color attributes.

Method setXXXParameter

There are 3 methods that can be used to set an indicator parameters:

setInputParameter sets the input data array setOptInputParameter sets the optional input parameter setOutputParameter sets the output data array

A type of the passed parameter depends on the description objects returned by getXXXInfo methods.

Method getLookback

The getLookback method specifies a number of subsequent values before the indicator calculating reference point. For instance, if there is SMA indicator with time period of 20, it pre-requires 20 subsequent prices before the indicator calculating reference point to calculate a value for the reference point. If we pass input array of size 30 to the SMA indicator with time period 20, then SMA indicator can only be calculated starting from 21st position of the array due to there are no enough lookback price values for the previous 20 price values. The lookback in many indicators depends on parameters such as time period, etc.

Method getLookforward

The getLookforward method specifies a necessary number of future values after the indicator calculating reference point. For instance, a Fractal indicator requires 2 additional candles after the indicator calculating reference point to calculate a value for that reference point.

Method calculate

A main calulating method. It is called when all parameters are set. The method receives two indexes: startIndex is the index of the first element in input array for the corresponding output calculation, endIndex is the index of the last element in input array for the output calculation. In general, startIndex is set to 0, and ndIndexis set to a "length - 1" of the input array. For the indicator flexibility, it is not desirable to make any suggestions.

If startIndex is set to 0, it is not necessary that output has a value for corresponding input element with index 0. There isfirstValueIndex in returned IndicatorResult, which is the actual starting index of the element in input array. The same are for lookforward and lastValueIndex attribute of IndicatorResult. If there is input array with 30 elements and calculate method is called for SMA indicator with startIndex 0 and endIndex 29, then if there is time period of 21, indicator will have firstValueIndex 20 and lastValueIndex 29.

Method has to return IndicatorResult object. It has three attributes: firstValueIndex, lastValueIndex, and numberOfElements (a number of the calculated values written in output array).

Calculated values, which are equal to Integer.MIN_VALUE for int type array or Double.NaN for double type array, are threaded in a specific way. They are skipped during lines drawing. The line will be drawn from previous value to next not NaN value. A gap will be drawn, if output descriptor has gapAtNaN attribute set to true.

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