I am trying to write an indicator where outputs[i] = sma[i - shift], such that the output is a SMA lagging by 'shift' number of bars. Here's my code in calculate():
double[] smaData = new double[endIndex - startIndex + 1 + timePeriod];
sma.setInputParameter(0, inputs[0]);
sma.setOptInputParameter(0, timePeriod);
sma.setOutputParameter(0, smaData);
IndicatorResult dSmaResult = sma.calculate(startIndex - timePeriod, endIndex);
int i, k, j;
k = dSmaResult.getNumberOfElements();
j = dAtrResult.getNumberOfElements();
for (i = 0; i < Math.min(k, j); i++) {
outputs[0][i] = smaData[i + timePeriod];
}
return new IndicatorResult(startIndex, i);
The problem though, is that instead of receiving
lagging bars, the outputs are shifted
forward. How would I fix this please?