Do not do this when there is any delay inside the loop (server calls, sleep etc.) Any delays and you could break out of the loop prematurely and miss other valid orders.
int i=OrdersTotal(); while(i>0)if(OrderSelect(--i,SELECT_BY_POS) )
In the presence of multiple orders (one EA
multiple charts, multiple EAs, manual
trading,) because while you are waiting for the current operation (closing,
deleting, modifying) to complete, any number of other operations on other orders
could have concurrently happened and changed the position indexing:
For FIFO (US brokers,)and you
(potentially) process multiple orders per symbol, you mustcount
up and on a successful operation, reprocess all positions (set index
to -1 before continuing.)
and if you (potentially) process multiple orders, must call
RefreshRates() after server calls if you want to use the Predefined Variables(Bid/Ask) or OrderClosePrice() instead, on the next order/server
call.
Do not do this when there is any delay inside the loop (server calls, sleep etc.) Any delays and you could break out of the loop prematurely and miss other valid orders.
Instead use:
Or
Those examples whroeder provided would face the same challenge if a new order arrived. If you want to totally avoid order-collision issues then don't use either of our examples and instead restart the loop if it detects a new order.
for(int total=OrdersTotal(),i=total-1;OrderSelect(i,SELECT_BY_POS);i--)
{
if(OrdersTotal() != total)
{
i=total=OrdersTotal();
continue;
}
//rest of code here
}
nicholishen: If you want to totally avoid order-collision issues then don't use either of our examples and instead restart the loop if it detects a new order.
No need. The current code didn't add a new order, so no need to look at new ones.
No need. The current code didn't add a new order, so no need to look at new ones.
No, but an EA on a separate thread could have, isn't that the point you were trying to make? Otherwise calling OrderSelect outside of the loop declaration and inside of the for-block is redundant because you're checking the iterator twice, once in the for loop and once again in the OrderSelect function. What would cause OrderSelect to return false other than array out of range?
Yes a separate thread could have, so what? The point I made was a separate thread could delete/remove/close earlier trades and that changes positions and must be accounted for. Other threads adding later positions are irrelevant.
Read the link previously provided. It shows examples how OrderSelect would return false.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Why is this code:
Not having my desired effect of only selecting the order if its OrderOpenTime() is larger than the previous one?
Because you are comparing the same ticket! You might as well be using this, because it does the same thing.
Awesome posts btw Ill sort this out hopefully so confused thx
Awesome posts btw Ill sort this out hopefully so confused thx
If you're looking for the absolute most simple implementation without any other functionality then you could try this.
If you're looking for the absolute most simple implementation without any other functionality then you could try this.
awesome this looks it!! lemme check it out, you the best help online ever
Thanks a zillion zillion zillion zillion, I finally got it down with your
Do not do this when there is any delay inside the loop (server calls, sleep etc.) Any delays and you could break out of the loop prematurely and miss other valid orders.
Loops and Closing or Deleting Orders - MQL4 and MetaTrader 4 - MQL4 programming forum
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Do not do this when there is any delay inside the loop (server calls, sleep etc.) Any delays and you could break out of the loop prematurely and miss other valid orders.
Those examples whroeder provided would face the same challenge if a new order arrived. If you want to totally avoid order-collision issues then don't use either of our examples and instead restart the loop if it detects a new order.
No need. The current code didn't add a new order, so no need to look at new ones.
No need. The current code didn't add a new order, so no need to look at new ones.
No, but an EA on a separate thread could have, isn't that the point you were trying to make? Otherwise calling OrderSelect outside of the loop declaration and inside of the for-block is redundant because you're checking the iterator twice, once in the for loop and once again in the OrderSelect function. What would cause OrderSelect to return false other than array out of range?