Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 73

 
Alexey Viktorov:
Artem, you are wrong. The array declared on a global level is visible in all parts of the program and it isn't necessary to pass it somewhere from somewhere. You just fill it in one place in the program, and sort it in another, and read it in the third, it doesn't matter.

The same function can successfully sort and/or search data in different arrays. Right? And if so, it's better to pass the array by reference - for the future. And when calling the function, it won't hurt to see what array it will work with.

I'm just making these considerations. Where am I wrong?

 
Artyom Trishkin:

The same function can successfully sort and/or search data in different arrays. Right? And if so, it's better to pass the array by reference - for the future. And when calling the function, you should also be able to see the array it will work with.

I'm only right about that. Where is wrong?

Got it. Your advice is for lego-programmers. You don't do this perversion yourself.

That leaves one thing wrong, in that the array must be declared globally.

I'm glad we understand each other.

 
Alexey Viktorov:

Got it. Your advice is for lego programmers. You don't do such perversions yourself.

Then one thing remains, wrong about the array having to be declared globally.

Glad we understand each other.

My point in this context is this:

  1. We need to achieve as few loops per tick as possible.
  2. We want to have one constant array with data of market orders and positions and one array with data of deleted/closed orders and positions
  3. If we have the array locally in a function, calling it repeatedly requires filling it again. I suggest that it is filled only once at a new tick - so the array is global, otherwise we would lose it when exiting the function.
  4. In order to find something in it (in the array), we need a filled array and functions that will return the found data. Within functions, we can declare auxiliary arrays for necessary calculations.

For this reason, it would be better to have global arrays - for closed and open orders and positions. Once on a new tick, we pass the necessary amount of orders/positions once, filling two arrays with them. And then we get all the necessary data from them on the same tick. Note that not only the last closed/open order/position and all its data are calculated, but also all parent and child ticks of all positions are searched in case of partial closing. Accordingly, at any time I can see what ticket this or that position is from, if it has been partially closed more than once - all this already works in a class that runs in a timer. I have many other data I need with a small total number of cycles. The required depth of history for arrays is set for the tester.

And so on and so forth ...

 
Artyom Trishkin:

In this context, my point is this:

  1. We need to get as few cycles per tick as possible.
  2. We need to have one constant array with data of market orders and positions and one array with data of deleted/closed orders and positions
  3. If we have the array locally in a function, calling it repeatedly requires filling it again. I suggest that it is filled only once at a new tick - so the array is global, otherwise we would lose it when exiting the function.
  4. In order to find something in it (in the array), we need a filled array and functions that will return the found data. Within functions, we can declare auxiliary arrays for necessary calculations.

For this reason, it would be better to have global arrays - for closed and open orders and positions. Once on a new tick, we pass the necessary amount of orders/positions once, filling two arrays with them. And then we get all the necessary data from them on the same tick. Note that not only the last closed/open order/position and all its data are calculated, but also all parent and child ticks of all positions are searched in case of partial closing. Accordingly, at any time I can see which ticket originated from one or another position, if it has been closed partially more than once - all this already works in a class that runs in a timer. I have many other data I need with a small total number of cycles. For the tester, the desired depth of history is set for the arrays.

And so on and so forth ...

So we don't quite understand each other.

If the array is global, why pass it into a function by reference if it's already visible inside this function?

 
Alexey Viktorov:

Then we don't quite understand each other.

If the array is global, why pass it into a function by reference, if it is already visible within this function?

Function overloading - there is such a notion ;)

If you need to do the same actions with different arrays in one function, then...

However - we are discussing different special cases...

 
Artyom Trishkin:

Function overloading - there is such a concept ;)

If you need to do the same actions with different arrays in one function, then...

However - we are discussing different special cases...

Well, thank God, I understood your thoughts. But they are very similar to advice to lego-programmers.
 
Alexey Viktorov:
Well, thank goodness I get your thoughts. But they are very much like advice to lego programmers.

It would be very strange to have a huge number of 100% working functions in stock and write them all over again every time. This is not advice for building houses out of dice. It's advice to accumulate your own function libraries and classes. And what's wrong with one function handling multiple arrays depending on which one is passed to it by reference? And what's wrong with function templates?

If you have code for sorting an array, why write a separate function for every array type? You can simply overload and sort any type. How do you think ArraySort() works? You pass different types of arrays there, and on an output you receive the sorted one which was passed - or meta quotas also lego-coders or what?

 
Artyom Trishkin:

It would be very strange to have a huge number of 100%-working functions in stock and write them all over again every time. This is not advice for building houses out of cubes. It's advice to accumulate your own function libraries and classes. And what's wrong with one function working with multiple arrays depending on which one is passed to it by reference? And what's wrong with function templates?

If there is code for sorting an array, why should we write a separate function for each type of array? You can just do an overload and sort any type. How do you think ArraySort() works? You pass different types of arrays there, and the output is a sorted one, which you passed - or metaquotes also lego-coders, or what?

The main thing is not to come to this.

https://www.mql5.com/ru/forum/165468/page3#comment_3978059

Простой советник. Проверка размера бара. Покупка/продажа
Простой советник. Проверка размера бара. Покупка/продажа
  • www.mql5.com
Что должен делать советник: на каждом тике проверять размер бара как только размер бара станет равным или превысит заданный размер то: если свеча б...
 
Alexey Viktorov:

The main thing is not to come to this.

https://www.mql5.com/ru/forum/165468/page3#comment_3978059

It's no use there. It has a check to check and then a check to see if it's right. It's still crooked. That's not the case - that's where professors are needed.
 

there is a variable

int Level = 0;

While the program is running, it is constantly changing. Help me write a condition: if Level has NOT changed, do nothing, if Level has changed (it doesn't matter if it has changed more or less), do some action { operator }