PureBytes Links
Trading Reference Links
|
Hello,
As written here
http://www.amibroker.com/guide/errors/10.html
You must always include condition like bar < BarCount in your for loop to prevent
accessing array elements past BarCount.
So either write:
for ( i = 0; i < myPeriod AND i < BarCount; i++ )
or write:
if( myPeriod >= BarCount ) // enter for loop ONLY if there are enough quotes !!!
{
for ( i = 0; i < myPeriod; i++ )
{
...
}
}
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "Steve Dugas" <sjdugas@xxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, March 24, 2006 7:41 PM
Subject: Re: [amibroker] How to count from arrays?
> Hi,
>
> It is pretty clear that you are exceeding Barcount. Without knowing more,
> here are a couple of thoughts:
>
> 1. I *think* that Barcount is affected by QuickAFL, so if you are running
> your code in a chart it would be less than the normal barcount, something
> closer to the number of visible bars. I have not checked this, just passing
> along a thought. If this is the case, then using SetBarsRequired() or
> zooming out the chart should probably fix the problem.
>
> 2. If running the code in AA, maybe one of your tickers has just a few
> quotes?
>
> Steve
>
> ----- Original Message -----
> From: "John Nelson" <trader@xxxxxxxxxxxxxxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Friday, March 24, 2006 12:49 PM
> Subject: [amibroker] How to count from arrays?
>
>
>>
>> All,
>>
>> I'm counting the number of 1's and 0's from arrays which are the results
>> of our well-known set of indicators. The 1's and 0's actually represent
>> peaks and valleys and I'd like an indication of how many of them there
>> are within a specific period starting from the current bar and going back
>> myPeriod bars. I've noticed something strange though.
>>
>> If I try to count in this manner....
>>
>> for ( i = 0; i < myPeriod; i++ ) {
>> if ( myarray[i] == 1 )
>> total1 = total1 + 1;
>> else
>> total2 = total2 + 1;
>> }
>>
>> I stumble across a runtime error that admonishes me for having a subscript
>> that is not between 0 ... (BarCount-1). However the following snippet of
>> code avoids the runtime error...
>>
>> for ( i = 0; i < BarCount && i < myPeriod; i++ ) {
>> if ( myarray[i] == 1 )
>> total1 = total1 + 1;
>> else
>> total2 = total2 + 1;
>> }
>>
>> Now this is really strange since I know "myPeriod" is far less than the
>> BarCount. Could it be that AFL operations aren't striclty linear in that
>> the results of my array operations preceeding the for loop are not yet
>> complete? Could it be that I don't understand how array subscripts work?
>>
>> So what is the proper way to count the number of 1's and 0's in an array
>> starting from the most recent bar and working back?
>>
>> -- John
>>
>>
>>
>>
>> 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 other support material please check also:
>> http://www.amibroker.com/support.html
>>
>>
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
> 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 other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
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 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/
<*> 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/
|