PDA

View Full Version : Time based exit with a twist


gsandral
15th September 2005, 03:20 PM
Dear Jose

Thanks for your last reply to my double exit question. It works very well in some systems. This time around I would like to test a time based exit with a twist.

It goes Something like this....

If bars since entry is >= 24 then exit when %R > 90, otherwise exit when bars >= 32.

any coding suggestions :)

Regards Graeme

Jose
16th September 2005, 06:24 AM
Graeme, entry-related exits are always a pain to code in Metastock, since the exit then affects the next entry.

Take a look at this entry-related timed exit indicator - maybe you can modify it for your own needs.

========================
Entry-related timed exit
========================
---8<--------------------------

&#123; Long entry-related timed exit &#125;

&#123; ©Copyright 2004~2005 Jose Silva
For personal use only.
http&#58;//www.metastocktools.com &#125;

&#123; User inputs &#125;
exitPds&#58;=Input&#40;"Exit trade at x periods",
1,2600,10&#41;;
delay&#58;=Input&#40;"Entry and Exit delay",0,5,0&#41;;

&#123; Sample entry conditions &#125;
In&#58;=Cross&#40;C,Mov&#40;C,21,E&#41;&#41;;

&#123; Entry-related exit latch &#125;
latch&#58;=If&#40;PREV>0,
If&#40;BarsSince&#40;PREV<=0&#41;<exitPds,1,-1&#41;,In&#41;;

&#123; Clean Entry & Exit signals &#125;
entry&#58;=latch=1 AND Alert&#40;latch<1,2&#41;;
exit&#58;=latch=-1;

&#123; Plot signals in own window &#125;
0;Ref&#40;entry-exit,-delay&#41;

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



jose '-)