Bug with iMACD?

 

I'm trying to get the current value for timeframe M15 on a M5 chart for MACD and the values I get for period [0] don't match what the MACD indicator shows me (using MTF MACD).

Code:

      MacdCurrent=iMACD(NULL,15,5,13,1,PRICE_CLOSE,MODE_MAIN,0);
      MacdPrevious=iMACD(NULL,15,5,13,1,PRICE_CLOSE,MODE_MAIN,1);
      
      ObjectCreate("mt_1",OBJ_LABEL,0,0,0);
      ObjectSetText("mt_1","MACD[0] = " + DoubleToStr(MacdCurrent, 4) + " | MACD[1] = " + DoubleToStr(MacdPrevious, 4),9,"Arial Bold",White);
      ObjectSet("mt_1",OBJPROP_CORNER,0);
      ObjectSet("mt_1",OBJPROP_XDISTANCE,2);
      ObjectSet("mt_1",OBJPROP_YDISTANCE,170);

The MacdPrevious shows the correct value as it is the first completed bar [1], but the MacdCurrent does not match with what I'm getting from the indicator on the same M15 timeframe with the same settings. Can anyone explain why this is?


I've also tried iOsMA and had the same results.

 
Tester limitation, you can not get bar zero data (other timeframes/pairs)
 

Why is this a limitation in the tester?

 
WHRoeder:
Tester limitation, you can not get bar zero data (other timeframes/pairs)

My own testing doesn't indicate that this is true. We have disagreed about this before; https://www.mql5.com/en/forum/129856. As far as I know, an indicator which is called from an EA in backtesting can safely and successfully get values for higher timeframes. The MQL4 documentation at https://docs.mql4.com/series says "At the testing, price data of the same symbol but of another timeframe are modelled exactly, with the exception of volumes."

As far as I am aware, the issue lies with "MTF" indicators which are manually added to visual-mode backtesting - i.e. added by the user, not called by the EA being backtested. Such indicators sit half inside and half outside the backtesting sandbox. My understanding is that an indicator which is manually added to a chart in visual-mode backtesting sees the simulated values for the backtesting timeframe, but gets bar-end values on higher timeframes, not the simulated intra-bar values. Putting it crudely, if you manually add an "MTF" indicator to a visual-mode backtesting chart, then it can see into the future on higher timeframes.

Reason: