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

Re: how to carry entry price to later day



PureBytes Links

Trading Reference Links

David

> When I create a new system test, how to carry a constant, this constant
> represent entry price, to later day test.  For example:  if the test
satisfy
> "enter long", I want keep entry price and then I want test "close long" if
> current price - entry price > $2.00 or other criteria to see which one
> happen first.

I know the indicator below is more complex than you require, but I am sure
that it can be adapted to meet your need. The idea behind this indicator is
that by using an entry (Fml("Your Entry");) and an independant exit not
based on entry price (Fml("Your Exit");) we can create a 'flag' (or 'latch'
if you prefer) that remembers the entry price (variable Tr) and check for
profit or loss targets to signal the close of the trade. Subsequent entry
signals have no effect on the indicator until the profit target, stop loss,
or normal exit have been reached. If you need help with simplifying and/or
adapting this indicator you can email me at rlarsen@xxxxxxxxxxxxxx .

Roy

  {Trade Stop}
No:=Input("Enter 1=O 2=C 3=Stop",1,3,2);
Xo:=Input("Close 1=O 2=C 3=Stop",1,3,2);
Nd:=Input("Entry Delay",0,3,0);
Xd:=Input("Close Delay",0,3,0);
Pt:=Input("Profit Target %",1,99,20)/100;
Ls:=Input("Maximum Loss % ",1,99,10)/100;
Cm:=25;
Cp:=5000;
N:=Fml("Your Entry");
X:=Fml("Your Exit");
N:=If(No=3,N,Ref(N,-Nd));
X:=If(Xo=3,X,Ref(X,-Xd));
Np:=If(No=1,O,If(No=2,C,N));   {Entry price}
Xp:=If(Xo=1,O,If(Xo=2,C,X));   {Close price}
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,Np,0),
If(X>0 OR If(Xo<3,Xp,H)>=PREV*Pf OR
If(Xo<3,Xp,L)<=PREV*Lf,0,PREV));
Xb:=Tr=0 AND Alert(Tr>0,2);      {Exit bar}
Ev:=ValueWhen(1,(Cum(N>-1 AND X>-1)=1) OR Tr>0,Tr);   {Entry value}
Sp:=If(Xb,If(Xo<3,If(Xp>=Ev*Pf,Xp,0),
If(O>=Ev*Pf,O,If(H>=Ev*Pf,Ev*Pf,0))),0);
Sl:=If(Xb,If(Xo<3,If(Xp<=Ev*Lf,Xp,0),
If(O<=Ev*Lf,O,If(L<=Ev*Lf,Ev*Lf,0))),0);
Tr; Tr*Pf; Tr*Lf; {Entry amt, Target, Stoploss}
If(Xb,If(Xo<3,1,If(Sp>0,Sp,If(Sl>0,Sl,X))),0);