Download MetaTrader 5
To add comments, please log in or register
Interested in earning money via MQL5 Cloud Network? Enter your profile!
Paul
529
Paul 2015.03.06 19:43 
Does anyone know where I can find a Linear Weighted Moving Average?

Thanks!
Keith Watford
Moderator
7861
Keith Watford 2015.03.06 20:13  
In the standard Moving Average that comes with MT4
Paul
529
Paul 2015.03.06 20:20  

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

Thanks!

Carl Schreiber
5926
Carl Schreiber 2015.03.06 22:12  
Read the editor's reference for iMA
Ernst Van Der Merwe
4396
Ernst Van Der Merwe 2015.03.07 06:13  

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