Having trouble with Ehlers High Pass Filter

 

Hello,

I am trying to make an indicator with Ehlers formula for a high pass filter with a user input cut off period. The formula Ehlers writes in is paper "Predictive Indicators for Effective Trading Strategies" is coded in EasyLanguage as follows:

//Highpass filter cyclic components whose periods are shorter than 48 bars
alpha1 = (Cosine(.707*360 / 48) + Sine (.707*360 / 48) -1) / Cosine(.707*360 / 48); 
HP  =  (1 -alpha1    /  2)*(1 -alpha1  /  2)*(Close -2*Close[1]  +  Close[2])  +  2*(1 -alpha1)*HP[1] -(1 -alpha1)*(1 -alpha1)*HP[2];


I wrote in mql4 the follwing excerpt:

 for (i=limit; i>=0; i--){
 alpha = MathCos(0.707*360/CutOff) + MathSin((0.707*360/CutOff)-1) / MathCos(0.707*360/CutOff);
 highPass[i] = (1-alpha/2) * (1-alpha/2) * (Close[i] - 2*Close[i+1] + Close[i+2]) + 2 * (1-alpha) * highPass[i+1] - (1-alpha) * (1-alpha) * highPass[i+2];
 }

Everything compiles fine with no errors or warnings but when attached to a chart the Data Window returns a value of "-nan(ind)" for the highPass buffer.
I'm assuming I have a syntax problem somewhere but I have not found out where. Does anyone have any ideas?
Thanks

 
brw32:

Hello,

I am trying to make an indicator with Ehlers formula for a high pass filter with a user input cut off period. The formula Ehlers writes in is paper "Predictive Indicators for Effective Trading Strategies" is coded in EasyLanguage as follows:


I wrote in mql4 the follwing excerpt:

Everything compiles fine with no errors or warnings but when attached to a chart the Data Window returns a value of "-nan(ind)" for the highPass buffer.
I'm assuming I have a syntax problem somewhere but I have not found out where. Does anyone have any ideas?
Thanks

(1-alpha)/2 isn't interpreted like (1-alpha/2)

Try this.

 
For all trigonometric calculations, 360 should be replaced by 2pi (6.283185).