## Ehlers Indicators for MT4

Moderators: xard777, mrtools, Banzai

NO EXTERNAL LINKS, SOURCE CODE REQUESTS OR MODIFICATION OF DECOMPILED INDICATORS. To avoid post deletion please follow the rules.

### Re: Ehlers Indicators for MT4

#241

I'm sorry as I don't understand the code well, so I don't know if this is helpful, but I have found 3 possible formula.

I can't speak towards the effectiveness or authenticity of these codes but hopefully one of them is what we are looking for!

This first code says that it is from John Ehler's "Cybernetic Analysis for Stocks and Futures"

Code: Select all

``````{Sine Wave indicator - //// From 'Cybernetic Analysis for Stocks and Futures' by John Ehlers //// code compiled by dn
} // plot on a subgraph separate from the price region.

Inputs: Price((H+L)/2), alpha(.07);

Vars: Smooth(0),Cycle(0),I1(0),Q1(0),I2(0),Q2(0),DeltaPhase(0),MedianDelta(0),MaxAmp(0),AmpFix(0),Re(0),Im(0),DC(0),
alpha1(0),InstPeriod(0),DCPeriod(0),count(0),SmoothCycle(0),RealPart(0),ImagPart(0),DCPhase(0);

Smooth = (Price+2*Price+2*Price+Price)/6;
Cycle = (1-.5*alpha)*(1-.5*alpha)*(Smooth-2*Smooth+Smooth)+2*(1-alpha)*Cycle-(1-alpha)*(1-alpha)*Cycle;
If CurrentBar <7 then Cycle=(Price-2*Price+Price)/4;
Q1=(.0962*Cycle+.5769*Cycle-.5769*Cycle-.0962*Cycle)*(.5+.08*InstPeriod);
I1 = Cycle;
If Q1<>0 and Q1<>0 then DeltaPhase=(I1/Q1-I1/Q1)/(1+I1*I1/(Q1*Q1));
If DeltaPhase <0.1 then DeltaPhase=0.1;
If DeltaPhase > 1.1 then DeltaPhase = 1.1;
MedianDelta = Median(DeltaPhase,5);
If MedianDelta =0 then DC=15 else DC=6.28318/MedianDelta+.5;
InstPeriod=.33*DC+.67*InstPeriod;
Value1 = .15*InstPeriod+.85*Value1;
DCPeriod = IntPortion(Value1);
RealPart = 0;
ImagPart = 0;
For count = 0 To DCPeriod - 1 begin
RealPart = RealPart + Sine(360 * count / DCPeriod) * (Cycle[count]);
ImagPart = ImagPart + Cosine(360 * count / DCPeriod) * (Cycle[count]);
End;
If AbsValue(ImagPart) > 0.001 then DCPhase = Arctangent(RealPart / ImagPart);
If AbsValue(ImagPart) <= 0.001 then DCPhase = 90 * Sign(RealPart);

DCPhase = DCPhase + 90;
If ImagPart < 0 then DCPhase = DCPhase + 180;
If DCPhase > 315 then DCPhase = DCPhase - 360;

Plot1(Sine(DCPhase), "Sine",blue);

{Note: This indicator tries to determine the current phase of the cycles you are in. A sinewave indicator has an advantage over
other oscillators such as RSI and Stochastic because it predicts rather than waits for confirmation. This assumes that the measured
phase has existed at least briefly in the past and will continue at least briefly into the future.
The phase languishes when the market is in a trend mode, and can even have a negative rate of change.
This indicator gives entry and exit signals 1/16th of a cycle period in advance of the cycle turning point
and seldom gives false whipsaw signals when the market is in a trend mode.}[/quote]

I found a website with a list of many of Ehler's formulas.

On that page the author has listed an a "special" version of the sinewave indicator.

It looks almost identical to the one written in Ehler's "Rocket Science for Traders Digital Signal Processing Applications" at first glance. If it is different or special, I can't tell how.

I have copied the code below.

