iMA of higher timeframe doesn't work in strategy tester

 

Hi Traders,

i need some help. I want to use values of indicators of higher timeframes in the strategy tester. But this doesn't work. 

I start the strategy tester on M15 and have an indicator attached. This indicator prints the values of iMA of the higher timeframe M30 in the onTick function .

When the strategy tester is started then the first output of the M30 value is correct. While the strategy tester is running the output of the the M30 value does not change.

It seems that the value of the higher timeframe is read correctly only once, in the moment when the indicator is initialized. If I pause the strategy tester after many hours of candle data are processed and press the "compile" button in MetaEditor for this indicator then the correct value of the iMA of the timeframe M30 is printed. But if i resume the strategy tester then again, only the old value (wrong) value of the M30 is printed.

Following two lines produce the output:

double higherMA = iMA(Symbol(), 30, 13,8,MODE_SMMA,PRICE_MEDIAN,1);;
Print("higherMA " + higherMA);

Following screenshot shows the output:


 
double higherMA = iMA(Symbol(), 30, 13,8,MODE_SMMA,PRICE_MEDIAN,1);;
  1. Don't mix apples and oranges. Get the shift of the PERIOD_M30 bar from the time of the current bar.
  2. Unless the chart is that specific pair/TF, you must handle 4066/4073 errors. See Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum