System Stopped – Array Problem
Forums › ProRealTime English forum › ProOrder support › System Stopped – Array Problem
- This topic has 34 replies, 3 voices, and was last updated 4 months ago by PeterSt.
-
-
07/17/2024 at 12:05 PM #235380
Has anybody used Arrays and their Algo was Stopped with the following error message?
The trading system was stopped because the code tries to : – define or access an invalid index in an array : Valid indexes are any strictly positive integer less than 1000000 : [1, 2 ,3, …, 1000000] –
or access an index that has not been previously set in the array : You can check if an index has previously been set using the “IsSet” function : “IsSet($MyArray[MyIndex])”
Please NOTE: My Array does NOT contain either of the 2 errors above, I checked as follows …
- My Array Indexes are 0 to 16
- Indexes 0 to 16 all show a value … proven / seen by using GRAPH IsSet($Fib[0]) GRAPH IsSet($Fib[1]) GRAPH IsSet($Fib[2]) … etc up to GRAPH IsSet($Fib[16])
It would appear the above error message is another ‘error fudge message’ i.e. does not directly apply / relate to the cause of the Stoppage??
Any thoughts / comments / ideas to try and solve appreciated.
07/17/2024 at 12:42 PM #23538407/17/2024 at 12:51 PM #23538707/17/2024 at 1:41 PM #23539507/17/2024 at 2:33 PM #235400Fight fire with fire, trying to use logic against the logic!
On the assumption that the error message is right and there was an invalid index…
To be invalid it must have been one of…
. undefined, not a integer, negative, > 9999999.
To be undefined, if index is a variable, then index = undefined, but you maybe would expect undefined var error message.
Or, the index has been increased to a value which exceeds the current defined array elements.
To be negative , some calculation of the index resulted in a negative value, 16-17=-1.
(array index) – (array element count) = -1
Similar, calculation turning integer into decimal.
To exceed 1 million elements, then array would have to keep increasing in size in background, however only a small amount of elements are used.
When max reached , error message.
I would think if the error appears random and not repeatable, then it could be an edge case in the code, eventually triggering 1 of the above.
It may not be possible to see the error using graph because, when the error is hit in back test it may show up as undefined and not an error message.
Where by in algo it error’s, and stops bot.
A few tests with an array in back test didn’t through error if index undefined directly or indirectly on undefined element.
Using trial and error, with code validating index is not one of the above may help track down
Does the element exist and index fall within require range.
If isset(index) and index >= 0 and index <= 16 then /// index valid
I think in summary, how can a index be invalid or become invalid.
By not being set, by calculating, being out of sequence with defined elements,
or by inadvertently increasingly defining elements, though not using them.
Now moving beyond that, is the array were looking at the right array!
Is there additional code, external code , like average[]() type commands etc., or called code with possible arrays.
I’m sure that, when you look at the code version from the proOrder window it includes all the code used, no sure to what depth though for sum.
Could run two versions in demo, 1 normal, 1 with a check 0n the validity of the index to see in both or one errors.
If you can catch the error and avoid algo stopping, you might be able to encode a number of error conditions within the contract size and then quit, if it comes to that, since there no graph in algo.
Any way that’s what I’m thinking.
1 user thanked author for this post.
07/17/2024 at 2:47 PM #23540207/17/2024 at 3:14 PM #235406That was a data dump straight out of brain, just pressed print…
You could look at your code from a couple of points of view.
Is the code doing what I think its doing, have I only got 17 elements, are all my elements defined, does my index stay within range…
Or, is code making more element than I think, is my index moving out of range or invalid….
And then figure out how you can prove it.
Hopefully, you find the answer, but worse case you know what it’s not and then focus on new idea’s.
1 user thanked author for this post.
07/17/2024 at 4:35 PM #235414Valid indexes are any strictly positive integer less than 1000000 : [1, 2 ,3, …, 1000000] –
My Array Indexes are 0 to 16
does not comply to what’s in the first quote. That suggests the Arrays are 0 based (I don’t know or forgot). So if your text in the second quote is literal, you are using element 0. -error-
1 user thanked author for this post.
07/18/2024 at 9:43 AM #235463From array link, @Nicolas started, info implies, that an array index includes zero,’0′ as a valid index.
https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/
Though, where [n] is commonly used in other situations, using zero can throw ‘positive integer’ error along with being negative.
ex, average[0], higher[0]
Another common one is, barindex[var], where var takes barindex negative when its size gets greater than barindex.
ex. barindex =100, var = 101, barindex[var] = -1
However, average[10000] , barindex[10000],works even though bars maybe only be 1000, just stays undefined or not able to see the result since out of range of display.
Also these others can exceed 1,000,000.
Then there’s others where zero is ok , close[0], barindex[0].
However, when you do get an error message, there usually some indication what keyword statement caused error.
So, depending on custom code, its possible to use a variable who’s value may work in one situation but fail in another.
The failure may be random or time delayed since a conditional edge case may have to be met to execute the code for failure.
And since, indicators, back test and algo’s, can, or appear to do different things, you can’t assume an error in one equates to the error in other.
Or probably a better way of thinking is that an error in one may ‘not’ error in the other.
This may be to the different platform code doing checking, which is not on the other stages.
I suppose it would be very time consuming to test every keyword statement in all modules and situations to be able to identify the limits of the code in general.
Only way is to come up with a testing strategy, and/or code snippets to verify the code stays within requirements and known limits.
Code is like hydrogen, simple, only being 1 atom in size, it’s very useful in certain applications, however trying to contain a load of it in one place is quite difficult, it finds ways of leaking out!
1 user thanked author for this post.
07/18/2024 at 10:48 AM #235465@PeterSt, didn’t get straight away what you were referring to, we’ll spotted.
The error message, doesn’t explicitly state ‘zero’ as an index, where array info does.
And zero is not a positive integer.
Not sure what this means…
Is it an oversight and you can use zero as an array index, which it appears you can.
Or, you can use zero but not in algo. There could be an inconsistence if you use it.
1 user thanked author for this post.
07/18/2024 at 1:56 PM #235475I fixed Algo1 that prompted me to ask for help … I had 8 array elements listed then a few lines of code then the other 8 elements listed. I amended so all 16 array elements were listed consecutively (no code between element 8 and 16 etc) and it worked / no Stoppage / no error message.
For reference / info re index 0 :
I still got the stoppage (with error as I posted above) if my elements started at 0 or started at 1.As you have both been so helpful and clearly are more knowledgeable than me re coding, attached is (a completely different) Algo2 which works fine in backtest, but gets Stopped when runing on Live data with the following error message …
The trading system was stopped because the code tries to : – define or access an invalid index in an array : Valid indexes are any strictly positive integer less than 1000000 : [1, 2 ,3, …, 1000000] –
or access an index that has not been previously set in the array : You can check if an index has previously been set using the “IsSet” function : “IsSet($MyArray[MyIndex])”
Instrument, TF etc are in the Algo title. In order to fault find quickly, I ran it Live on 1 min TF as that saved waiting 5 mins between each tweak!
I even got ChatGPT on this one a few weeks back, but despite about 4 versions of AI revised code (all looking logical etc) the problem remained.
The version attached is the original version with no AI amendments. I could post the AI amended version if you wish?
07/18/2024 at 3:53 PM #23547807/18/2024 at 4:15 PM #23547907/18/2024 at 4:30 PM #23548207/18/2024 at 4:47 PM #235483 -
AuthorPosts
Find exclusive trading pro-tools on