[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Is there a way to exit unprofitable trades after a certain number of bars?



PureBytes Links

Trading Reference Links

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 amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@xxx> 
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 amibroker@xxxxxxxxxxxxxxx, "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;
> >
>



------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/