MetaStock -> Tools -> Indicator Builder -> New -> Copy & paste complete formula between "---8<---" lines. ===================== EMA - Ehlers Zero Lag ===================== ---8<-------------------------------------- {John Ehlers' "Zero Lag" EMA & Signals - v1.1 http://www.traders.com/Documentation/FEEDbk_docs/2010/11/Ehlers.html Coded for MetaStock by Jose Silva and tested with the VSTpro platform: http://www.metastocktools.com/vst/samples/index.htm#ZeroLag } {Inputs} pds:=Input("EMA periods",3,260,32); gain:=Input("EMA error amplitude Gain [0-100]", 0,100,22); thresh:=Input("Error % Threshold for signals", 0,100,0.75); plot:=Input("[1]ZeroLag+EMA [2]Error amplitude [3]Signals",1,3,1); {EMA} EMA:=Mov(C,pds,E); {Zero Lag EMA} x:=2/(pds+1); gain:=Min(gain,pds*5)/10; ECr:=x*(EMA+gain*(C-PREV))+(1-x)*PREV; ECr:= ValueWhen(1,Cum(IsDefined(EMA))>pds/2+1,ECr); {EMA % deviance from Close} errorPer:=Abs(C-ECr)/C*100; {Signals} entry:=Cross(ECr,EMA) AND errorPer>thresh; exit:=Cross(EMA,ECr) AND errorPer>thresh; {Clean signals} init:=Cum(IsDefined(entry+exit))=1; bin:=ValueWhen(1,entry-exit<>0 OR init,entry); long:=bin *(Alert(bin=0,2) OR entry*Cum(entry)=1); short:=(bin=0)*(Cum(bin)>0) *(Alert(bin,2) OR exit*Cum(exit)=1); {Display Zero Lag EMA on chart} If(plot=1,EMA,If(plot=2,thresh,0)); If(plot=1,ECr,If(plot=2,errorPer,0)); If(plot=1,ECr,If(plot=2,errorPer,long-short)) ---8<-------------------------------------- http://www.metastocktools.com