Metatrader4 and iMa "Wrong" evaluation

 

Hi everybody, I am new here just enjoying MQL....

I am referring to Metatrader4 Release 4.00 (Mac).

I noted an incongruence between the Mean value at 200 period as evaluated programmatically using the iMA function

and that evaluated by  the Moving Average Indicator on the graph.

Of course I am referring to the "Trend>Moving Average" Indicator who is reporting at time[0] on the Graph a value which

is different from iMA(Symbol(),PERIOD_CURRENT,200,0,MODE_SMMA,PRICE_CLOSE,0) .


If I am not wrong I suppose the call for the Simple Mean at 200 period is

val=iMA(Symbol(),PERIOD_CURRENT,200,0,MODE_SMMA,PRICE_CLOSE,0) using the Close value.

In my test the value obtained is not corresponding to that on the Indicator over the Graph, in this case 1782.66

iMa is returning instead a value of val=1780.35

On the Graph the value at the same bar is different.


Just to be clear: I used also Close[1] verifying the same incongruence at the previous bar.


Just to be more precise: I wrote the simple debug Function meanCloseValueOverPeiod(200) obtaining the Right value

as on the Graph. iMA gives however a different wrong value respect to the Indicator's Graph and also to the debug function.


Is there a Call Mistake? I just checked carefully the iMA parameters and of course I am

using the same Symbol and TimeFrame as on the Graph.


Here is the Debug function:

double meanCloseValueOverPeriod(int period){

int count=0; double mean=0.;

if (period<1) return Close[0];

for (int i = 0; i <= period; i++, count+=1.) mean=mean+Close[i];

return(mean/count);

} 


The Version (OS/Mac) I used is:

Metatrader4 Version 4.00 Build 1350

14 Oct. 2021

Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. al=iMA(Symbol(),PERIOD_CURRENT,200,0,MODE_SMMA,PRICE_CLOSE,0) using the Close value.
    SMMA is not the mean, SMA is.
  3. Never any reason to use the SMMA(L) it's equivalent to the EMA(2L-1).
              The Smoothed Moving Average or SMMA - How to Avoid It - NinjaTrader Programming | futures.io (March 23rd 2019)

 

Many thanks, and sorry for the editing... :-) All my best, Marco