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

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
is greater than or equal to, because the first element of the array also needs to be taken into account, and its index in the array is zero.
No, it's OK. If there are no positions, then i=OrdersTotal()-1 will be equal to -1. And the loop condition i>=0 will not be executed immediately. And the program will not enter the loop.
I don't understand what array everyone is referring to here. If OrdersTotal doesn't work like that.
Orders are essentially in an array in the program, we just don't see it. OrdersTotal is equal to ArraySize, and shows the total number of elements.
In an array, the index of the first element always starts with zero, and the size of the last element minus one.
Orders are essentially in an array in the program, we just don't see it. OrdersTotal is equal to ArraySize, and shows the total number of elements.
The index of the first element in the array is always zero, while the size of the last one, respectively, is minus one.
What difference does it make where the orders are located, if OrdersTotal isn't an array. It returns the number of orders, not the array index.
But that's not correct, it turns out "sum of orders" is 1, which means 1 order will always be excluded from the loop.
the orders are in a numbered list... The list counts down from 0...
For example
serial number 0, buy type, lot 0.1
serial number 1, sell type, lot 1
serial number 2, sell type, lot 0.5
sequence number 3, buy type, lot 0.16
If you now call OrdersTotal() it will = 4
But if we want to navigate through all rows of the list, we need to go through numbers 0 1 2 3, number 4 is not here... although there are 4 orders.
So a trick is done, when putting together a loop, minus 1 on the number of orders, that's it...
What difference does it make where the orders are located if OrdersTotal is not an array. It returns the number of orders, not the array index.
What difference does it make where the orders are located if OrdersTotal is not an array
But this is not correct, you get "sum of orders" - 1, i.e. 1 order will always be excluded from the loop.
If you don't like "-1", you can do this
Orders are essentially in an array in the program, we just don't see it. OrdersTotal is equal to ArraySize, and shows the total number of elements.
In an array, the index of the first element always starts with zero, and the size of the last one - minus one.
So total and array index are different things, why do you think it's the same? To create an array with 1 index, type 1, not 0, (int ar[1]), so ArraySize( ar ) also returns 1, not 0.
If you don't like "-1", you can
that's not correct... an order with the number 0 will be skipped...
The correct way is as follows