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

Re: [EquisMetaStock Group] Metastock Fixed Trailing Stop Loss



PureBytes Links

Trading Reference Links

Here's an example on the more complex side. This code is intended as a
companion for 'Trade Equity' so don't be concerned if it doesn't make much
sense. It's a little dated and probably not bug-free, but if you look at the
first 'Tr' variable you'll see how a range of possible exits are tested by
the latch. The second 'Tr' variable to cover intraday trade situations when
using EOD data (entry and exit on the same bar).

Roy

  {Trade Stop LE Trail} {V2.7 long equal}
No:=Input("Enter 1=O 2=C 3=H 4=L 5=Stop",1,5,2);
Xo:=Input(" Exit 1=O 2=C 3=H 4=L 5=Stop",1,5,2);
Nd:=Input("Entry Delay",0,3,0);
Xd:=Input(" Exit Delay",0,3,0);
Cm:=Input("Entry Commission $",0,99,50);
Cx:=Input(" Exit Commission $",0,99,50);
Cp:=10000; {* trade capital *}
Ls:=12.5 {stop loss % } /100;
Xc:=2; {timing, 1=C/O+ 2=C/C 3=Stop/C 4=Stop}
Am:=3; {multiplier}
Ap:=3; {trail from price, 1=MP 2=C 3=H 4=L}
N:=Cross(Mov(C,15,E),Mov(C,25,E));
Ns:=0;
X:= 0;
Xs:=0;
  {end of user area}
Ap:=If(Ap=2,C,If(Ap=3,H,If(Ap=4,L,MP())));
Am:=Ap-ATR(10)*Am; Ap:=Ref(Am,-1);
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(No=5,If(Ns>0,Max(L,Ns),0),N);
X:=If(Xd=0,X,Alert(X,Xd+1) AND Alert(X,Xd)=0);
X:=If(X>0,If(Xo=1,O,If(Xo=3,H,If(Xo=4,L,C))),0);
X:=If(Xs>0 AND Xo=5,Max(L,Xs),X);
Lf:=Min(1,(Cp*(1-Ls)+Cx)/(Cp-Cm));
Tr:=If(PREV=0,If(N>0 AND X=0 AND
 (No=2 OR If(Xc<3,C,L)>Max(Lf*N,Ap)),N,0), If(X>0 OR
 If(Xc<3,C,L)<=HighestSince(1,PREV=0,Ap) OR
 (If(Xc<3,C,L)<=Lf*PREV AND Ls<>.99),0,PREV));
Tr:=If(Alert(Tr>0,2)=0 AND N>0 AND
(((If(Xc<3,C,L)<=Max(Lf*N,Ap))
AND No<>2) OR (X>0 AND Nd+Xd<1 AND No<>2 AND
Xo>1 AND (Max(No,Xo)>4 OR No<>Xo))),-N,Tr);
Xb:=(Tr=0 AND Alert(Tr>0,2)) OR (Tr<0 AND Alert(Tr=0,2));
Cx:=ValueWhen(1,Cum((N+Ns+X+Xs+Ap)>-1)=1 OR Tr<>0,Abs(Tr));
Cm:=Max(HighestSince(1,Alert(Tr,2)=0,Ap),Cx*Lf);
Cm:=If(Xb,If(Xc<3 AND C<=Cm,C,If(Xc>2 AND L<=Cm,Cm,0)),0);
Cm:=If(Cm>0,If(Cm>=.5,PREC(Cm,2),If(Cm<.1,PREC(Cm,3),PREC(Cm*2,2)/2)),0);
Cm:=If(Xc=4 AND Cm>0,Max(L,Min(If(Tr<0,H,O),Cm)),Cm);
Cm:=If((Xc=2 OR Xc=3) AND Cm>0,C,If(Xc=1 AND Xo<5,Ref(Cm,-1),Cm));
Cm:=If(Xc=1 AND Cm>0 AND Xo<5,O,Cm);
Cx*Alert(Tr<>0,2); Cx*Lf*Alert(Tr<>0,2);
HighestSince(1,Alert(Tr<>0,2)=0,Am)*Alert(Tr<>0,2);
If(Cm>0,Cm,If(Xs>0 AND Xo=5,X,0));

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Low on Ink? Get 80% off inkjet cartridges & Free Shipping at 77Colors.com.
We have your brand: HP, Epson, Lexmark, Canon, Compaq and more!
http://www.c1tracking.com/l.asp?cid=5981
http://us.click.yahoo.com/DmnqpB/IyhGAA/ySSFAA/BefplB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


Attachment:
snap.gif

Attachment: Description: "Description: GIF image"