PDA

View Full Version : Bars since entry


Ang
4th December 2006, 10:16 PM
Hi Jose,
I am trying to convert tradestation code into metastock coding to backtest a system.
The system has 3 exit rules and the one I am struggling with is:

exit trigger: If ADX(14)<30 AND BSE{bars since entry} > 20
how do we code the BSE?

Thanks

Ang

Jose
5th December 2006, 05:58 PM
Ang, without concrete exits in place, you'll probably need to use MetaStock's PREV function to self-reference the entry signal.

Here's an example:

---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,20);
delay:=Input("Entry and Exit delay",0,5,0);

{ Sample entry condition }
In:=ADX(14)<30;

{ 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;

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

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


jose '-)