- MQL4 Learning
- I don't understand why the -1 in for loop OrdersTotal() - 1
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
Here's a tip.
Don't use this code.
I wish someone would take the person who wrote it, cut off their hands and confiscate their keyboard.
Instead use a loop which counts downwards rather than upwards.
The reason is that each time you delete an order, the remaining orders are reindexed - so if you are counting upwards, your loop is going to miss some orders.
CB
OrdersTotal() returns the number of open and pending trades.
If it returns the value 3, you have three positions open or pending.
They are stored in index 0, 1, and 2 of the orders pool.
So...
for (int i = OrdersTotal()-1; i >= 0; i--)
... will loop "backwards" through the pool of orders, starting with index #2.
Same thing with OrdersHistoryTotal()., but it is the number of Closed orders.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use