Hello,
I found a strange behavior of indicators when I'm backtesting. Where did I make the mistake?
I have the following code in the
onBar method:
IBar previousBar = history.getBar(instrument, period, OfferSide.BID, 1);
long currBarTime = previousBar.getTime();
int candlesBefore = 2, candlesAfter = 0;
double sma200[] = indicators.sma(myInstrument, myPeriod, OfferSide.BID, AppliedPrice.CLOSE,
200, Filter.NO_FILTER, candlesBefore, currBarTime, candlesAfter);
I want to use later this indicator to read the value for the previously closed bar, or the one before by using:
sma200[1] or sma200[0]
When I'm running my strategy in real time, everything seems fine, I'm getting the correct values for the indicator.
The problem starts when I run my strategy in the Historical Tester. If I compare the value of SMA200 of the chart of the Historical Tester with the value my code prints into the log I found a difference. Please note that the problem is only with the indicator values, the bar OHLC values are fine...