Libraries: MovingAverages

 

MovingAverages:

The MovingAverages library is a part of Standard package of MetaTrader 5 client terminal.

The library contains functions for calculation of different types of moving averages. Totally, there are 8 functions that can be divided into 2 groups of functions of the same type, each containing 4 of them.

The first group contains functions that receive an array and simply return a value of a moving average at a specified position:

These functions are intended for obtaining the value of an average once for an array, and are not optimized for multiple calls. If you need to use a function from this group in a loop (to calculate values of an average and further write each calculated value into an array), you'll have to organize an optimal algorithm.

The second group of functions is intended for filling out the recipient array by values of a moving average based on the array of initial values:

  • SimpleMAOnBuffer() - fills out the output array buffer[] by values of a simple average from the price[] array;
  • ExponentialMAOnBuffer() - fills out the output array buffer[] by values of an exponential average from the price[] array;
  • SmoothedMAOnBuffer() - fills out the output array buffer[] by values of a smoothed average from the price[] array;
  • LinearWeightedMAOnBuffer() - fills out the output array buffer[] by values of a linear weighted average from the price[] array.

Author: MetaQuotes Software Corp.

 
Automated-Trading:

MovingAverages:

Author: MetaQuotes Software Corp.

Excuse me, what's the variable "position"?

double SimpleMA(const int position,const int period,const double &price[])
 
double SimpleMA( const int position, const int period, const double &price[])
  {
   double result= 0.0 ;
 //--- check period 
   if (period> 0 && period<=(position+ 1 ))
     {
       for ( int i= 0 ; i<period; i++)
         result+=price[position-i];

      result/=period;
     }

   return (result);
  }

Good morning

Is it clearer like this?

 
Gerard Willia G J B M Dinh Sy #:

Good morning

Is it clearer like this?

No, I already saw it thinking that position was the first bar to calculate as example 20 if I want 20 period but I'm not sure. 

price has [position - 1] (and not +1) because mql5 doesn't set as series by default? 

 
Milko Vivaldi # :
because mql5 doesn't set as series by default? 

The as_series is according to...
It will depend on what you are looking at.

But to make an SMA, we don't care.
It doesn't come into play, unlike the average exhibition where meaning is important.

 
Gerard Willia G J B M Dinh Sy #:

The as_series is according to...
It will depend on what you are looking at.

But to make an SMA, we don't care.
It doesn't come into play, unlike the average exhibition where meaning is important.

Ok, therefore if I want SMA with 5 periods which position I have to write?