Chaikin Volatility in Expert only current bar

 

Unable to calculate Chaikin Volatility in Expert only for current bar


    double hl[30];
    double emahl[30];    
    for(int i=0; i< 30 ; i++) hl[i] = iHigh(_Symbol, _Period, i) - iLow(_Symbol, _Period, i); 
    
    ArraySetAsSeries(emahl, true);
    ExponentialMAOnBuffer(ArraySize(emahl) ,0,0,10,hl,emahl);
    double chv = ( emahl[0] - emahl[10] ) / emahl[10]*100;
    


The resulting value is totally different from built-in MT5 indicator.

Chaikin Volatility (CHV)
Chaikin Volatility (CHV)
  • www.mql5.com
Chaikin's volatility indicator calculates the spread between the maximum and minimum prices. It judges the value of volatility basing on the amplitude between the maximum and the minimum. Unlike Average True Range, Chaikin's indicator doesn't take gaps into account.
 
Sergei Toroshchin: Unable to calculate Chaikin Volatility in Expert only for current bar. The resulting value is totally different from built-in MT5 indicator.

You can't run an exponential moving average in the same way as a simple moving average.

An EMA requires at least 3.45×(Length+1) bars for 99.9% convergence. So for an EMA(30) you require at least 107 bars.

You will actually need much more to get the exact same value as the build in indicator.

Please read the following post ... https://www.mql5.com/en/forum/446533/page2#comment_46578197

 
Your topic has been moved to the section: Technical Indicators — In the future, please consider which section is most appropriate for your query.
 
Fernando Carreiro #:

You can't run an exponential moving average in the same way as a simple moving average.

An EMA requires at least 3.45×(Length+1) bars for 99.9% convergence. So for an EMA(30) you require at least 107 bars.

You will actually need much more to get the exact same value as the build in indicator.

Please read the following post ... https://www.mql5.com/en/forum/446533/page2#comment_46578197

In above code 30 is just fixed buffer size.

MA period is 10

 
Sergei Toroshchin #: In above code 30 is just fixed buffer size. MA period is 10

It is still not enough. You would need at least 38 bars for 99.9% convergence and even then it will not give the same value.

An EMA is an infinitely weighted moving average. It does not work like an SMA. Read the math explained in the Wikipedia link.

 
Fernando Carreiro #:

It is still not enough. You would need at least 38 bars for 99.9% convergence and even then it will not give the same value.

An EMA is an infinitely weighted moving average. It does not work like an SMA. Read the math explained in the Wikipedia link.

You don't hear me.

Its not a problem to increase buffer ...

but even if I do it I got totally different result 

For eg original indicator shows 35  ... I got -12 and so on and so on

 
Sergei Toroshchin #: You don't hear me. Its not a problem to increase buffer ... but even if I do it I got totally different result  For eg original indicator shows 35  ... I got -12 and so on and so on

Then please apply the same maths correctly ...

Code Base

Chaikin Volatility (CHV)

MetaQuotes, 2010.01.26 11:09

Chaikin's volatility indicator calculates the spread between the maximum and minimum prices. It judges the value of volatility basing on the amplitude between the maximum and the minimum. Unlike Average True Range, Chaikin's indicator doesn't take gaps into account.

Calculation:

H-L (i) = HIGH (i) - LOW (i)
H-L (i - 10) = HIGH (i - 10) - LOW (i - 10)
CHV = (EMA (H-L (i), 10) - EMA (H-L (i - 10), 10)) / EMA (H-L (i - 10), 10) * 100

where:

  • HIGH (i) - maximum price of current bar;
  • LOW (i) - minimum price of current bar;
  • HIGH (i - 10) - maximum price of the bar ten positions away from the current one;
  • LOW (i - 10) - minimum price of the bar ten positions away from the current one;
  • H-L (i) - difference between the maximum and the minimum price in the current bar;
  • H-L (i - 10) - difference between the maximum and the minimum price ten bars ago;
  • EMA - exponential moving average.
Reason: