[MQL5]How to use SmoothedMA

 

Hi,

since documentation is rather slim I would like have an explanation of the signature of SmoothedMA in MovingAverages.mqh.

double SmoothedMA(const int position,const int period,const double prev_value,const double &price[])


So lets say I want to use this function to implement my own Moving Average Indicator ( I know it is already there ).

Now position is which bar we are at I guess, and I guess 0 is the most recent on the chart since for example Open[0] will give me the opening price of the rightermost bar.

Period is clear i think, moving averages need periods and it is an int.

I have no idea what prev_value means or should mean or what it used for.

price is obvious again, what array we have to iterate over.


After looking at the code of SmoothedMA I came to the realization that position should never be 0 ( or infact smaller than the period )  because it will always return 0, so I don't know what position means either.


Could somebody please explain what those parameters mean?

 

i have exactly the same problem like you

 

By definition a smoothed moving average is calculated from previous value, except the first one. So you have the prev_value parameter.

Position is the index of the value to calculate. Positions 0 to Period - 2 don't have a value. Position Period - 1 is the first value that can be calculated (needs 'Period' previous element in the array).