If OrdersTotal() were 4 lets say (4-1)=3 so the (i) would be 3
The documents suggest: OrdersHistoryTotal() and i++
- If there are 4 orders, they are numbered 0, 1, 2, 3.
- Get in the habit of counting down. Loops and Closing or Deleting Orders - MQL4 forum
- If there are 4 orders, they are numbered 0, 1, 2, 3.
- Get in the habit of counting down. Loops and Closing or Deleting Orders - MQL4 forum
So your saying 0 would actually be an order ? Similar to [0] index types are treated ?
Perhaps this is where I am confused.
Please confirm this
Thanks ALOT for the responses
for(int i = OrdersTotal()-1; i >= 0 ; i--)Ever thought why i >= 0; ? Get that figured out and welcome to the world of loops.
So your saying 0 would actually be an order ? Similar to [0] index types are treated ?
Perhaps this is where I am confused.
Please confirm this
Ever thought why i >= 0; ? Get that figured out and welcome to the world of loops.
Wouldn't this be missing the open order 0 all the time ?
Also, why does OrdersTotal() return 0 when there are NO market or pending orders open ?
Print("OrdersTotal ",OrdersTotal()); /// prints 1's and 0's for my EA that places only 1 trade at a time ?
Try not to confuse how many orders there are with what the order indices are. OrdersTotal() does not return an index.
If OrdersTotal() return 0, there are no orders. Any attempt to retrieve an index is out of range.
If OrdersTotal() returns 1, there is 1 order and its index is 0.
If OrdersTotal() returns 2, there are 2 orders and their indices are 0 and 1.
And so forth
Try not to confuse how many orders there are with what the order indices are. OrdersTotal() does not return an index.
If OrdersTotal() return 0, there are no orders. Any attempt to retrieve an index is out of range.
If OrdersTotal() returns 1, there is 1 order and its index is 0.
If OrdersTotal() returns 2, there are 2 orders and their indices are 0 and 1.
And so forth
OK now I'm really confused
I mean why not just i=OrdersTotal() ?
So for this loop below
for(int i = OrdersTotal()-1; i >= 0 ; i--)
For example:
If OrdersTotal() were (2) for example:
And the loop says OrderTotal(2)-1. Isn't this order number 1 with an index of [0]
If that is not how works, then I can't seem to comprehend how it selects the last order in OrdersTotal() when using -1; or why that is preferred over this ---- for( i = OrderstTotal(); i>=0; i--) ?
Thanks for the response
OK now I'm really confused
I mean why not just i=OrdersTotal() ?
i for index
There is never an order index == OrdersTotal().
The reason is because we count from 1 upwards with the number of orders... 1-2-3-4-5-6-7
But we count from 0 upwards with indices of the orders. 0-1-2-3-4-5-6 Does it help if you think of the indices as being labelled A-B-C-D-E-F-G rather than 0-1-2-3-4-5-6?
You are comparing apples (the number of orders) with pears (the index of order numbers).
OK now I'm really confused
I mean why not just i=OrdersTotal() ?
int nOpenOrders = OrdersTotal(); // count = 4 int iHighestPosition = nOpenORders - 1; // highest = 3 int iLowestPosition = 0; // lowest = 0 // positions = 0, 1, 2, 3 : total of 4 for(int iPos = iHighestPosition; iPos >= iLowestPosition; --iPos){ // ALL open 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
IMO it seems to miss the latest order everytime wouldn't it ?
If OrdersTotal() were 4 lets say
(4-1)=3 so the (i) would be 3 and the selected order would be -1 of the OrdersTotal or even OrdersHistoryTotal(). This confuses me.
The documents suggest: OrdersHistoryTotal() and i++
https://docs.mql4.com/trading/ordershistorytotal
This makes sense to me while -1 and i-- confuses me.
It seems even OrdersTotal() and i-- without the -1 makes more sense to me, but I am confused about the -1.
Please advise.