[quote]{***************************************

Ehlers - Rocket Science for Traders
Sinewave Indicator (Figure 9.3)

****************************************}

Inputs:
Price((H+L)/2);

Vars:
Smooth(0),
Detrender(0),
I1(0),
Q1(0),
jI(0),
JQ(0),
I2(0),
Q2(0),
Re(0),
Im(0),
Period(0),
SmoothPeriod(0),
SmoothPrice(0),
DCPeriod(0),
RealPart(0),
Imagpart(0),
count(0),
DCPhase(0);

If CurrentBar > 5 Then Begin
Smooth = (4*Price + 3*Price + 2*Price + Price) / 10;
Detrender = (.0962*Smooth + .5769*Smooth - .5769*Smooth
- .0962*Smooth)*(.075*Period + .54);

Q1 = (.0962*Detrender + .5769*Detrender - .5769*Detrender
- .0962*Detrender)*(.075*Period + .54);
I1 = Detrender;

{Advance the phase of I1 and Q1 by 90 degrees}
jI = (.0962*I1 + .5769*I1 - .5769*I1 - .0962*I1)*(.075*Period + .54);
JQ = (.0962*Q1 + .5769*Q1 - .5769*Q1 - .0962*Q1)*(.075*Period + .54);

{Phasor addition for 3 bar averaging}
I2 = I1 - JQ;
Q2 = Q1 + jI;

{Smooth the I and Q components before applying the discriminator}
I2 = .2*I2 + .8*I2;
Q2 = .2*Q2 + .8*Q2;

{Homodyne Discriminator}
Re = I2*I2 + Q2*Q2;
Im = I2*Q2 - Q2*I2;
Re = .2*Re + .8*Re;
Im = .2*Im + .8*Im;

If Im <> 0 And Re <> 0 Then Period = 360/ArcTangent(Im/Re);
If Period > 1.5*Period Then Period = 1.5*Period;
If Period < .67*Period Then Period = .67*Period;
If Period < 6 Then Period = 6;
If Period > 50 Then Period = 50;
Period = .2*Period + .8*Period;
SmoothPeriod = .33*Period + .67*SmoothPeriod;

{Compute Dominant Cycle Phase}
SmoothPrice = (4*price + 3*Price + 2*Price + Price) / 10;
DCPeriod = IntPortion(SmoothPeriod + .5);
RealPart = 0;
ImagPart = 0;

For count = 0 To DCPeriod - 1 Begin
RealPart = RealPart + Sine(360*count/DCPeriod)*(SmoothPrice[count]);
ImagPart = ImagPart + CoSine(360*count/DCPeriod)*(SmoothPrice[count]);
End;

If AbsValue(ImagPart) > 0 Then DCPhase = Arctangent(RealPart/ImagPart);
If AbsValue(ImagPart) <= .001 Then DCPhase = DCPhase + 90*Sign(RealPart);
DCPhase = DCPhase + 90;

{Compensate for one bar lag of the Weighted Moving Average}
DCPhase = DCPhase + 360 / SmoothPeriod;

If ImagPart < 0 Then DCPhase = DCPhase + 180;
If DCPhase > 315 Then DCPhase = DCPhase - 360;

Plot1(Sine(DCPhase), "Sine");
End;[/quote]

The third is from Ehler's "Cycle Analytics for Traders Advanced Technical Trading Concepts", the "Even Better Sinewave Indicator"

[quote]{
Even Better Sinewave Indicator
}
Inputs:
Duration(40);
Vars:
alpha1(0),
HP(0),
a1(0),
b1(0),
c1(0),
c2(0),
c3(0),
Filt(0),
count(0),
Wave(0),
Pwr(0);

//HighPass filter cyclic components whose periods are
shorter than Duration input
alpha1 = (1 - Sine (360 / Duration)) / Cosine(360 /
Duration);
HP = .5*(1 + alpha1)*(Close - Close) + alpha1*HP;
//Smooth with a Super Smoother Filter from equation 3-3
a1 = expvalue(-1.414*3.14159 / 10);
b1 = 2*a1*Cosine(1.414*180 / 10);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(HP + HP) / 2 + c2*Filt + c3*Filt;
//3 Bar average of Wave amplitude and power
Wave = (Filt + Filt + Filt) / 3;
Pwr = (Filt*Filt + Filt*Filt + Filt*Filt) / 3;
//Normalize the Average Wave to Square Root of the Average
Power
Wave = Wave / SquareRoot(Pwr);
Plot1(Wave);``````

I will continue to search. I wish I could be of more help.

Also, is there a new/good version of either of the two following indicators?
• Ehler's Super Smoother Filter
• Ehler's MESA or MAMA (I have found the attached indicator on these forums, but it doesn't seem to work on my MT4. Not sure why, but I also have not yet tried to recompile it)

Thanks in advance for any help.
mama (mtf + alerts + arrows).ex4
mama (mtf + alerts + arrows).mq4

### Re: Ehlers Indicators for MT4

#242
Chintzki wrote:
Fri Jul 24, 2020 2:11 pm

Thanks in advance for any help.
Not sure what could be the problem, code wise looks like it should be working.

### Re: Ehlers Indicators for MT4

#243
Hello mrtools,

why don´t appear the indicator ?
I´v tried several Broker and I´v compiled multiple times !

Regard
mama (mtf + alerts + arrows).mq4

### Re: Ehlers Indicators for MT4

#245
Chintzki wrote:
Fri Jul 24, 2020 2:11 pm

I'm sorry as I don't understand the code well, so I don't know if this is helpful, but I have found 3 possible formula.

I can't speak towards the effectiveness or authenticity of these codes but hopefully one of them is what we are looking for!

This first code says that it is from John Ehler's "Cybernetic Analysis for Stocks and Futures"

Code: Select all

``````{Sine Wave indicator - //// From 'Cybernetic Analysis for Stocks and Futures' by John Ehlers //// code compiled by dn
} // plot on a subgraph separate from the price region.

Inputs: Price((H+L)/2), alpha(.07);

Vars: Smooth(0),Cycle(0),I1(0),Q1(0),I2(0),Q2(0),DeltaPhase(0),MedianDelta(0),MaxAmp(0),AmpFix(0),Re(0),Im(0),DC(0),
alpha1(0),InstPeriod(0),DCPeriod(0),count(0),SmoothCycle(0),RealPart(0),ImagPart(0),DCPhase(0);

Smooth = (Price+2*Price+2*Price+Price)/6;
Cycle = (1-.5*alpha)*(1-.5*alpha)*(Smooth-2*Smooth+Smooth)+2*(1-alpha)*Cycle-(1-alpha)*(1-alpha)*Cycle;
If CurrentBar <7 then Cycle=(Price-2*Price+Price)/4;
Q1=(.0962*Cycle+.5769*Cycle-.5769*Cycle-.0962*Cycle)*(.5+.08*InstPeriod);
I1 = Cycle;
If Q1<>0 and Q1<>0 then DeltaPhase=(I1/Q1-I1/Q1)/(1+I1*I1/(Q1*Q1));
If DeltaPhase <0.1 then DeltaPhase=0.1;
If DeltaPhase > 1.1 then DeltaPhase = 1.1;
MedianDelta = Median(DeltaPhase,5);
If MedianDelta =0 then DC=15 else DC=6.28318/MedianDelta+.5;
InstPeriod=.33*DC+.67*InstPeriod;
Value1 = .15*InstPeriod+.85*Value1;
DCPeriod = IntPortion(Value1);
RealPart = 0;
ImagPart = 0;
For count = 0 To DCPeriod - 1 begin
RealPart = RealPart + Sine(360 * count / DCPeriod) * (Cycle[count]);
ImagPart = ImagPart + Cosine(360 * count / DCPeriod) * (Cycle[count]);
End;
If AbsValue(ImagPart) > 0.001 then DCPhase = Arctangent(RealPart / ImagPart);
If AbsValue(ImagPart) <= 0.001 then DCPhase = 90 * Sign(RealPart);

DCPhase = DCPhase + 90;
If ImagPart < 0 then DCPhase = DCPhase + 180;
If DCPhase > 315 then DCPhase = DCPhase - 360;

Plot1(Sine(DCPhase), "Sine",blue);

{Note: This indicator tries to determine the current phase of the cycles you are in. A sinewave indicator has an advantage over
other oscillators such as RSI and Stochastic because it predicts rather than waits for confirmation. This assumes that the measured
phase has existed at least briefly in the past and will continue at least briefly into the future.
The phase languishes when the market is in a trend mode, and can even have a negative rate of change.
This indicator gives entry and exit signals 1/16th of a cycle period in advance of the cycle turning point
and seldom gives false whipsaw signals when the market is in a trend mode.}[/quote]

I found a website with a list of many of Ehler's formulas.

On that page the author has listed an a "special" version of the sinewave indicator.

It looks almost identical to the one written in Ehler's "Rocket Science for Traders Digital Signal Processing Applications" at first glance. If it is different or special, I can't tell how.

I have copied the code below.

[quote]{***************************************

Ehlers - Rocket Science for Traders
Sinewave Indicator (Figure 9.3)

****************************************}

Inputs:
Price((H+L)/2);

Vars:
Smooth(0),
Detrender(0),
I1(0),
Q1(0),
jI(0),
JQ(0),
I2(0),
Q2(0),
Re(0),
Im(0),
Period(0),
SmoothPeriod(0),
SmoothPrice(0),
DCPeriod(0),
RealPart(0),
Imagpart(0),
count(0),
DCPhase(0);

If CurrentBar > 5 Then Begin
Smooth = (4*Price + 3*Price + 2*Price + Price) / 10;
Detrender = (.0962*Smooth + .5769*Smooth - .5769*Smooth
- .0962*Smooth)*(.075*Period + .54);

Q1 = (.0962*Detrender + .5769*Detrender - .5769*Detrender
- .0962*Detrender)*(.075*Period + .54);
I1 = Detrender;

{Advance the phase of I1 and Q1 by 90 degrees}
jI = (.0962*I1 + .5769*I1 - .5769*I1 - .0962*I1)*(.075*Period + .54);
JQ = (.0962*Q1 + .5769*Q1 - .5769*Q1 - .0962*Q1)*(.075*Period + .54);

{Phasor addition for 3 bar averaging}
I2 = I1 - JQ;
Q2 = Q1 + jI;

{Smooth the I and Q components before applying the discriminator}
I2 = .2*I2 + .8*I2;
Q2 = .2*Q2 + .8*Q2;

{Homodyne Discriminator}
Re = I2*I2 + Q2*Q2;
Im = I2*Q2 - Q2*I2;
Re = .2*Re + .8*Re;
Im = .2*Im + .8*Im;

If Im <> 0 And Re <> 0 Then Period = 360/ArcTangent(Im/Re);
If Period > 1.5*Period Then Period = 1.5*Period;
If Period < .67*Period Then Period = .67*Period;
If Period < 6 Then Period = 6;
If Period > 50 Then Period = 50;
Period = .2*Period + .8*Period;
SmoothPeriod = .33*Period + .67*SmoothPeriod;

{Compute Dominant Cycle Phase}
SmoothPrice = (4*price + 3*Price + 2*Price + Price) / 10;
DCPeriod = IntPortion(SmoothPeriod + .5);
RealPart = 0;
ImagPart = 0;

For count = 0 To DCPeriod - 1 Begin
RealPart = RealPart + Sine(360*count/DCPeriod)*(SmoothPrice[count]);
ImagPart = ImagPart + CoSine(360*count/DCPeriod)*(SmoothPrice[count]);
End;

If AbsValue(ImagPart) > 0 Then DCPhase = Arctangent(RealPart/ImagPart);
If AbsValue(ImagPart) <= .001 Then DCPhase = DCPhase + 90*Sign(RealPart);
DCPhase = DCPhase + 90;

{Compensate for one bar lag of the Weighted Moving Average}
DCPhase = DCPhase + 360 / SmoothPeriod;

If ImagPart < 0 Then DCPhase = DCPhase + 180;
If DCPhase > 315 Then DCPhase = DCPhase - 360;

Plot1(Sine(DCPhase), "Sine");
End;[/quote]

The third is from Ehler's "Cycle Analytics for Traders Advanced Technical Trading Concepts", the "Even Better Sinewave Indicator"

[quote]{
Even Better Sinewave Indicator
}
Inputs:
Duration(40);
Vars:
alpha1(0),
HP(0),
a1(0),
b1(0),
c1(0),
c2(0),
c3(0),
Filt(0),
count(0),
Wave(0),
Pwr(0);

//HighPass filter cyclic components whose periods are
shorter than Duration input
alpha1 = (1 - Sine (360 / Duration)) / Cosine(360 /
Duration);
HP = .5*(1 + alpha1)*(Close - Close) + alpha1*HP;
//Smooth with a Super Smoother Filter from equation 3-3
a1 = expvalue(-1.414*3.14159 / 10);
b1 = 2*a1*Cosine(1.414*180 / 10);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(HP + HP) / 2 + c2*Filt + c3*Filt;
//3 Bar average of Wave amplitude and power
Wave = (Filt + Filt + Filt) / 3;
Pwr = (Filt*Filt + Filt*Filt + Filt*Filt) / 3;
//Normalize the Average Wave to Square Root of the Average
Power
Wave = Wave / SquareRoot(Pwr);
Plot1(Wave);``````

I will continue to search. I wish I could be of more help.

Also, is there a new/good version of either of the two following indicators?
• Ehler's Super Smoother Filter
• Ehler's MESA or MAMA (I have found the attached indicator on these forums, but it doesn't seem to work on my MT4. Not sure why, but I also have not yet tried to recompile it)

Thanks in advance for any help.
Maybe try this version posted here viewtopic.php?p=1295415526#p1295415526

### Re: Ehlers Indicators for MT4

#246
Chintzki wrote:
Wed Jul 08, 2020 2:07 pm
Has anybody seen this indicator? I've seen some that look similar but seem to function differently. The screenshot is from a pdf.
Have you looked at these? They might be what you are looking for.

viewtopic.php?t=8472604&p=1295389775#p1295389775

### Re: Ehlers Indicators for MT4

#247
mrtools wrote:
Sat Jul 25, 2020 7:22 am
Try this version.
I find it intersting that the change of MA-method (input: price pre filtering method) doesn't change anything whatsoever - looks like a glitch. But I'm no coder - so it's up to you to decide.

### Re: Ehlers Indicators for MT4

#248
mrtools wrote:
Sat Jul 25, 2020 7:22 am
Try this version.
my favorite ma cross indicator now............... thx mrtoolz

### Re: Ehlers Indicators for MT4

#249
josi wrote:
Sun Jul 26, 2020 9:23 pm
mrtools wrote:
Sat Jul 25, 2020 7:22 am
Try this version.
I find it intersting that the change of MA-method (input: price pre filtering method) doesn't change anything whatsoever - looks like a glitch. But I'm no coder - so it's up to you to decide.
By default the price prefiltering period = 1, if you leave it like that all ma's will be the same.

### Re: Ehlers Indicators for MT4

#250
mrtools wrote:
Mon Jul 27, 2020 12:38 am
josi wrote:
Sun Jul 26, 2020 9:23 pm
I find it intersting that the change of MA-method (input: price pre filtering method) doesn't change anything whatsoever - looks like a glitch. But I'm no coder - so it's up to you to decide.
By default the price prefiltering period = 1, if you leave it like that all ma's will be the same.
Thanks for enlightening me, MrTools.
So - if I change the prefiltering period (which values are possible? what effects do they have?)
- how does that affect MAs?

1. ### Similar Topics

93 Replies 22906 Views

by Skyold, Mon Jun 10, 2019 7:39 pm in Trading Systems

93 Replies
22906 Views