John Ehlers Zero Lag Indicator

S

Srt4ever

New member
VIP
This is not mine and I did not make it, I found it on another thread and wanted to share here with y'all. Also is it possible for someone to make it as close to the original as possible ? I will post a link to John Ehlers original code on his website. Original Zero Lag John Ehlers


Code:
#NICA_ZEROLAG
#This is my version, anyone is welcome to play with it and modify it for better results.

input length = 32;
input GainLimit = 22;
input Thresh = 0.75;

def alpha = 2 / (length + 1);

def EMA = alpha * close + (1 - alpha) * EMA[1];

def Value1 = -GainLimit + GainLimit;
def Gain = Value1 / 10;

def EC = alpha * (EMA + Gain * (close - EC[1])) + (1 - alpha) * EC[1];
def Error = close - EC;

def BestGain = Gain;

def LeastError = 1000000;

plot EC1 = alpha * (EMA + BestGain * (close - EC[1])) + (1 - alpha) * EC[1];
EC1.SetDefaultColor(Color.ORANGE);

plot EMA48 = alpha * close + (1 - alpha) * EMA[1];
#Plot1(EC);

#Plot3(EMA);

#plot EC Crosses Over EMA and 100*LeastError / Close > Thresh Then Buy Next Bar on Open;
#plot EC crosses Under EMA and 100*LeastError / Close > Thresh Then Sell Short Next Bar on Open;
 
BenTen

BenTen

Administrative
Staff
VIP
Have you tried this?

Code:
# Zero Lag EMA (Using an Error Correcting Filter)
# Mobius
# Ported to TOS 08.31.2016 from Article by John Ehlers
# Using an EMA error term, the current price – EMA[1], the amplitude of the error term is altered by multiplying the error by a gain term. The new filter is an EC or Error Corrected EMA.

# Inputs:
input Length = 20;
input GainLimit = 50;
input LabelsOn = yes;

# Vars:
def alpha;
def BestGain;
def EC1;
def Gain;
def EC;
def Error;
def LeastError;
def EMA;
alpha = 2 / (Length + 1);
EMA = alpha * close + (1 - alpha) * EMA[1];
plot EMAdata = EMA;
EMAdata.SetDefaultColor(Color.Yellow);

Gain = fold g = -GainLimit to GainLimit
       do getValue(g / 10, g);
EC1 = fold V = -GainLimit to GainLimit
      do alpha * (EMA + (fold i = -GainLimit to GainLimit
                         do i / 10) * (Close - EC1[1])) + (1 - alpha) * EC1[1];
Error = AbsValue(Close - EC1);
If Error < 1000000
Then {
LeastError = Error;
BestGain = Gain;
} else {
LeastError = LeastError[1];
BestGain = 0;
}
EC = alpha * (EMA + BestGain * (Close - EC1)) + (1 - alpha) * EC1;
Plot ECdata = EC;
ECdata.SetDefaultColor(Color.Cyan);
AddLabel(LabelsOn, "Standard EMA", color.yellow);
AddLabel(LabelsOn, "Error Corrected EMA", color.cyan);
#End Code Error Corrected EMA
 
H

horserider

Active member
@Srt4ever Just look in ToS for EhlersRoofingFilter, EhlersDecyclerOscillator or EhlersForwardReverseEMA. All three will give same signals as Ehlers Zero Lag you describe. The study you quoted above should plot as described in the linked article. Just adjust the length as you wish.
 
H

horserider

Active member
The Mobius study mentioned has a less smooth EMA possibly due to high gain. I suggest lowering the gain if you try that one. Why not use one of the lower studies and unclutter your upper chart as they give the same crossover signals. I thought I had a fancier Ehlers one but a quick search did not find it, oh well it gave the same crossovers. I think it colored the candles also. One day I may run across it again.
 
S

Srt4ever

New member
VIP
@Srt4ever Just look in ToS for EhlersRoofingFilter, EhlersDecyclerOscillator or EhlersForwardReverseEMA. All three will give same signals as Ehlers Zero Lag you describe. The study you quoted above should plot as described in the linked article. Just adjust the length as you wish.
I have the one I listed and the roofing filter as my indicators.
 
S

Srt4ever

New member
VIP
Have you tried this?

Code:
# Zero Lag EMA (Using an Error Correcting Filter)
# Mobius
# Ported to TOS 08.31.2016 from Article by John Ehlers
# Using an EMA error term, the current price – EMA[1], the amplitude of the error term is altered by multiplying the error by a gain term. The new filter is an EC or Error Corrected EMA.

# Inputs:
input Length = 20;
input GainLimit = 50;
input LabelsOn = yes;

