Dit heb ik eens geprogrammeerd, voor een ieder die het bruikbaar vind.
Het is een exit strategie gebaseerd op de avg truerange.
Documentatie: https://www.tradestation.com/Discussion ... LeBeau.pdf
https://www.tradestation.com/Discussion ... 011&Page=1
Invoegen onder system, plots kun je als candles (automatisch dik)weergeven (Vestics kent nog geen points).
Inputs:Chandelier_Exit(true){on/off},
Set_Chandelier(true){Chandelier exit},
Set_SAR(true){Parabolic SAR exit},
Set_YoYo(false){Yo-Yo exit},
Chandelier_Fact(4){Multi ATR},
Ratchet_Incr (5){Tightning stop},
ATR_length (15),
YoYo_Fact(2){Multi ATR},
Prof_Fact_Chan(1){Profit target},
Prof_Fact_SAR(0){Profit tatget},
SAR_AF(0.02),
Initial_Risk(3){Opening Risk},
Show_All_Stops(false);
Vars: Chandelier_stop(0),YoYo_stop(0),SAR_stop(0),Stop_Loss(0);
vars: Market_Position(0),Position_High(0), Position_Low(0);
Vars: ATR(0),SAR(0),AF(0);
vars: Tg_Prof_Chandelier(0),Tg_Prof_SAR(0);
{Initialize variables}
Market_Position = MarketPosition;
ATR=AvgTrueRange(ATR_length);
SAR=round(Parabolic(SAR_AF),2);
Tg_Prof_Chandelier=Prof_Fact_Chan*ATR;
Tg_Prof_SAR=Prof_Fact_SAR*ATR;
if Chandelier_Exit then begin {on/off}
if Market_Position <> 0 then
begin
{LONG}
If Market_Position[1]<>1 and Market_Position = 1 Then Begin {Day 0}
Position_High=high;
{Opening Risk}
Chandelier_Stop =round(Entryprice-Initial_Risk*ATR,2);
YoYo_stop =round(Entryprice-Initial_Risk*ATR,2);
SAR_stop =round(Entryprice-Initial_Risk*ATR,2);
Stop_Loss =round(Entryprice-Initial_Risk*ATR,2);
end;
If Market_Position[1]=1 and Market_Position = 1 Then Begin {Day 1 .........}
if High>Position_High[1] then Position_High=High ;
if Set_Chandelier then begin
If Position_High>=Entryprice + Tg_Prof_Chandelier then {ProfitTarget}
Chandelier_stop = round(lowest(low,10) + (ATR * barssinceentry )*(Ratchet_Incr/100),2) {ATRRatchet}
else Chandelier_stop= round(Position_High-Chandelier_Fact*ATR,2); {Chandelier}
if Chandelier_Stop < Chandelier_Stop[1] then
Chandelier_Stop = Chandelier_Stop[1] ;
end;
if Set_YoYo then begin
YoYo_stop= Round(c - YoYo_Fact * ATR,2) ;{Yo-Yo}
end;
if Set_SAR then begin
If Prof_Fact_SAR <>0 then begin
SAR_stop=round(Position_High-Chandelier_Fact*ATR,2)else
if Position_High>=Entryprice + Tg_Prof_SAR then SAR_stop=SAR;
end else
SAR_stop=SAR;{SAR}
if SAR_stop < SAR_stop[1] then
SAR_stop = SAR_stop[1] ;
end;
Stop_Loss=maxlist(Chandelier_Stop,YoYo_stop,SAR_stop);
if Stop_Loss < Stop_Loss[1] then
Stop_Loss = Stop_Loss[1] ;
Exitlong next bar at Stop_Loss stop;
end {end Long}
else
{SHORT}
If Market_Position[1]<>-1 and Market_Position = -1 Then Begin {Day 0}
Position_Low=low;
{Opening Risk}
Chandelier_Stop =round(Entryprice+Initial_Risk*ATR,2);
YoYo_stop =round(Entryprice+Initial_Risk*ATR,2);
SAR_stop =round(Entryprice+Initial_Risk*ATR,2);
Stop_Loss =round(Entryprice+Initial_Risk*ATR,2);
end;
If Market_Position[1]=-1 and Market_Position = -1 Then Begin {Day 1 .........}
if low<Position_Low[1] then Position_Low=Low;
if Set_Chandelier then begin
if Position_Low<= entryprice-Tg_Prof_Chandelier then {ProfitTarget}
Chandelier_stop = round(highest(high,10) - (ATR * barssinceentry )*(Ratchet_Incr/100),2) {ATRRatchet}
else Chandelier_stop= round(Position_Low+Chandelier_Fact*ATR,2);{Chandelier}
if Chandelier_Stop > Chandelier_Stop[1] then
Chandelier_Stop = Chandelier_Stop[1] ;
end;
if Set_YoYo then begin
YoYo_stop=round(c + YoYo_Fact * ATR,2) ;{Yo-Yo}
end;
if Set_SAR then begin
If Prof_Fact_SAR <>0 then begin
SAR_stop=round(Position_Low+Chandelier_Fact*ATR,2)else
if Position_Low<= entryprice- Tg_Prof_SAR then SAR_stop=SAR;
end else
SAR_stop=SAR;{SAR}
if SAR_stop > SAR_stop[1] then
SAR_stop = SAR_stop[1] ;
end;
Stop_Loss=minlist(Chandelier_Stop,YoYo_stop,SAR_stop);
if Stop_Loss > Stop_Loss[1] then
Stop_Loss = Stop_Loss[1] ;
Exitshort next bar at Stop_Loss stop;
end;{end Short}
end; {end Position}
end; {end Chandelier_Exit}
{Plots}
if Market_Position <> 0 then
begin
if Show_All_Stops then
begin
if Set_Chandelier then Plot1(Chandelier_Stop ,"Chandelier_stop"+ " "+NumToStr(Chandelier_Fact));
if Set_YoYo then Plot2(YoYo_stop,"YoYo_stop"+ " "+NumToStr(YoYo_Fact));
if Set_SAR then Plot3(SAR_stop,"SAR_stop");
end { end show all stops}
else plot1(Stop_Loss,"Stop_Loss"); { plot only closest stop}
end ; { end plots }
Paul