Discrepancy in iMA values in strategy tester

 

I noticed that the values returned by iMA for an EA are different from the ones shown on the graph by the corresponding indicator. I have written a small EA to test this:

int start()
  {
   double EMA;
      
   EMA = iMA(NULL,0,10,0,1,PRICE_CLOSE,0);
   Alert("EMA=",EMA);
  }

I have done backtests on EURUSD, H4 and the values printed on the Alert statement differ from those on the indicator attached to the same chart. I also noticed the same behaviour with other indicators that are based on MAs like the MACD. Is this a bug in MQL4? If yes, is there a fix or way around it?

Thanks

Nikos

 
Is this a bug in MQL4?

No, that would have been seen and fixed years ago.

What indicator? What settings? Are you sure you are using period=10, EMA, on the close?

 

I don't see a problem:

Data window is MA10 set for EMA and Close. Comment is iMA value for 10 periods and Close Price

http://screencast.com/t/YWUyNTVhNz

 
There can be discrepancies between tester and live chart with MAs of *very* long periods due to the fact that a backtest chart might not be initialized with enough bars before the start of the test. There was a discussion about this on FF a few months ago where someone used an EMA of 1000 bars. This showed different values in the backtest than in the live chart due to the way an exponential moving average is calculated. I can't remember exactly how easy it was to reproduce, some people tried it, some could not reproduce it and and some seemed to be able to reproduce it. It seemed to depend on the available history.
Reason: