iMA function is not right?

 

I use iMa function in my code, but I campare with indicator shipped with mt4, the value iMa computed is not right.

the code I use iMa is below:

while(i>=0) // Loop for uncounted bars
{
Buf_0[i]=iMA(NULL,0,MA_Period,0,MODE_SMA,PRICE_CLOSE,i );
// Value of 0 buffer on i bar


i--; // Calculating index of the next bar

}

I think it should be SMA(CLOSE,10) .

but when put it compare with MA10(SIMPLE MA) indicator, they are so different .

did i do something wrong . any one help.

Files:
test.mq4  2 kb
 

the compare pic, red is MA indicator (origin one),yellow is mine (with iMa function )

the MA indicator line variable is same to iMa ( price is close price, sample ma, periord = 10 )


MA indicator setting

 
muyuan11 wrote >>

I use iMa function in my code, but I campare with indicator shipped with mt4, the value iMa computed is not right.

the code I use iMa is below:

while(i>=0) // Loop for uncounted bars
{
Buf_0[i]=iMA(NULL,0,MA_Period,0,MODE_SMMA,PRICE_CLOSE,i );
// Value of 0 buffer on i bar


i--; // Calculating index of the next bar

}

I think it should be SMA(CLOSE,10) .

but when put it compare with MA10(SIMPLE MA) indicator, they are so different .

did i do something wrong . any one help.

I think you should use MODE_SMA, not MODE_SMMA (smoothed average) in your call to the iMA function.

 
any help
 

flimbo
wrote >>

I think you should use MODE_SMA, not MODE_SMMA (smoothed average) in your call to the iMA function.

yes, I modified it to MODE_SMA, but still different

I think iMa maybe has bug,I must make sure I do not do something wrong first

Files:
test_1.mq4  2 kb
 

sorry, it is my fault,

flimbo is right

I use wrong para, iMA is ok

I close this thread