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

[amibroker] Re: Correct use of BarsSince inside a loop



PureBytes Links

Trading Reference Links

Where and how is ShortSignal first defined? You define it iteratively
near the end of the loop, but HoldTime is based on its value before
entering the loop. If it was just all Null before that, then the test
for HoldTime[i] > 1728 would always fail (ie. effectively be False).

GP


--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> 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
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/