Newbie Question Regarding iMA Function

 

In order to calculate the MA slope, I need to obtain the MA value from a few periods back, say 5 periods prior to the current period. As best I can tell, the "shift" parameter in this function is the means for obtaining that value, and I have used "5" for that parameter. However, it does not retrieve the value from five periods ago. To check this out, I wrote the current MA value for several periods in a row, and then compared it to the MA value that was being retrieved when the "shift" parameter was set at "5". The values do not match ---- they are close (about 1 or 2 PIPs off) but they do not match. Can someone tell me what I am doing wrong?

 

The mistake can be your command, can you publish the MA code section ?


figurelli@fxcoder.com

 
FXtrader2008 wrote >>

In order to calculate the MA slope, I need to obtain the MA value from a few periods back, say 5 periods prior to the current period. As best I can tell, the "shift" parameter in this function is the means for obtaining that value, and I have used "5" for that parameter. However, it does not retrieve the value from five periods ago. To check this out, I wrote the current MA value for several periods in a row, and then compared it to the MA value that was being retrieved when the "shift" parameter was set at "5". The values do not match ---- they are close (about 1 or 2 PIPs off) but they do not match. Can someone tell me what I am doing wrong?

double EMA1=iMA(Symbol(),0,45,0,MODE_EMA,PRICE_CLOSE,1);
double EMA2=iMA(Symbol(),0,45,0,MODE_EMA,PRICE_CLOSE,5);

 
EADeveloper:

double EMA1=iMA(Symbol(),0,45,0,MODE_EMA,PRICE_CLOSE,1);
double EMA2=iMA(Symbol(),0,45,0,MODE_EMA,PRICE_CLOSE,5);

Thanks EA for posting those two function statements with the differing "shift" parameter. I had been using "0" for the current period, and was beginning to think that was my mistake since the MA value is calculated on the closing price, and the MA value will fluctuate until the current period closes. Thus as you have indicated, I should be looking at the MA value of the period just prior to the current period instead of the current period to ensure I don't retrieve a fluctuating value.

Reason: