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

[amibroker] Correct use of BarsSince inside a loop



PureBytes Links

Trading Reference Links

Hello, hoping someone can help me with this code bug. I'm simply
trying to cover a short position if it has been held for more than 6
days ( 1728 five-min bars). The backtest results indicate that the 'if
else'condition is being ignored. Positions continue to be held well
beyond the 6 days.

If I try declaring HoldTime inside the loop, for e.g.:

HoldTime = BarsSince(ShortSignal[i]==1)
or just HoldTime = BarsSince(ShortSignal[i])

what happens is that AB just hangs indefinitely when I try to verify
AFL syntax from within the formula editor (using AB 5.16)

And when I try declaring HoldTime outside the loop, the 'if else'
condition is ignored (but at least AB does not hang). For now, please
assume that I need the loop. The below code snippet is a piece of a
more involved system. What's wrong?

HoldTime = BarsSince(ShortSignal==1);

for (i = Length; i < (BarCount-TradeDelay); i++)
{
wasLong = longContractCount > 0;
wasShort = shortContractCount > 0;

if (shortContractCount > 0)
{
reachedProfitLevel = C[i] < profitLevel;
if (reachedProfitLevel)
{
coverSignal[i] = 3;
shortContractCount = 0;
}
else if( HoldTime[i] > 1728) // 6 days worth of 5-min bars
{
coverSignal[i] = 2;
shortContractCount = 0;

}
}
// Short entry
if (NOT wasShort AND (longContractCount == 0))
{
shortSignal[i] = 1;
shortContractCount = 1;
}
}
__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___