PureBytes Links
Trading Reference Links
|
Here is V2.2 of 'Trade Stop LE'. A funds version, which does not check OPEN
for a gap-open condition, is also listed. These indicators are intended for
use with 'Trade Equity LE' and require price inputs rather than binary
inputs.
Roy
{Trade Stop LE} {V2.2}
{use '99' to disable timed exit or stops}
Pd:=Input("Timed exit delay periods",1,99,30);
Xa:=Input("C/Next Open=1 C/Close=2 H/Close=3 Intraday=4",1,4,3);
Xc:=Input("Target price/timing /\ Stoploss price/timing \/",0,0,0);
Xc:=Input("C/Next Open=1 C/Close=2 L/Close=3 Intraday=4",1,4,3);
Pt:=Input("Profit target %",1,99,25)/100;
Ls:=Input("Maximum loss %" ,1,99,12)/100;
Cm:=30; {commission}
Cp:=6000; {capital}
N:=Fml("PS Fractal Entry"); {entry/price}
X:=Fml("PS Fractal Exit"); {exit/price}
I:=Cum(N > -1 OR X > -1)=1; {formulas valid}
Pf:=(Cp*(1+Pt)+Cm)/(Cp-Cm); {profit factor}
Lf:=(Cp*(1-Ls)+Cm)/(Cp-Cm); {loss factor}
{+Cm for exit, -Cm for entry}
Tr:=If(PREV=0,If(N>0 AND X=0,N,0), {trade latch}
If(X>0 {independant exit} OR
(BarsSince(PREV=0)>=Pd AND Pd<>99)
{timed exit} OR
(If(Xa < 3,C,H)>=Pf*PREV AND Pt<>99)
{profit target exit} OR
(If(Xc<3,C,L)<=Lf*PREV AND Ls<>99)
{stop loss exit},0,PREV {or previous value}));
Tr:=If(Tr=0 AND N>0 AND Alert(N=0,2) AND X>0,-N,Tr);
{intraday entry and exit}
Xb:=(Tr=0 AND Alert(Tr>0,2)) OR (Tr<0 AND Alert(Tr=0,2)); {exit bar}
Ev:=ValueWhen(1,I OR Tr<>0,Abs(Tr)); {buy price}
Tr:=Abs(Tr); {remove negative excursion}
{profit exit price and timing}
Sp:=If(Xb,If(Xa<3 AND C >=Ev*Pf,C,
If(Xa>2 AND H>=Ev*Pf,Ev*Pf,0)),0);
Sp:=If(Xa=4 AND Sp>0,Max(O,If(Sp>=0.5,PREC(Sp,
2),If(Sp<0.1,PREC(Sp,3),PREC(Sp*2,2)/2))),Sp);
Sp:=If(Xa=3 AND Sp>0,C,If(Xa=1,Ref(Sp,-1),Sp));
Sp:=If(Xa=1 AND Sp>0,O,Sp);
{profit exit price and timing}
Sl:=If(Xb,If(Xc<3 AND C<=Ev*Lf,C,
If(Xc>2 AND L<=Ev*Lf,Ev*Lf,0)),0);
Sl:=If(Xc=4 AND Sl>0,Min(O,If(Sl>=0.5,PREC(Sl,
2),If(Sl<0.1,PREC(Sl,3),PREC(Sl*2,2)/2))),Sl);
Sl:=If(Xc=3 AND Sl>0,C,If(Xc=1,Ref(Sl,-1),Sl));
Sl:=If(Xc=1 AND Sl>0,O,Sl);
{timed exit}
St:=If(Pd<>99 AND Xb AND Alert(Tr>0,2) AND
BarsSince(Alert(Tr>0,2)=0)=Pd+1,C,0);
Alert(Tr,2)*Ev; {trade & entry price}
Alert(Tr,2)*Ev*Pf; {profit target price}
Alert(Tr,2)*Ev*Lf; {stoploss price}
{prioritise & output exit price spike}
If(Sl>0,Sl,If(Sp>0,Sp,If(X>0 AND Xb,X,If(St>0,St,0))));
{Trade Stop LE Funds} {V2.2}
{use '99' to disable timed exit or stops}
Pd:=Input("Timed exit delay periods",1,99,30);
Xa:=Input("C/Next Close=1 C/Close=2 H/Close=3 Intraday=4",1,4,3);
Xc:=Input("Target price/timing /\ Stoploss price/timing \/",0,0,0);
Xc:=Input("C/Next Close=1 C/Close=2 L/Close=3 Intraday=4",1,4,3);
Pt:=Input("Profit target %",1,99,25)/100;
Ls:=Input("Maximum loss %" ,1,99,12)/100;
Cm:=30; {commission}
Cp:=6000; {capital}
N:=Fml("PS Fractal Entry"); {entry/price}
X:=Fml("PS Fractal Exit"); {exit/price}
I:=Cum(N > -1 OR X > -1)=1; {formulas valid}
Pf:=(Cp*(1+Pt)+Cm)/(Cp-Cm); {profit factor}
Lf:=(Cp*(1-Ls)+Cm)/(Cp-Cm); {loss factor}
{+Cm for exit, -Cm for entry}
Tr:=If(PREV=0,If(N>0 AND X=0,N,0), {trade latch}
If(X>0 {independant exit} OR
(BarsSince(PREV=0)>=Pd AND Pd<>99)
{timed exit} OR
(If(Xa < 3,C,H)>=Pf*PREV AND Pt<>99)
{profit target exit} OR
(If(Xc<3,C,L)<=Lf*PREV AND Ls<>99)
{stop loss exit},0,PREV {or previous value}));
{intraday entry and exit}
Tr:=If(Tr=0 AND N>0 AND Alert(N=0,2) AND X>0,-N,Tr);
Xb:=(Tr=0 AND Alert(Tr>0,2)) OR (Tr<0 AND Alert(Tr=0,2)); {exit bar}
Ev:=ValueWhen(1,I OR Tr<>0,Abs(Tr)); {buy price}
Tr:=Abs(Tr); {remove negative excursion}
{profit exit price and timing}
Sp:=If(Xb,If(Xa<3 AND C >=Ev*Pf,C,
If(Xa>2 AND H>=Ev*Pf,Ev*Pf,0)),0);
Sp:=If(Xa=4 AND Sp>0,If(Sp>=0.5,PREC(Sp,
2),If(Sp<0.1,PREC(Sp,3),PREC(Sp*2,2)/2)),Sp);
Sp:=If(Xa=3 AND Sp>0,C,If(Xa=1,Ref(Sp,-1),Sp));
Sp:=If(Xa=1 AND Sp>0,C,Sp);
{stop loss exit price and timing}
Sl:=If(Xb,If(Xc<3 AND C<=Ev*Lf,C,
If(Xc>2 AND L<=Ev*Lf,Ev*Lf,0)),0);
Sl:=If(Xc=4 AND Sl>0,If(Sl>=0.5,PREC(Sl,
2),If(Sl<0.1,PREC(Sl,3),PREC(Sl*2,2)/2)),Sl);
Sl:=If(Xc=3 AND Sl>0,C,If(Xc=1,Ref(Sl,-1),Sl));
Sl:=If(Xc=1 AND Sl>0,C,Sl);
{timed exit}
St:=If(Pd<>99 AND Xb AND Alert(Tr>0,2) AND
BarsSince(Alert(Tr>0,2)=0)=Pd+1,C,0);
Alert(Tr,2)*Ev; {trade & entry price}
Alert(Tr,2)*Ev*Pf; {profit target price}
Alert(Tr,2)*Ev*Lf; {stoploss price}
{prioritise & output exit price spike}
If(Sl>0,Sl,If(Sp>0,Sp,If(X>0 AND Xb,X,If(St>0,St,0))));
|