Reading this I assume you are using real time intraday data. If that is true you can store the bar time in a static var when the buy/short condition is true. TimeNum gives the time of the last complete bar. So if the current bar time us three bars later and you have a loss you can get out. Or you can store the system time, Now(4), the same way and wait the number of minutes you select and exit the trade. I feel that systime is better IMO because your trade can come mid bar and using it you can wait however long you want.
But GP is right, if your code allows many buy signals in a row this will only work if you manage multiple signals or you will get invalid results. One way to do that is update the static var only if it is 0, use it for comparison and set the static var to 0 when you exit the trade. Barry --- In [email protected], "gp_sydney" <[EMAIL PROTECTED]> wrote: > > Due to the way array maths works, you can't normally use operations of > the form: > > <exitCondition> = BarsSince(<entryCondition>); > > This is because the entry array will likely have more signals than > will ultimately be used once the exit array is defined (ie. there will > likely be entry signals ignored because there's already a trade in > progress), and BarsSince() will always be from the most-recent entry > signal, even if it's one that's ultimately ignored. The first thought > is usually to remove the excess entries with ExRem(), but you can't do > that until after the exit array has been defined, so you have a > Catch-22 situation. > > For iterative operations like this, you need to use a loop and work > through the arrays bar by bar, so that you can both create the exit > array and remove excess entry signals at the same time. > > So you don't need to use the CBT, just a loop. > > GP > > > --- In [email protected], "trustdnb" <trustdnb@> wrote: > > > > Is there a way to exit unprofitable trades after a certain number of > > bars without using the CBT? Essentially what I want is an Nbar stop > > that only triggers on unprofitable trades, without stopping winners. > > > > My weak attempt did not work: > > > > Short = /*short fomula */; > > ShortExit = BarsSince(Short) > 12 AND C >= ValueWhen(Short, C); > > Cover = ShortExit; > > >
