Re: [amibroker] Re: error 10. subscript out of range

 

Hi TJ

Thank you for the tip.







On Mon, Apr 25, 2016 at 1:14 PM, Tomasz Janeczko groups@amibroker.com [amibroker] <amibroker@yahoogroups.com> wrote:
 

Hello,

I would not recommend bypassing. The code should execute cleanly with every bar count starting from 1.

Instead in your code you should have code like that:


HTFBarindex = 0;

// check the index !
if(
LTFBarindex < BarCount ) HTFBarindex = LowToHighTFBarindex[LTFBarindex];


Then the code would run cleanly.

You just can *not* assume that you always have more than X bars.

Best regards,
Tomasz Janeczko
amibroker.com

On 2016-04-25 11:44, 'B. Pitatzidis' bobptz@gmail.com [amibroker] wrote:
Hello TJ

I see what you say.  Since my requirement is the entire database (usually bigger than 200) I could use something like this (status("ActionEx") <> actionExEditVerifyFormula), to disable syntax checking in the parts of the formula that show error 10:

SetBarsRequired( -2, -2 );
.....
AbsBarcount = Status( "quickaflfirstdatabar" ) + BarCount;
.....
if (status("ActionEx") <> actionExEditVerifyFormula )  // dissable Editor syntax checking here
{
TFdatetime[AbsBarCount - 1] = xxxx;
...
}

I found that KB code more useful for preventing runtime errors, which could help discover a logical error.  In my case it is only a syntax error, not happening in runtime.  I need to make this bypass in 10-20 places but yes, it is doable.

 

On Mon, Apr 25, 2016 at 12:00 PM, Tomasz Janeczko groups@amibroker.com [amibroker] <amibroker@yahoogroups.com> wrote:
 

Hello,

"I cannot use the APPLY in the editor."

Sure you CAN. Did you read the article to the very end ???

I suggest you really read that especially the last sentence and code block at the very end.
http://www.amibroker.com/kb/2014/09/22/do-not-make-assumptions-on-number-of-bars/

I am always surprised when people find it easier to send dozens of e-mails instead of just reading
ready-to-use answer from KB.

If you still can not find it, here is verbatim copy of last sentence from KB
http://www.amibroker.com/kb/2014/09/22/do-not-make-assumptions-on-number-of-bars/
article that I pointed already 4 posts ago.

=== Quote start ===

What to do if your formula, for some reason, really requires fixed number of bars? Well, the answer is that you should check if you really get as many bars as you think:

if( BarCount 300 // check first if you have enough bars  {     // here we know that we have more than 300 bars     for( 0300i++ )     {        Close];      }  }

=== Quote end ===

Best regards,
Tomasz Janeczko
amibroker.com

On 2016-04-25 10:26, 'B. Pitatzidis' bobptz@gmail.com [amibroker] wrote:
TJ

My problem now is I cannot use the APPLY in the editor.  I wish there was a way to tell the editor to count ALL bars.

I use a complex script with multiple timeframes and using absolute bar counting is the only way I could think to keep track of the barindex between different timeframes.  ie what barindex from lower timeframe corresponds to which barindex from the higher timeframe.

Here is a small demo I wrote for this:
http://bbb-amibroker.blogspot.gr/2016/03/timeframeset-and-barindex-of-compressed.html

If somebody could suggest a better way to relate barindexes from different timeframes, without the need for 
SetBarsRequired( -2, -2 ),   then the script would become much more efficient.





On Mon, Apr 25, 2016 at 11:05 AM, Tomasz Janeczko groups@amibroker.com [amibroker] <amibroker@yahoogroups.com> wrote:
 

Hello,

Thank you very much for your e-mail.

As written in the article, you should not make assumptions on how many bars you
get because different symbols may use different counts.

AFL editor for "Syntax Check" uses not more than 200 bars for two reasons:
1. To catch coding mistakes exactly like this one, i.e. making assumptions on number of bars
2. To make syntax checks faster for very complex formulas

Best regards,
Tomasz Janeczko
amibroker.com

On 2016-04-25 08:43, 'B. Pitatzidis' bobptz@gmail.com [amibroker] wrote:
Thank you for the link TJ.

I think this answers my question:
"during AFL Editor's Verify Syntax not more than 200 most recent bars are used"

In my code I use something like:
SetBarsRequired( -2, -2 );
.....
AbsBarcount = Status( "quickaflfirstdatabar" ) + BarCount;
.....
TFdatetime[AbsBarCount - 1] =

The last line triggers the error ONLY from the Editor.  Makes sense if inthe editor the barcount is only 200.









On Mon, Apr 25, 2016 at 9:21 AM, Tomasz Janeczko groups@amibroker.com [amibroker] <amibroker@yahoogroups.com> wrote:
 

Hello,

"I am pretty sure my indexes are not out of range"

If program says it is out of range you can be 100% sure that it really *is* out of range.

As always everything is covered by documentation:
http://www.amibroker.com/kb/2014/09/22/do-not-make-assumptions-on-number-of-bars/


Best regards,
Tomasz Janeczko
amibroker.com



On 2016-04-25 08:14, 'B. Pitatzidis' bobptz@gmail.com [amibroker] wrote:
Hello

I am having "Error 10" (subscript out of range), but I am pretty sure my indexes are not out of range.  The problems occurs only in the editor, when I click the Apply button.  The script runs without any problems and produces correct results when I run it normally. 

Here is a typical error message I get:
Error 10. Array subscript out of range. You must not access array elements outside 0..(BarCount-1) range. You attempted to access non-existing 11454-th element of array.

However the BARCOUNT is 11491 (bigger than 11457). 

I checked this guide and it is definetely not my case:
http://www.amibroker.com/guide/errors/10.html

I assume it is some setting in the editor or cache that I need to set?  I searched all of them and increased them to over 20.000.
 










__._,_.___

Posted by: "B. Pitatzidis" <bobptz@gmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (10)

Upgrade your account with the latest Yahoo Mail app
Get organized with the fast and easy-to-use Yahoo Mail app. Upgrade today!

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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


.

__,_._,___


EmoticonEmoticon