Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
For what it's worth here's a "Trade Equity" indicator formula that uses external indicators as well as Input()functions and the odd constant.
Remember, MetaStock is a purely sequential language and works from top to bottom without loops or branches
etc. (not counting PREV as I mentioned earlier).
{Trade Equity GV LE}
{Roy Larsen, 20/12/15, v8.6}
{}
A:=Input("Trade Equity LE Options",0,127,0);
B:=Input("Entry, 1=O 2=C 3=H 4=L 5=Stop",1,5,1);
Z:=Input("Exit, 1=O 2=C 3=H 4=L 5=Stop",1,5,1);
G:=Input("Entry $",0,999,5);
J:=Input("Exit $",0,999,5);
D:=Input("Entry/Exit Delays 00-55",0,55,11);
K:=1000; F:=1;{Equity/Factor}
{}
I:=Fml("Green-Red DWF System");
N:= I>0;
Ns:=0;
X:= I<0;
Xs:=0;
{}
F:=ExtFml("GV.SetVar","Cf",If(F=0,1,F));
I:=ExtFml("GV.SetVar","Le",A);
Xd:=LastValue(Int(Frac(D/9.9)*10));
D:=LastValue(Int(D/10));Ns:=(B=5)*Ns;
F:=ValueWhen(1+D,1,If(Abs(F)>1,Abs(F),-F));
M:=If(Ns>0,Min(H,Max(L,Ns)),If(B=1,O,If(B=3,H,If(B=4,L,C))));
N:=N*(Alert(N=0,2)+(Cum(N>-1)=1));
X:=X*Alert(X=0,2)*(Z<5);
N:=ValueWhen(1+D,1,N);N:=If(B<5,N,Ns>0);
N:=If((F<=1)*(F>0)*(F*K<M),(K=0)*N,N);
Xs:=(Xs>0)*Min(H,Max(L,Xs));
Y:=If(Xs>0,Xs,If(Z=1,O,If(Z=3,H,If(Z=4,L,C))));
X:=ValueWhen(1+Xd,1,X);X:=X+Xs>0;
Y:=If((Z<5)*(X=0),C{Y},Y);Y:=If((Xs>0)*N*X,Xs,Y);
I:=Cum(Abs(F)+K+N+X>-1)=1;N:=(I>-1)*N;
Y:=If((N+X=0)*Alert(N*X,2),ValueWhen(2,1,Y),Y);
R:=BarsSince(I+N)<(BarsSince(I+X)+(Cum(N)=1 AND Cum(I+X)=1));
R:=If((N+X>1)*(Alert(R,2)+((D+Xd<1)
*(B<>2)*(Z>1)*(Max(B,Z)>4 OR B<>Z))),1,R);
U:=R*Alert(R=0,2)+I;{M:=If(I*(N=0),C,M);}
Rx:=Alert(R,2);Q:=Rx*(LastValue(Cum(1))=Cum(1));
Z:={Q+}(R=0)*Rx;D:=A<99;A:=ValueWhen(1,U,If(M,M,1));
F:=ValueWhen(1,U,If(F<0,K*Abs(F),
If(F<=1,Int((F*K-G)/A)*A+G,F*A+G)))*(K>0);
B:=Rx*(1+BarsSince(U));
I:=(F-G)*Y/A-F;U:=(F-G)*(A-Y)/A-G;
N:=(Z+Q>0)*If(D,If(K,I-J*Z,Y-A),If(K,U-J*Z,A-Y));
Xs:=Rx*If(D,If(K,I-Z*J,Y-A),If(K,U-Z*J,A-Y));
X:=Cum((Z+Q>0)*(N>0)*(B-1));Xd:=Cum((Z+Q>0)*(N<=0)*(B-1));
M:=Cum(N)+K+R*(Q=0)*If(D,If(K,I,Y-A),If(K,U,A-Y));
I:=ExtFml("GV.SetVar","Mx",Rx*If(D,If(K,(F-G)*
((H/A)-1)-G-J*Z,H-A),If(K,(F-G)*((A-L)/A)-G-J*Z,A-L)));
I:=ExtFml("GV.SetVar","Mn",RX*If(D,If(K,(F-G)*
((L/A)-1)-G-J*Z,L-A),If(K,(F-G)*((A-H)/A)-G-J*Z,A-H)));
I:=ExtFml("GV.SetVar","A",A);I:=ExtFml("GV.SetVar","Cn",G);
I:=ExtFml("GV.SetVar","Cp",K);I:=ExtFml("GV.SetVar","Cx",J);
I:=ExtFml("GV.SetVar","Eq",M);I:=ExtFml("GV.SetVar","F",F);
I:=ExtFml("GV.SetVar","N",N);I:=ExtFml("GV.SetVar","Tr",R);
I:=ExtFml("GV.SetVar","X",X);I:=ExtFml("GV.SetVar","Xd",Xd);
I:=ExtFml("GV.SetVar","Xs",Xs);I:=ExtFml("GV.SetVar","Y",Y); M; {100*(M-K)/K;}
Roy
|