I wrote the following code in the onBar() method to skip further processing if the trend is not going up:
double[] fastMA = JForexContext.getIndicators().ma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 40, IIndicators.MaType.SMA, Filter.ALL_FLATS, 2, barTime, 0);
double[] slowMA = JForexContext.getIndicators().ma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 80, IIndicators.MaType.SMA, Filter.ALL_FLATS, 2, barTime, 0); if (fastMA[0] < slowMA[0]) return;
In theory, there should be no trade if fastMA is below slowMA. However during backtesting, I saw several trades under this condition. Am I doing something wrong in the code, or is the MA calculation not working properly in backtesting?
Thanks,
Vinh
|