Forced array clearing in MT5? - page 4

 
I didn't know that in 4 the initialisation by zeros is done during resizing. This is not a convenience, but some kind of nonsense, leading to lower speed of programs. I.e. if I need to initialize array with value -1, then double initialization happens.
And then wonder why MT4 is slower.
 
Vasiliy Sokolov:

... MQL5, unlike MQL4, does not try to understand what a user wants and this is correct.

I suggest to put it on a poster. :) (just kidding)

Vasily, I understand that there are some nuances that justify such an approach of MT5 to the programmer's convenience. And I don't mind it. Let it be so.

 
Реter Konow:

1. logic tells us that the procedure of clearing arrays is performed by the compiler once at compile time.

Yes, you have a problem with logic :)

 
Nikolai Semko:
I didn't know that in 4ka the initialization by zeros occurs during resizing. This is not convenience, but some kind of nonsense, leading to lower speed of programs. I.e. if I need to initialize array with value -1, double initialization happens.
And then they wonder why MT4 is slower.

In principle, we could add some flag when declaring an array, which would tell the compiler to clear the array. It would be either convenient or fast - your choice.

 
Реter Konow:

In principle, we could add some kind of flag when declaring an array that would tell the compiler to clear the array. It would be either convenient or fast - your choice.

What difference does it make? You do initialization after resizing, that's all the flag.
Especially when declaring a dynamic array, the size is not known.
 
Nikolai Semko:
What's the difference. You do initialization after resizing, that's the whole flag.
Especially when declaring a dynamic array, the size is not known.

Yes, after each global array declaration and after each array resizing. And what if you have 20-30 global arrays, some of which change size under certain circumstances? Do you need to write initialization in loops everywhere? (arrays can be two-dimensional). Isn't it a potential source of errors?

 
Реter Konow:

Yes, after each global array declaration and after each array resizing. But what if you have 20 to 30 global arrays, some of which change size under certain circumstances? Do you need to write initialization in loops everywhere? (arrays can be two-dimensional). Isn't this a potential breeding ground for errors?

This surgical operation is done quite simply. Replace word"ArrayResize" with something else - it will be name of your function for resizing. Check in it, if resize is up, then go through the new elements in the loop and assign zero to them.

Also, in the inite, initialize all arrays that have size (if any).

There can also be arrays of a given size in functions - those too. Search for them using square brackets.

 
Dmitry Fedoseev:

This surgical operation is done quite simply. Replace the word "ArrayResize" with something else - this will be the name of your resize function. In it check, if the resize is upwards, then go through the new elements in the loop and assign them zero.

Also, in the inite, initialize all arrays that have size (if any).

There can also be arrays of a given size in functions - those too. Look for them by square brackets.

By the way, yes.
Pyotr, Dmitry is saying a sensible thing.
A properly written define will save you from rewriting the whole code.
 
Nikolai Semko:
By the way, yes.
Peter, Dimitri is saying a sensible thing.
A properly written define will save you from rewriting the whole code.

I'll give it a try. It's an interesting hack.

 

I will support the topicstarter, although there are many questions to his creation ))))

MQL5 developers, in the pursuit of speed of calculations (or some other beautiful numbers?) have removed all the "little extras" that made MQL4 more friendly,

If there is a rule of thumb in MQL5, the indicators that are based on MQL4 will become a "primer" in MQL5, and this "primer" needs to be read in the trading terminal:

1. when calling OnInit(), the indicator buffers are not initialized automatically

2. I looked through about a hundred indicators in the kodobase, alas, under the guise of programming in MQL5 they write indicators in the style of MQL4 - they expand the numbering of arrays and timeseries

3. iHighest / iLowest do not work logically - they look for bars with the highest / lowest values in the direction of increasing timeseries numbering... I.e., if we use the standard scheme of indicators in MQL4 - calculation from the previous data to the present, this problem is not solved with iHighest and iLowest, as the leftmost bar is 0, and when iLowest is called, we're searching for values in the future....

4. the same problem with ArrayMaximum() - it's hard to use in indicators... it's hard not to increase timeseries numbering, we take and constantly subtract from the starting el-ta some number of bars and get ArrayMaximum(high[i], i -Period,Period)

5. alas, even MQL5 experts use questionable constructions.... Let's say a certain base of crutches saved in the transition from MT4 is still being carried around.


What's the point? - MQL doesn't pretend to be pure С++, why they removed simpler implementations for users... I've been reviewing Python for about a month, why so many works in it... It's only now that I understand that Python allows people to ignore the little things and has a more user friendly interface ;) - to an experienced programmer it all seems wrong, but people use it and Python is quite popular