Saturday, January 4, 2014

ATR CHANDELIER EXIT


Chandelier Exit is designed to keep traders in a trend and prevent an early exit as long as the trend extends.

Chandelier Exit (long) = 22-day High - ATR(22) x 3 
Chandelier Exit (short) = 22-day Low + ATR(22) x 3
The Chandelier Exit identifies outsized price movements.
===================================
Trailing Stop - ATR Chandelier Exit
===================================
---8<-------------------------------------
 
{ Trailing Stop - ATR Chandelier Exit v3.0
  Long (+1) & Short (-1) trigger signals at
 Close crossover of user-defined trailing stops.
 
  Copyright © 2003-2007 Jose Silva.
  The grant of this license is for personal use
   only - no resale or repackaging allowed.
  All code remains the property of Jose Silva.
  http://www.metastocktools.com }
 
{ User Inputs }
multi:=Input("ATR multiplier",0,10,2.5);
pds:=Input("ATR periods",1,252,10);
pds1:=Input("ATR lookback periods",1,252,21);
plot:=Input("[1]Trailing Stop,  [2]Long+Short,  [3]Signals",1,3,1);
adv:=Input("plot:  today's trailing stop=0,  tomorrow's stop=1",0,1,0);
delay:=Input("Entry and Exit signal delay",0,5,0);
 
{ Trailing Stops }
StLong:=HHV(C-multi*Mov(ATR(1),pds,E),pds1);
StShort:=LLV(C+multi*Mov(ATR(1),pds,E),pds1);
stopLong:=If(C<PREV,StLong,Max(StLong,PREV));
stopShort:=If(C>PREV,StShort,Min(StShort,PREV));
 
{ Trade flags/signals }
In:=Cross(C,Ref(stopShort,-1));
Out:=Cross(Ref(stopLong,-1),C);
Init:=Cum(IsDefined(In+Out))=1;
x:=ValueWhen(1,In-Out<>0 OR Init,In-Out);
long:=x=1 AND (Alert(x<>1,2) OR Init);
short:=x=-1 AND (Alert(x<>-1,2) OR Init);
signals:=long-short;
flag:=ValueWhen(1,signals<>0 OR Init,signals);
 
{ Switch between Long/Short stops }
stop:=Ref(If(flag=1,stopLong,stopShort),-1+adv);
 
{ Plot in price chart }
If(plot=1,stop,
 If(plot=2,Ref(stopLong,-1+adv),0));
If(plot=1,stop,
 If(plot=2,Ref(stopShort,-1+adv),signals))
 
---8<-------------------------------------
 
 
 
==============================
Trailing Stop - ATR - TradeSim
==============================
---8<-------------------------------------
 
{ Triggers: Long (+1) & Short (-1) signals at
  crossover of user-defined trailing stops.
  x23 faster than MetaStock's 4-PREV version.
 
  TradeSim.dll must be in
   ...\MetaStock\External Function DLLs\ folder.
 
  Copyright © 2003 Jose Silva
  http://www.metastocktools.com }
 
pds:=Input("ATR periods",1,252,10);
multi:=Input("ATR multiplier",0,10,2.5);
plot:=Input("plot:  trailing stop=1,  Long+Short=2,  signals=3",1,3,1);
adv:=Input("plot:  today's trailing stop=0,  tomorrow's stop=1",0,1,0);
delay:=Input("Entry and Exit signal delay",0,5,0);
 
stopLong:=ExtFml("TradeSim.TrailingStop",
 BAND,LONG,multi*ATR(pds),C,C);
 
stopShort:=ExtFml("TradeSim.TrailingStop",
 BAND,SHORT,multi*ATR(pds),C,C);
 
In:=Cross(C,Ref(stopShort,-1));
Out:=Cross(Ref(stopLong,-1),C);
Init:=Cum(In+Out>-1)=1;
InInit:=Cum(In)=1;
flag:=BarsSince(Init OR In)
 < BarsSince(Init OR Out)+InInit;
signals:=Ref((InInit AND Alert(InInit=0,2)
 OR flag AND Alert(flag=0,2))
 -(flag=0 AND Alert(flag,2)),-delay);
stop:=Ref(If(flag=1,stopLong,stopShort),-1+adv);
 
If(plot=1,stop,
 If(plot=2,Ref(stopLong,-1+adv),0));
If(plot=1,stop,
 If(plot=2,Ref(stopShort,-1+adv),signals))
 

---8<-------------------------------------

No comments:

Post a Comment