# Vars:
def alpha;
def BestGain;
def EC1;
def Gain;
def EC;
def Error;
def LeastError;
def EMA;
alpha = 2 / (Length + 1);
EMA = alpha * close + (1 - alpha) * EMA[1];
plot EMAdata = EMA;
EMAdata.SetDefaultColor(Color.Yellow);

Gain = fold g = -GainLimit to GainLimit
       do getValue(g / 10, g);
EC1 = fold V = -GainLimit to GainLimit
      do alpha * (EMA + (fold i = -GainLimit to GainLimit
                         do i / 10) * (Close - EC1[1])) + (1 - alpha) * EC1[1];
Error = AbsValue(Close - EC1);
If Error < 1000000
Then {
LeastError = Error;
BestGain = Gain;
} else {
LeastError = LeastError[1];
BestGain = 0;
}
EC = alpha * (EMA + BestGain * (Close - EC1)) + (1 - alpha) * EC1;
Plot ECdata = EC;
ECdata.SetDefaultColor(Color.Cyan);
AddLabel(LabelsOn, "Standard EMA", color.yellow);
AddLabel(LabelsOn, "Error Corrected EMA", color.cyan);
#End Code Error Corrected EMA
I have not but I will give this one a shot.
 
S

Srt4ever

New member
VIP
Have you tried this?

Code:
# Zero Lag EMA (Using an Error Correcting Filter)
# Mobius
# Ported to TOS 08.31.2016 from Article by John Ehlers
# Using an EMA error term, the current price – EMA[1], the amplitude of the error term is altered by multiplying the error by a gain term. The new filter is an EC or Error Corrected EMA.

# Inputs:
input Length = 20;
input GainLimit = 50;
input LabelsOn = yes;

# Vars:
def alpha;
def BestGain;
def EC1;
def Gain;
def EC;
def Error;
def LeastError;
def EMA;
alpha = 2 / (Length + 1);
EMA = alpha * close + (1 - alpha) * EMA[1];
plot EMAdata = EMA;
EMAdata.SetDefaultColor(Color.Yellow);

Gain = fold g = -GainLimit to GainLimit
       do getValue(g / 10, g);
EC1 = fold V = -GainLimit to GainLimit
      do alpha * (EMA + (fold i = -GainLimit to GainLimit
                         do i / 10) * (Close - EC1[1])) + (1 - alpha) * EC1[1];
Error = AbsValue(Close - EC1);
If Error < 1000000
Then {
LeastError = Error;
BestGain = Gain;
} else {
LeastError = LeastError[1];
BestGain = 0;
}
EC = alpha * (EMA + BestGain * (Close - EC1)) + (1 - alpha) * EC1;
Plot ECdata = EC;
ECdata.SetDefaultColor(Color.Cyan);
AddLabel(LabelsOn, "Standard EMA", color.yellow);
AddLabel(LabelsOn, "Error Corrected EMA", color.cyan);
#End Code Error Corrected EMA
Is this for Thinkorswim ?
 
H

horserider

Active member
@Srt4ever I removed the study after a quick look so do not remember gain, maybe 20. Best is to just change it till you get what fits what you want.
I do not understand why you want to use that study. You mentioned an easier one to work with and were given several very easy to use alternatives. Why make it harder than it has to be ?
 
S

Srt4ever

New member
VIP
The only one I cant find on TOS is the ForwardReverseEMA unless you have a script for it.
 
BenTen

BenTen

Administrative
Staff
VIP
Here is the Forward Reverse EMA by Mobius

Code:
# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

declare lower;

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2)   * RE1 + RE1[1];
RE3 = Power(CC, 4)   * RE2 + RE2[1];
RE4 = Power(CC, 8)   * RE3 + RE3[1];
RE5 = Power(CC, 16)  * RE4 + RE4[1];
RE6 = Power(CC, 32)  * RE5 + RE5[1];
RE7 = Power(CC, 64)  * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
signal.AssignValueColor(if Signal > Signal[1]
                        then color.green
                        else color.red);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.gray);
addCloud(0, Signal, color.red, color.green);
# End Code Ehlers Forward / Reverse EMA
 
markos

markos

Well-known member
VIP
You should know that if a study like that isn't already put into TOS, they probably had reason not to, like redundancy...
Thanks @BenTen
 
tenacity11

tenacity11

Member
VIP
# Zero Lag EMA (Using an Error Correcting Filter) # Mobius
I just started using this with parameters of 13,3
 
S

Srt4ever

New member
VIP
@BenTen is there a script for back testing the zero lag ?
 
Top