Download MetaTrader 5

Linear Weighted Moving Average?

To add comments, please log in or register
Paul
530
Paul  
Does anyone know where I can find a Linear Weighted Moving Average?

Thanks!
Keith Watford
Moderator
10612
Keith Watford  
In the standard Moving Average that comes with MT4
Paul
530
Paul  

Want stand alone.  Looking for code.  So I can bring values into EA.

Thanks!

Carl Schreiber
7365
Carl Schreiber  
Read the editor's reference for iMA
Ernst Van Der Merwe
5128
Ernst Van Der Merwe  

In the MovingAverages.mqh header file.

//+------------------------------------------------------------------+
//| Linear Weighted Moving Average                                   |
//+------------------------------------------------------------------+
double LinearWeightedMA(const int position,const int period,const double &price[])
  {
//---
   double result=0.0,sum=0.0;
   int    i,wsum=0;
//--- calculate value
   if(position>=period-1 && period>0)
     {
      for(i=period;i>0;i--)
        {
         wsum+=i;
         sum+=price[position-i+1]*(period-i+1);
        }
      result=sum/wsum;
     }
//---
   return(result);
  }
To add comments, please log in or register