I am trying to use a custom indicator in a strategy to backtest using a 4 hour period. I am attempting to calculate the current and previous indicator value using the following code...
Object[] result = indicators.calculateIndicator(instrument, period, new OfferSide[] {offerSide},"MyIndicator", new IIndicators.AppliedPrice[]{appliedPrice}, new Object[]{macd1Fast,macd1Slow, macd2Fast, macd2Slow, maType.ordinal(),maType2.ordinal()}, Filter.WEEKENDS, 2, bar.getTime(), 0);
Where the period is the 4 hour period. I call this every 5 minutes.
When I run the strategy using a demo account, the returned indicator values are correct. The following shows the current value of the indicator calculated every five minutes when running the strategy in a demo account...
2018-08-24 20:20:00 Curr Fast Score:268636.1520462199 2018-08-24 20:15:00 Curr Fast Score:272076.5230735722 2018-08-24 20:10:01 Curr Fast Score:274042.4493739013 2018-08-24 20:05:00 Curr Fast Score:271093.5599234077 2018-08-24 20:00:00 Curr Fast Score:285838.0071815603 2018-08-24 19:55:00 Curr Fast Score:279448.7467022932 2018-08-24 19:50:00 Curr Fast Score:284363.5624545371 2018-08-24 19:45:00 Curr Fast Score:281906.1545780599
When I run the strategy using the historical tester, I get the same result returned every five minutes for the entire 4 hour candle. The calculated values represent the calculated value at the end of the 4 hour candle (the strategy in effect sees 4 hours ahead at the start of the 4 hour candle)
07:15:00 Curr Fast Score:-13780.751096970078 07:10:00 Curr Fast Score:-13780.751096970078 07:05:00 Curr Fast Score:-13780.751096970078 07:00:00 Curr Fast Score:-13780.751096970078 06:55:00 Curr Fast Score:-13780.751096970078 06:50:00 Curr Fast Score:-13780.751096970078 06:45:00 Curr Fast Score:-13780.751096970078 06:40:00 Curr Fast Score:-13780.751096970078
How can I correctly calculate the current and previous value of the indicator with a 4 hour period every 5 minutes using the historical tester?
|