Volatility indicator idea needs a help with MQL4 coding

1
Hello compadres!
Some of you might've already heard of the Kaufman Efficiency Ratio as it can be an effective filter for Reversal/Mean-Reversion trading.
My idea of using the indicator is quite simple, I want to have a filter line that tells when market's volatility is above or below the trading objective.
And so instead of having a static line like this:
Image
I attach the LWMA from the default Moving Average indicator, much better:
Image

Problem is I've been trying to put together an EA using a software that doesn't require coding knowledge but this particular one with two indis being used as one is a challenging case.
Hope everybody finding this useful and happy to give me hand with the coding.
Thanks for reading!

mql4 MA Codes:

Code: Select all

//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
double SimpleMA(const int position,const int period,const double &price[])
  {
//---
   double result=0.0;
//--- check position
   if(position>=period-1 && period>0)
     {
      //--- calculate value
      for(int i=0;i<period;i++) result+=price[position-i];
      result/=period;
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
double ExponentialMA(const int position,const int period,const double prev_value,const double &price[])
  {
//---
   double result=0.0;
//--- calculate value
   if(period>0)
     {
      double pr=2.0/(period+1.0);
      result=price[position]*pr+prev_value*(1-pr);
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| Smoothed Moving Average                                          |
//+------------------------------------------------------------------+
double SmoothedMA(const int position,const int period,const double prev_value,const double &price[])
  {
//---
   double result=0.0;
//--- check position
   if(period>0)
     {
      if(position==period-1)
        {
         for(int i=0;i<period;i++) result+=price[position-i];
         result/=period;
        }
      if(position>=period)
         result=(prev_value*(period-1)+price[position])/period;
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| 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);
  }


Re: Volatility indicator idea needs a help with MQL4 coding

2
TropicalSteve96 wrote: Sat Mar 19, 2022 4:00 am Hello compadres!
Some of you might've already heard of the Kaufman Efficiency Ratio as it can be an effective filter for Reversal/Mean-Reversion trading.
My idea of using the indicator is quite simple, I want to have a filter line that tells when market's volatility is above or below the trading objective.
And so instead of having a static line like this:
Image
I attach the LWMA from the default Moving Average indicator, much better:
Image

Problem is I've been trying to put together an EA using a software that doesn't require coding knowledge but this particular one with two indis being used as one is a challenging case.
Hope everybody finding this useful and happy to give me hand with the coding.
Thanks for reading!

mql4 MA Codes:

Code: Select all

//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
double SimpleMA(const int position,const int period,const double &price[])
  {
//---
   double result=0.0;
//--- check position
   if(position>=period-1 && period>0)
     {
      //--- calculate value
      for(int i=0;i<period;i++) result+=price[position-i];
      result/=period;
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
double ExponentialMA(const int position,const int period,const double prev_value,const double &price[])
  {
//---
   double result=0.0;
//--- calculate value
   if(period>0)
     {
      double pr=2.0/(period+1.0);
      result=price[position]*pr+prev_value*(1-pr);
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| Smoothed Moving Average                                          |
//+------------------------------------------------------------------+
double SmoothedMA(const int position,const int period,const double prev_value,const double &price[])
  {
//---
   double result=0.0;
//--- check position
   if(period>0)
     {
      if(position==period-1)
        {
         for(int i=0;i<period;i++) result+=price[position-i];
         result/=period;
        }
      if(position>=period)
         result=(prev_value*(period-1)+price[position])/period;
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+
//| 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);
  }
So you're looking for a ma of Kaufman efficiency ratio?

Re: Volatility indicator idea needs a help with MQL4 coding

5
TropicalSteve96 wrote: Sun Mar 20, 2022 3:37 am Hi Mrtools,
Perhaps I should've wrote more clearly, basically I just need an indicator of the Kaufman Efficiency Ratio with Averages already attached to it as parameter options.
Hope to have some help of your expertise.
Much thanks!
Another version.Not sure if it's a correct version or not.
These users thanked the author mrtools for the post:
Jedidiah


Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], cdk1212, DotNetDotCom [Bot], Proximic [Bot], Ricstar_8, RodrigoRT7, Sogou [Bot] and 76 guests