Hi there,
I am attempting to call the ATR indicator to create an ATR Band but I am having difficulties understanding how this should be done. The first problem being is that there is little info on what parameters it takes without going to the TA-LIB site and then trying decode the source (unless there is some proper docco on each indicator & their parameters?)
From what I understand so far, the ATR is expecting an array with OHLCV which is given by the input:
inputParameterInfos =
new InputParameterInfo[]{new InputParameterInfo("Input data", InputParameterInfo.Type.PRICE)};
When I try to feed this into the ATR indicator, I seem to be getting a graph that is shifted forward by the lookback value (14). Could someone kindly point out what I have done incorrectly in this code:
double atrBuffer[] = new double[endIndex - startIndex + 2 + atrIndicator.getLookback()];
//multPrice - copy the section of the array
double[][] multPrice = new double[5][endIndex - startIndex + 1 + getLookback()];
for (int arrc=0, j=0; arrc < 5; arrc++, j++)
for (int resIndex = 0; resIndex <= endIndex; resIndex++) {
//Inputs: 0 open, 1 close, 2 high, 3 low, 4 volume
multPrice[j][resIndex] = inputs[0][arrc][resIndex];
}
// call the atr indicator
atrIndicator.setInputParameter(0, multPrice);
atrIndicator.setOptInputParameter(0, timePeriod);
atrIndicator.setOutputParameter(0, atrBuffer);
IndicatorResult atrResult = atrIndicator.calculate(startIndex - 1, endIndex);
// Set output values which is Close + atr*multipler
int i = 0, k =0;
for (i = 1, k = atrResult.getNumberOfElements(); i < k; i++) {
outputs[0][i - 1] = multPrice[1][i] + atrBuffer[i]*multipler;
outputs[1][i - 1] = multPrice[1][i] + atrBuffer[i]*multipler;
}
return new IndicatorResult(startIndex, i-1);
Appreciate your help!