Errors, bugs, questions - page 1999
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Let's take an indicator buffer array for example: When initializing an indicator, the buffer has a zero length. What is there to initialize with zeros? When another index is added, is it forced to be zeroed and then filled with some value??? What is this zeroing or filling with EMPTY_VALUE for? And if there is a need to assign PLOT_EMPTY_VALUE and not 0 or EMPTY_VALUE or to force one, but we need another... No matter how you slice it, you end up wasting your time...
And a custom array... The array is declared for some data different from zero and EMPTY_VALUE. So what's the purpose of forcefully initializing it with something?
So it turns out that performance is affected in most cases.
I'm obviously out of touch with life. To my mind, the indicator buffer always has the length equal to the number of bars. And the refusal of its initialization in MT5 leads to displaying of rubbish on the screen. It turns out that the explicit initialization is obligatory. And it is not clear why it is simply transferred from the core (as it was in MT4) to the MQL programmer. I haven't seen any real arguments that somehow you can speed up without initialization and still get the rubbish display.
I'm not saying anything about a custom dynamic array - there's really a rule: the one who allocated it, is responsible for correct cleaning. ArrayInitialize is useful in many cases. It's not a question of speed, but the correctness of the program. Prioritize: fast and/or correct. Usually, some checks for correctness and data preparation require additional time (although minimal), but you can't do without it - miracles never happen.
I'm not saying anything about a custom dynamic array - the rule really applies there: whoever allocated it is responsible for cleaning it correctly.
Don't insult the arrays.
In MT4 it will always return false, because without rubbish - all zeros. In MT5 it is true.
Therefore, the same code in the MT4 tester will always show identical results from run to run. In an MT5 tester it will not.
In MT4 it will always return false, because without rubbish it is all zeros. In MT5 it is true.
Is this a test that MT4 fills the array with zeros? Then we have to keep in mind that if ArrayResize uses a third parameter with reserve, then subsequent reallocations within the reserve will not initialise anything. There will be rubbish. I recommend doing explicit initialization, so that you don't accidentally get surprised later, as in the optimization example that prompted this discussion.
For those who worry about braking because of initialization, I dare say that there are usually plenty of other places and techniques where efficiency can be improved to a much greater extent.
Is this a test for MT4 filling the array with zeros? Then you have to keep in mind that if ArrayResize uses a third parameter with a reserve, then subsequent reallocations within the reserve will not initialise anything. There will be rubbish.
There will be no rubbish.
I recommend doing explicit initialisation so that you are not accidentally surprised later, as in the optimisation example that prompted this discussion.
Forum on trading, automated trading systems and strategy testing
Bugs, bugs, questions
fxsaber, 2017.09.12 11:18
Even if I wrote perfectly (without making mistakes - which I don't), it's normal to take someone else's library (sometimes without source code - in the Marketplace) and use it, hoping it's written competently. And there is no insurance that after that you will run into different results in the tester. And finding the real cause will be VERY difficult. And fixing it is sometimes impossible.
The goal is that from run to run the result is reproducible - identical, even with an error.
There will be no rubbish.
Should we correct documentation then?
Initialization of an array with expressionArrayInitialize(array, init_val) doesn't mean initialization of elements of the reserve, allocated for this array, with the same value. WhenArrayResize() function subsequently increases the size of array within the current reserve, the elements are added to the end of the array whose values are not defined and, most often, are not equal toinit_val.
Do we need to correct the documentation then?
Initializing an array with the expressionArrayInitialize(array, init_val) doesn't mean that the elements of the reserve, allocated for this array, are initialized with the same value. WhenArrayResize() function subsequently increases the size of array within the current reserve, the elements are added to the end of the array whose values are not defined and, most often, are not equal toinit_val.
You don't, because there is simply no such thing in the MT4 documentation.
It's horrifying to think that some math library (Include\Math -7Mb source code) hasn't initialised in one/two places! And how to dig out this error, which gives different single runs in MT5 tester, and the same one in MT4?
I must be behind the times. It seems to me that the indicator buffer always has a length equal to the number of bars. And the refusal of its initialization in MT5 leads to displaying rubbish on the screen. It turns out that the explicit initialization is obligatory. And it is not clear why it is simply transferred from the core (as it was in MT4) to the MQL programmer. I haven't seen any real arguments that somehow it's possible to speed up without initialization and still get the rubbish display.
I'm not saying anything about a custom dynamic array - there's really a rule: the one who allocated it, is responsible for correct cleaning. ArrayInitialize is useful in many cases. It's not a question of speed, but the correctness of the program. Prioritize: fast and/or correct. Usually, some checks for correctness and data preparation require additional time (albeit minimal), but you can't do without it - miracles happen.
Forum on trading, automated trading systems and strategy testing
Bugs, bugs, questions
Alexey Viktorov, 2017.09.12 10:50
Let's take the indicator buffer array for example: When initializing the indicator, the buffer has zero length. What is there to initialize with zeros? When another index is added it is forced to be zeroed and then filled with some value??? What is this zeroing or filling with EMPTY_VALUE for? And if there is a need to assign PLOT_EMPTY_VALUE and not 0 or EMPTY_VALUE or to force one, but we need another... No matter how you slice it, you end up wasting your time...
And a custom array... The array is declared for some data different from zero and EMPTY_VALUE. So why should it be forcibly initialized with something?
So it turns out that it affects the performance in most cases.
And it makes no sense to do this in OnCalculate. Why would we need to initialize the array with something and then fill it with some values from the formula? When you add a bar, respectively an array cell, what is the point of filling it with something and then immediately with a value from the formula or an empty value?
And it already in OnCalculate it makes no sense. Why would we need to initialize the array with something and then immediately fill it with some values from the formula? When you add a bar, and respectively an array cell, what is the point of filling it with something and then immediately with a value from the formula or an empty value?
Only new array elements are initialised. And the point is still the same - identical results from run to run, even if there is an error in the code (often not your own). I gave an example with the math library above.
The rubbish is evil.
Don't, because there simply isn't one in the MT4 documentation.
Where did I get it from then? Go here.
Where did I get that from then? Go here.
So it's not about ArrayResize, it's about ArrayInitialize. ArrayResize guarantees zeros in MT4.
For the sake of interest, I looked in all my sources for MT5 how often I use ArrayInitialize. Just a few times. Seems to be less than a percentage of all dynamic arrays. And where I used it, I had to use nulls on purpose, so I used a shorter notation instead of for.