[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

TE and TS V3



PureBytes Links

Trading Reference Links

Hi All



The following versions (3.0) of 'Trade Equity LE' and 'Trade Stop LE' are
not intended to replace earlier versions, but they offer greater System
Tester compatibility for those users that prefer to use binary entry and
exit code in preference to price code. 'Trade Stop LE' can now manage "OHLC"
prices derived from the user settings.



'TS' now has 12 user inputs so it has been necessary to change the way in
which the various options are selected. The following example will help
demonstrate the new method. Consider the input for 'Cp'.

Cp:=Input("Position size,  entry and exit delay, $ ## ",0,100033,10000);

There are actually three values contained within "10000". The two low order
digits represent the delay periods to be applied to the binary inputs for 'N
' and 'X', and the higher order digits represent the position size. These
values are split apart then used in the normal way.



Not much is different with 'TE' except that the user interface has been
changed to match that demanded by 'TS', and some minor changes have been
made to permit 'TS' to provide stops even when MS compatible binary code is
being used. Previous versions of 'TE' required the use of price code when
used in conjunction with 'TS'. This version of 'TE' can be used with older
versions of TS, but not the other way around when using binary code formula
inputs.



Some further explanation of the 'Xa' and 'Xc' variables would probably not
go amiss. These variables control when a stop is activated, and at what
price the stop will trade. 'Xa' is used for the profit stop, and 'Xc' for
the stop-loss. The possible settings are determined by the default values of
this input line.

Xa:=Input("Stop timing, 1=C/O+ 2=C/C 3=Stop/C 4=Stop, ##" ,11,44,22);

The left digit is for 'Xa' and the right digit for 'Xc'.

  1=C/O+  says that the stop will be triggered by the CLOSE touching or
crossing the stop value, and the trade will be made on the OPEN of the
following bar.

  2=C/C also says that the stop will be triggered by the CLOSE touching or
crossing the stop value, but the trade will be made on the CLOSE of the
current bar.

  3=Stop/C says that the stop will be triggered by the EXTREME price (H or L
respectively) touching or crossing the stop value, and the trade will be
made on the CLOSE of the current bar.

  4=Stop says that the stop will be triggered by the EXTREME price touching
or crossing the stop value, and the trade will be made at the next lower
tradable step below the stop value (stop at $0.4968 would trade at $0.495).



Roy



  {Trade Equity LE}  {V3.0 Long side only}

  {*** user default settings ***}

No:=Input("Entry and exit prices, 1=O 2=C 3=H 4=L 5=Price, ##",11,55,22);

Cp:=Input("Position size, entry and exit delays, $ ## ",0,100033,10000);

Cm:=Input("Entry and exit costs, $$",0,9999,3030);

N:= Fml("PS Fractal Entry")>0;

Ns:=0;

X:= Fml("PS Fractal Exit")>0;

Xs:=Fml("Trade Stop LE");

  {*** end of user area ***}

Nd:=LastValue(Int(Frac(Cp/100)*10));

Xd:=LastValue(Cp-Int(Cp/10)*10);

Cp:=Int(Cp/100)*100;

Xo:=No-10*Int(No/10); No:=Int(No/10);

Cx:=Cm-100*Int(Cm/100); Cm:=Int(Cm/100);

Ns:=If(No=5,Ns,0);

Np:=If(Ns>0,Ns,If(No=1,O,If(No=3,H,If(No=4,L,C))));

N:=N AND Alert(N=0,2); X:=X AND Alert(X=0,2);

N:=If(Nd=0,N,Alert(N,Nd+1) AND Alert(N,Nd)=0);

N:=If(No=5 AND Ns>0,1,If(No<5,N,0));

Xp:=If(Xs>0,Max(L,Xs),If(Xo=1,O,If(Xo=3,H,If(Xo=4,L,C))));

X:=If(Xd=0,X,Alert(X,Xd+1) AND Alert(X,Xd)=0);

X:=If(Xs>0,1,X);

Xp:=If(Xo<5 AND No=5 AND X=0,C,Xp);

Xp:=If(Xo=5 AND Xs>0 AND N AND X,Xs,Xp);

Xp:=If((Max(No,Xo)=5 OR No=1 OR Xo=2) AND Ref(N AND X,-1),Ref(Xp,-1),Xp);

I:=Cum((N+Ns+X+Xs)>-1)=1;

Tr:=BarsSince(I OR N)<BarsSince(I OR X);

Tr:=If((Max(No,Xo)=5 OR No=1 OR Xo=2) AND N AND X,1,Tr);

Np:=If(I AND N=0,C,Np);

En:=(Tr AND Alert(Tr=0,2)) OR I;

Ex:=Tr=0 AND Alert(Tr,2);

Lb:=(Alert(Tr,2)) AND LastValue(Cum(1)-0)=Cum(1);

Ea:=ValueWhen(1,En,If(No=5 AND N AND X,Np,Max(O,Np)));

Ea:=If(No<5,ValueWhen(1,En,Np),Ea);

En:=Tr AND Alert(Tr=0,2);

N:=If(Ex OR Lb,(Cp-Cm)*(Xp/Ea)-Cp -If(Ex,Cx,0),0);

Bt:=If(Alert(Tr,2),1+BarsSince(En OR I),0);

Xs:=If(Alert(Tr,2),(Cp-Cm)*(Xp/Ea)-Cp-If(Ex,Cx,0),0);

Nd:=LowestSince(1,I,Xs);

Ns:=HighestSince(1,I,Xs);

X:=Cum(If((Ex OR Lb) AND N>0,Bt,0));

Xd:=Cum(If((Ex OR Lb) AND N<=0,Bt,0));

Cum(N)+If(Tr AND Lb=0,(Cp-Cm)*(Xp/Ea),Cp);



  {Trade Stop LE} {V3.0 ASX rounding}

  {*** user default settings ***}

No:=Input("Entry and exit price, 1=O 2=C 3=H 4=L 5=Price, ##",11,55,22);

Cp:=Input("Position size,  entry and exit delay, $ ## ",0,100033,10000);

Cm:=Input("Entry and exit costs, $$",0,9999,3030);

Xa:=Input("Stop timing, 1=C/O+ 2=C/C 3=Stop/C 4=Stop, ##" ,11,44,22);

Pt:=Input("Profit target and max loss, 99=N/A, %%",0,9999,2510);

Pd:=Input("Timed exit, 99=N/A, ##",1,99,99);

N:= Fml("PS Fractal Entry")>0;

Ns:=0;

X:= Fml("PS Fractal Exit")>0;

Xs:=0;

  {*** end of user area ***}

Xo:=No-10*Int(No/10); No:=Int(No/10);

Xc:=Xa-10*Int(Xa/10); Xa:=Int(Xa/10);

Nd:=LastValue(Int(Frac(Cp/100)*10));

Xd:=LastValue(Cp-Int(Cp/10)*10);

Cx:=Cm-100*Int(Cm/100); Cm:=Int(Cm/100); Cp:=Int(Cp/100)*100;

Ls:=Frac(Pt/100); Pt:=Int(Pt/100)/100;

N:=N AND Alert(N=0,2); X:=X AND Alert(X=0,2);

N:=If(Nd=0,N,Alert(N,Nd+1) AND Alert(N,Nd)=0);

N:=If(N>0,If(No=1,O,If(No=3,H,If(No=4,L,C))),0);

N:=If(Ns>0 AND No=5,Max(L,Ns),N);

X:=If(Xd=0,X,Alert(X,Xd+1) AND Alert(X,Xd)=0);

X:=If(X>0,If(Xo=1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