The reason for going out of bounds is that arrays are filled with values gradually in different functions, and in this process, one cell is accessed via another cell. Some functions are called twice and fill the array sequentially. But, if there is rubbish in the cells, there is an overrun on the first fill.
The problem could probably be solved by clearing the arrays in advance, but of course this is an additional headache. Pity.
Get used to it.
I always declare an array, set the expected size, fill it with values (initialize it). It's often better to initialize with a non-zero value - it's easier to find an error that way.
I've never seriously worked with MT5, and now I'm transferring a huge project to it at once. Naturally, there are difficulties, one of which is constantly going outside the array. MT4 didn't have such a problem, as it turns out, also because arrays didn't need to be purposely cleared after the announcement. But in MT5 it is necessary. My technology requires gradual filling of the kernel along with changes of its size. The exact size of some arrays is not known in advance. At the same time, because of the great number of loops on arrays in the process of their filling, everything would be out of order. If there were no rubbish in the cells, everything would have worked long ago.
That is, there's rubbish in arrays on one hand and critical error of overruns on the other hand. It's like a draconian condition...
I want to understand why they had to remove automatic clearing of arrays and reduce declared variables to zero, like in MT4?
If we can tolerate variables, we will have to face the problem of constant rubbish collection in large arrays, and we will have to clean them up not only when declaring, but also when resizing... Why?
Also encountered similar difficulties at first.
In my opinion, arrays are filled in a specific way, this should be taken into account in loops often.
Peter, I don't know what you mean?
all about the samehttps://www.mql5.com/ru/forum/293630/page179#comment_10802823
now it's MQL5's fault... ;)
- 2019.02.28
- www.mql5.com
all about the samehttps://www.mql5.com/ru/forum/293630/page179#comment_10802823
now it's MQL5's fault... ;)
Yeah. I'm not used to MQL4.
Nikolay, do not worry about MQL4, everything is fine there. The topic-starter fills the arrays as he likes. That's it.
Well, yes. I'm not used to MQL4.
Of course you do.
Any programmer who respects himself and his programs will not let things slip. In MQL4, if you don't use #property strict, you can refer to an array with size 10 by index 20. And nothing will happen - the program will continue to work, but it is up to the programmer to decide what to use next. If he is smart, he will certainly check and control everything, so as not to get values outside the array, but if he does it "with a bang", he does not care about this control, and "the main thing is that it works, but how it will work somehow...".
The majority of users, who haven't bothered with this, have been complaining about "bad, evil and complicated MQL5", because it does not allow them to fake their own creations as before. But those who originally thought and created code with checking and controlling received data, didn't notice any difference in complexity of languages, and now wonder - "where's the complexity - it's the same...".
I've never seriously worked with MT5, and now I'm transferring a huge project to it at once.
Serious difference in arrays when rewriting
Forum on trading, automated trading systems and trading strategies testing
Features of mql4 language, subtleties and tricks
fxsaber, 2019.02.12 13:12
Features of ArrayResize for multidimensional arraysvoid OnStart() { int Array[][2]; Print(ArrayResize(Array, 7)); // MQL5 - 7, MQL4 - 14 Print(ArraySize(Array)); // 14 }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've never seriously worked with MT5, and now I'm transferring a huge project to it at once. Naturally, there are difficulties, one of which is constantly going outside the array. MT4 didn't have such a problem, as it turns out, also because arrays didn't need to be purposely cleared after the announcement. But in MT5 it is necessary. My technology requires gradual filling of the kernel along with changes of its size. The exact size of some arrays is not known in advance. At the same time, because of the great number of loops on arrays in the process of their filling, everything would be out of order. If there were no rubbish in the cells, everything would have worked long ago.
That is, there's rubbish in arrays on one hand and critical error of overruns on the other hand. It's like a draconian condition...
I want to understand why they had to remove automatic clearing of arrays and reduce declared variables to zero, like in MT4?
If we can tolerate variables, we will have to face the problem of constant rubbish collection in large arrays, and we will have to clean them up not only when declaring, but also when resizing... Why?