PureBytes Links
Trading Reference Links
|
Tim
Here are two possible options for the 'Trade' variable for you to build in
your profit exit. I strongly suggest that you do not include your profit
exit with the standard exit code (code in braces). If the exit is entry
dependant then that exit must be controlled from within the 'Trade'
variable. That's the only place where you can pull all the relevant
information together and examine it as a whole.
Trade:=If(PREV=0,
If(LE,C,
If(SE,-C,0)),
If((PREV>0 AND (LX { OR C>PREV*1.1 } )) OR
(PREV<0 AND (SX {OR C<Abs(PREV)/1.1 } ))
{OR condition X}
{OR condition Y} ,0,PREV));
In the above example I have commented out the profit stops so you can
compare the output directly with what you already have. The code below
should be much the same as yours in that it can swing directly from long to
short and vice versa. The code above will not allow a short entry to cause a
long exit, etc., and this method of construction is preferred in that the
latch will always reset to zero before setting another trade. The advantage
of this is that it allows the use of ValueWhen(1,PREV=0, "whatever value I
like"), i.e. you can reference the start of the trade to retrieve any price
or indicator value. This is more difficult to achieve when moving directly
from long to short or short to long as there is no bar where PREV=0.
Take care if you are using the current value of ATR, or whatever, to base an
exit stop on - you need to remember that the current bars ATR is not
available until you have the current CLOSE. The latch will work fine but the
timing may be impossible to replicate in real life. In some situations with
PREV you may also need to use Ref(PREV,-1). Can't think of one offhand but
the situation can arise.
Trade:=If(PREV=0, {not in any trade}
If(LE,C, {set long entry price}
If(SE,-C,0)), {set short entry price}
If(PREV<0 AND LE,C, {switch from short to long}
If(PREV>0 AND SE,-C, {switch from long to short}
If((LX AND PREV>0) OR
(SX AND PREV<0),0,PREV))));
I have not included your profit stops in this code but merely set it up to
swing on the same bars as your own 'Trade' variable.
After looking at your existing 'LE' I decided that there is no point trying
to move what is effectively a trailing stop into the 'Trade' variable.
Contrary to earlier comments I now see no reason why this should not work
exactly as you intended.
I hope I haven't missed the point completely.
Roy
----- Original Message -----
From: "timinwaedi" <timinwaedi@xxxxxxxxxxx>
To: <equismetastock@xxxxxxxxxxxxxxx>
Sent: Thursday, May 22, 2003 4:36 AM
Subject: Re: [EquisMetaStock Group] Referencing the most recent occurrence
> --- In equismetastock@xxxxxxxxxxxxxxx, "Roy Larsen" <rlarsen@xxxx>
> wrote:
> > Tim
> >
> > > Can anyone suggest how I can reference the price at which a the
> most
> > > recent occurrence of a long entry took place. I need to know this
> > > price in order to define a stop loss or stop profit exit.
> >
> > Here's some more "latch" practice.
> >
> > There are many ways you can configure this latch. By not storing
> the entry
> > price in the latch but referencing it using ValueWhen(entry) we
> eliminate
> > one PREV.
> >
> > Have fun.
> >
> > Roy
> >
> > {Trade Stop Tim}
> > N:=Fml("long entry signal (price spike)");
> > X:=Fml("nominal exit");
> > I:=Cum(N+X>-1)=1;
> > Tr:=If(PREV<=0,N>0,If( X {standard exit}
> > OR {10% profit stop}
> > ValueWhen(1,PREV=0, N {entry price} )>=C*1.1,
> > {OR any other entry related exit}
> > -1 {negative spike exit signal},
> > 1)); {or trade continues}
> > Xb:=Tr<0; {exit bar}
> > Tr:=Abs(Tr)*ValueWhen(1,I OR (Alert(Tr=0,2)
> > AND Tr),N); {trade acitive * entry price}
> > Tr;
>
> Thanks Roy,
>
> I've included an expert which functions ok, and I wanted to
> add to the long and short exit conditions a percentage profit
> target.I've added pseudo code to the exit conditions which I trust
> will explain my plight.
>
> ------------------------------
> {Enter on correction in trend with ATR stop or 10% profit target}
>
> {Long Entry}
>
> LE:=C <= Ref(C,-1) AND
> Ref(C, -1) <= Ref(C, -2) AND
> Ref(C, -2) <= Ref(C, -3) AND
> Mov(C, 21, E) > Ref(Mov(C, 21, E), -1)
> OR
> C <= Ref(C,-1) AND
> Ref(C, -1) <= Ref(C, -2) AND
> Ref(C, -2) <= Ref(C, -3) AND
> Ref(C, -3) <= Ref(C, -4) AND
> Mov(C, 21, E) > Ref(Mov(C, 21, E), -1);
>
> {Short Entry}
>
> SE:=C >= Ref(C,-1) AND
> Ref(C, -1) >= Ref(C, -2) AND
> Ref(C, -2) >= Ref(C, -3) AND
> Mov(C, 21, E) < Ref(Mov(C, 21, E), -1)
> OR
> C >= Ref(C,-1) AND
> Ref(C, -1) >= Ref(C, -2) AND
> Ref(C, -2) >= Ref(C, -3) AND
> Ref(C, -3) >= Ref(C, -4) AND
> Mov(C, 21, E) < Ref(Mov(C, 21, E), -1);
>
> {Long Exit}
>
> LongNumatr:=4;
> LongPeriods:=4;
> LongSL:=L-LongNumatr*ATR(LongPeriods);
> Longstop:=If(L<PREV,LongSL,If(LongSL>PREV,LongSL,PREV));
> LX:=L<Ref(Longstop,-1){or high >= Long entry price * 1.1};
>
> {Short Exit}
>
> ShortNumatr:=4;
> ShortPeriods:=4;
> ShortSL:=H+ShortNumatr*ATR(ShortPeriods);
> Shortstop:=If(H>PREV,ShortSL,If(ShortSL<PREV,ShortSL,PREV));
> SX:=H>Ref(Shortstop,-1){or low<= Short entry price /1.1};
>
> Trade:=If( LE=1, 1, If(SE=1, -1, If((LX AND PREV=1) OR (SX AND
> PREV=-1),0,PREV)));
>
> Long Entry: cross( trade, 0.5 )
> Short Entry: cross( -0.5, trade )
> Long Exit: cross( 0.5, trade )
> Short Exit: cross( trade, -0.5 )
>
> -----------------------------------------------------
>
> I understand that the use of the ValueWhen function can be used to
> store values of most recent occurrences, but am not sure how to
> integrate it. Would be grateful for your remarks.
>
> Regards,
>
> Tim
>
>
>
>
> 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/
>
>
>
>
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/uetFAA/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/
|