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
But the bottom of the stack is at zero rather than one isn't it? Hence having to subtract one from the number of orders returned when queried about this. Thus when the open order pool is empty, then it isn't going to return zero as this is a valid number for an order and there would still be one order in the pool. So do I test for 'NumberOfOrdersProcessed' < 0' to find out when i have gone through all of the stack including the last one at index position zero?
The processing is even more complicated than what you're thinking. Suppose you have open orders at position: 0) another chart order (different pair or EA,) 1) your buy, 2) your sell and you want to close the sell.
At this point You start the loop with OrdersTotal = 3 and iPos = 2. You select the sell and call OrderClose. While the order is closing, the other EA on the other chart closes its order at position 0.
When the OrderClose completes, OrdersTotal will now be 1 and your loop will decrement iPos to 1.
On next loop cycle OrderSelect will fail, there is no order at position 1. This is why you must count down AND test the OrderSelect status. What happens next is the iPos decrements again you select the order at 0 (Your buy) and ignore it since you're closing sells. and the loop exits.
You don't need to count anything. Once you get to iPos < 0, the loop exits and you are done.
When there are no open orders and no pending orders OrdersTotal() will return 0 . . . . this value is the number of orders, it has nothing to do with with any positions of any orders in the pool . . . there are no orders in the pool. When you have orders in the pool and you reference them by position valid positions are >= 0 the last position is OrdersTotal() - 1 if OrdersTotal() is 0 then 0 - 1 = -1 and this is not a valid position.
Got it,
Thanks Raptor
For FIFO (US brokers,) and if you (potentially) process multiple orders, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
Which is the most recent position's index.
This topic is about mql4. There is no "PositionTotal" function.