PDA

View Full Version : multiple exits


markcollins
27th December 2006, 10:19 PM
I want to test a system with multiple exits. I am trying to have a 28 day channel stop for the first 28 days and then switch to a 4 day channel stop.

I came up with the following code. Is this the correct way to code for what I am trying to do?

Stop1 := C<Ref(LLV(L,28),-1);
Stop2 := C<Ref(LLV(L,4),-1);

EntryTrigger := Cross(MACD(),Mov(MACD(),9,E))
EntryPrice :=Ref(C,-1) + (Ref(ATR(25),-1)*0.25);
NewEntryPrice := If(0>EntryPrice,O,EntryPrice);
ExitTrigger := If((BarsSince(EntryTrigger)>24),Stop2,Stop1);
ExitPrice := OPEN;
InitialStop:=C-(3*ATR(25));

regards
Mark

Jose
1st January 2007, 06:08 AM
ExitTrigger := If((BarsSince(EntryTrigger)>24),Stop2,Stop1);

This won't work because there may be multiple EntryTrigger signals before the exit, and this would reset the bar count.

Test example:

---8<---------------------------------------------
Stop1:=1;
Stop2:=2;

EntryTrigger:=Cross(MACD(),Mov(MACD(),9,E));
ExitTrigger:=
If((BarsSince(EntryTrigger)>24),Stop2,Stop1);

EntryTrigger;-ExitTrigger
---8<---------------------------------------------


Mark, you'll probably need to use PREV functions to deal properly with this issue. Here is an example of this method:

---8<---------------------------------------------

{ Long entry-related timed exit

©Copyright 2004~2006 Jose Silva
For personal use only.
http://www.metastocktools.com }

{ User inputs }
exitPds:=Input("Exit trade at x periods",1,2600,10);
delay:=Input("Entry and Exit delay",0,5,0);
plot:=Input("signals: [1]Entry + Exit, [2]All entries",1,2,1);

{ Sample entry conditions }
In:=Cross(C,Mov(C,50,S))
AND V>Mov(V,50,S)*2;

{ Entry-related exit latch }
latch:=If(PREV>0,
If(BarsSince(PREV<=0)<exitPds,1,-1),In);

{ Clean Entry & Exit signals }
entry:=latch=1 AND Alert(latch<1,2);
exit:=latch=-1;

{ Select Clean signals or All entries }
signals:=If(plot=1,entry-exit,In);

{ Plot signals in own window }
0;Ref(signals,-delay)

---8<---------------------------------------------


jose '-)