Zero Lag (Well, Almost)
In their article “Zero Lag (Well, Almost)”, John Ehlers and Ric Way have investigated how to remove a selected amount of lag from an exponential moving average and use the filter in an effective trading strategy.
Using Tradecision’s Indicator Builder, one needs to create the ZERO_LAG indicator:
ZERO_LAG indicator:
ins
Length : "Enter Period",20;
GainLimit:"Enter Gain Limit",50;
end_ins
var
alpha:=0;
Gain:=0;
BestGain:=0;
EC:=0;
Error:=0;
LeastError:=0;
EMA:=0;
Value1:=0;
end_var
if HistorySize < 1 then return c;
alpha:=2 / (Length + 1);
EMA:=alpha * Close + (1 - alpha) * EMA\1\;
LeastError:=1000000;
for Value1:= -GainLimit to GainLimit do begin
Gain:=Value1 / 10;
EC:=alpha * (EMA + Gain * (Close - EC\1\)) +
(1 - alpha) * EC\1\;
Error:=Close - EC;
if Abs(Error) < LeastError then
begin
LeastError:=Abs(Error);
BestGain:=Gain;
end;
end;
EC:=alpha * (EMA + BestGain * (Close - EC\1\)) +
(1 - alpha) * EC\1\;
return EC;
Using Tradecision’s Strategy Builder, one needs to create the ZERO_LAG strategy:
ZERO_LAG strategy:
Long Rule:
var
Length := 20;
GainLimit:=50;
alpha:=0;
Gain:=0;
BestGain:=0;
EC:=0;
Error:=0;
LeastError:=0;
EMA:=0;
Value1:=0;
Thresh:=1;
end_var
if HistorySize < 1 then return false;
alpha:=2 / (Length + 1);
EMA:=alpha * Close + (1 - alpha) * EMA\1\;
LeastError:=1000000;
for Value1:= -GainLimit to GainLimit do begin
Gain:=Value1 / 10;
EC:=alpha * (EMA + Gain * (Close - EC\1\)) +
(1 - alpha) * EC\1\;
Error:=Close - EC;
if Abs(Error) < LeastError then
begin
LeastError:=Abs(Error);
BestGain:=Gain;
end;
end;
EC:=alpha * (EMA + BestGain * (Close - EC\1\)) +
(1 - alpha) * EC\1\;
return CrossAbove(EC,EMA) and 100*LeastError /
Close > Thresh;
Short Rule:
var
Length := 20;
GainLimit:=50;
alpha:=0;
Gain:=0;
BestGain:=0;
EC:=0;
Error:=0;
LeastError:=0;
EMA:=0;
Value1:=0;
Thresh:=1;
end_var
if HistorySize < 1 then return false;
alpha:=2 / (Length + 1);
EMA:=alpha * Close + (1 - alpha) * EMA\1\;
LeastError:=1000000;
for Value1:= -GainLimit to GainLimit do begin
Gain:=Value1 / 10;
EC:=alpha * (EMA + Gain * (Close - EC\1\)) +
(1 - alpha) * EC\1\;
Error:=Close - EC;
if Abs(Error) < LeastError then
begin
LeastError:=Abs(Error);
BestGain:=Gain;
end;
end;
EC:=alpha * (EMA + BestGain * (Close - EC\1\)) +
(1 - alpha) * EC\1\;
return CrossBelow(EC,EMA) and 100*LeastError /
Close > Thresh;
|
Download to import into Tradecision. 
How to use this indicator in Tradecision:
- Click Download.
- Save this indicator in a safe location on your hard drive.
- Open Tradecision and in the Tools menu click Indicator Builder.
- In the Indicator Builder dialog, click Import, locate the saved file and then click OK.
The indicator will be added to the Custom Indicators list.
|