There is no check for the result of function OrderClose. If the order closing fails, we can't stay in the same function, since we have to find out why the closing was unsuccessful. To do this, we have to leave the function with the result false, and then decide what to do next.
We can't use one and the same closing price for all orders. First, orders may be of different types and, second, the price is likely to have changed over the time of executing previous orders (at closing). We can use an MT4 feature to avoid guessing what price to use: the OrderClosePrice() value of a market order prior to its closing is the Bid or Ask price depending on the order type.
There is no check for the result of function OrderClose. If the order closing fails, we can't stay in the same function, since we have to find out why the closing was unsuccessful. To do this, we have to leave the function with the result false, and then decide what to do next.
We can't use one and the same closing price for all orders. First, the orders can be of different types and, second, the price is likely to have changed during the execution of previous orders (at closing). To avoid guessing which price to use, we can use an MT4 feature: the OrderClosePrice() value of a market order prior to its closing is the Bid or Ask price depending on the order type.
Thank you, the main problem was probably just using the same price
From OrderSelect help " When orders are sequentially selected using SELECT_BY_POS parameter, the information is given in the order in which it came from the trade server. No sorting of the order list obtained is guaranteed".
If we think that this phrase was inserted in the help for nothing, we are OK. If we think that it was there for a reason, we should not change this list during the loop's run through the list of orders. How the orders will be ordered after the deletion of one of them on the server and the arrival of a new, current list with a smaller OrdersTotal, is unknown. It is more reliable, without deleting, to run through the same unchanged copy of the list and collect (in an array) all of the ticket numbers of the trades to be deleted. Then forget about that list and delete the trades, selecting them by ticket.
One would like to believe, of course, that the orderliness in the modifiable list is preserved, if only for this case of removing several orders from the end of an unordered list, but the developers are against it... Now it works, and if new build comes out - "we warned".
From OrderSelect help " When orders are sequentially selected using SELECT_BY_POS parameter, the information is given in the order in which it came from the trade server. No sorting of the order list obtained is guaranteed".
If we think that this phrase was inserted in the help for nothing, we are OK. If we think that it was there for a reason, we should not change this list during the loop's run through the list of orders. How the orders will be ordered after the deletion of one of them on the server and the arrival of a new, current list with a smaller OrdersTotal, is unknown. It is more reliable, without deleting, to run through the same unchanged copy of the list and collect (in an array) all of the ticket numbers of the trades to be deleted. Then forget about that list and delete the trades, selecting them by ticket.
One would like to believe, of course, that the orderliness in the modifiable list is preserved, if only for this case of removing several orders from the end of an unordered list, but the developers are against it... Now it works, and if new build comes out - "we warned".
Such "America" has been open for about three hundred years :)
This kind of "America" has been open for like three hundred years :)
I don't think the people asking questions here on behalf of newcomers have already discovered it themselves. That's why I'm writing it. Not for the moderators, but for the questioners. Look at the name of the thread.
P.S. I looked up where this interest came from. Turns out it's from the https://www.mql5.com/ru/forum/215783/page8 branch "Organising the Order Cycle". As it turns out, in October 2017, those three hundred years aren't over yet, there's still novelty.
I don't think the people asking questions here on behalf of newcomers have already discovered it themselves. That's why I'm writing it. Not for the moderators, but for the questioners. Look at the name of the thread.
P.S. I looked where this interest comes from. Turns out it's from the https://www.mql5.com/ru/forum/215783/page8 branch "Organising the order cycle". As it turns out, in October 2017 those three hundred years are not over yet, there is still novelty.
Wrong again :) Three hundred years started back at mql4.com - there was a time when it was actively discussed there. And there were even those moments that are described by you in "Now it works, and a new build will come out - "we warned". Only without warnings, and so several times - it depends, it doesn't depend on sorting...
And, yes, there is a special thread for such answers:
From OrderSelect help " When orders are sequentially selected using SELECT_BY_POS parameter, the information is given in the order in which it came from the trade server. No sorting of the order list obtained is guaranteed".
If we think that this phrase was inserted in the help for nothing, we are OK. If we think that it was there for a reason, we should not change this list during the loop's run through the list of orders. How the orders will be ordered after the deletion of one of them on the server and the arrival of a new, current list with a smaller OrdersTotal, is unknown. It is more reliable, without deleting, to run through the same unchanged copy of the list and collect (in an array) all of the ticket numbers of the trades to be deleted. Then forget about that list and delete the trades, selecting them by ticket.
I would like, of course, to believe that the ordering in the modifiable list is preserved at least for this case of deleting several orders from the end of an unordered list, but the developers are against it... Now it works, and if a new build comes out, "we warned you".
As a good idea (considering that there can be several Expert Advisors + trader working on the account in parallel), you can't perform trades in a loop at all. The necessary order is received, the operation is executed, the entire OnTick() is executed again (not necessarily with arrival of a new tick). And so on, until all necessary operations are executed.
Thus, forming an array to delete orders is equivalent to deleting orders in the loop.
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.
Could you please advise whether the function of closing all orders opened by the EA by the symbol is implemented correctly?
The architecture itself is correct. The errors are in the lack of checks and the use of some functions:
The architecture itself is correct. The errors are in the lack of checks and the use of some functions:
Thank you, the main problem was probably just using the same price
From OrderSelect help " When orders are sequentially selected using SELECT_BY_POS parameter, the information is given in the order in which it came from the trade server. No sorting of the order list obtained is guaranteed".
If we think that this phrase was inserted in the help for nothing, we are OK. If we think that it was there for a reason, we should not change this list during the loop's run through the list of orders. How the orders will be ordered after the deletion of one of them on the server and the arrival of a new, current list with a smaller OrdersTotal, is unknown. It is more reliable, without deleting, to run through the same unchanged copy of the list and collect (in an array) all of the ticket numbers of the trades to be deleted. Then forget about that list and delete the trades, selecting them by ticket.
One would like to believe, of course, that the orderliness in the modifiable list is preserved, if only for this case of removing several orders from the end of an unordered list, but the developers are against it... Now it works, and if new build comes out - "we warned".
From OrderSelect help " When orders are sequentially selected using SELECT_BY_POS parameter, the information is given in the order in which it came from the trade server. No sorting of the order list obtained is guaranteed".
If we think that this phrase was inserted in the help for nothing, we are OK. If we think that it was there for a reason, we should not change this list during the loop's run through the list of orders. How the orders will be ordered after the deletion of one of them on the server and the arrival of a new, current list with a smaller OrdersTotal, is unknown. It is more reliable, without deleting, to run through the same unchanged copy of the list and collect (in an array) all of the ticket numbers of the trades to be deleted. Then forget about that list and delete the trades, selecting them by ticket.
One would like to believe, of course, that the orderliness in the modifiable list is preserved, if only for this case of removing several orders from the end of an unordered list, but the developers are against it... Now it works, and if new build comes out - "we warned".
Such "America" has been open for about three hundred years :)
This kind of "America" has been open for like three hundred years :)
I don't think the people asking questions here on behalf of newcomers have already discovered it themselves. That's why I'm writing it. Not for the moderators, but for the questioners. Look at the name of the thread.
P.S. I looked up where this interest came from. Turns out it's from the https://www.mql5.com/ru/forum/215783/page8 branch "Organising the Order Cycle". As it turns out, in October 2017, those three hundred years aren't over yet, there's still novelty.
I don't think the people asking questions here on behalf of newcomers have already discovered it themselves. That's why I'm writing it. Not for the moderators, but for the questioners. Look at the name of the thread.
P.S. I looked where this interest comes from. Turns out it's from the https://www.mql5.com/ru/forum/215783/page8 branch "Organising the order cycle". As it turns out, in October 2017 those three hundred years are not over yet, there is still novelty.
Wrong again :) Three hundred years started back at mql4.com - there was a time when it was actively discussed there. And there were even those moments that are described by you in "Now it works, and a new build will come out - "we warned". Only without warnings, and so several times - it depends, it doesn't depend on sorting...
And, yes, there is a special thread for such answers:
From OrderSelect help " When orders are sequentially selected using SELECT_BY_POS parameter, the information is given in the order in which it came from the trade server. No sorting of the order list obtained is guaranteed".
If we think that this phrase was inserted in the help for nothing, we are OK. If we think that it was there for a reason, we should not change this list during the loop's run through the list of orders. How the orders will be ordered after the deletion of one of them on the server and the arrival of a new, current list with a smaller OrdersTotal, is unknown. It is more reliable, without deleting, to run through the same unchanged copy of the list and collect (in an array) all of the ticket numbers of the trades to be deleted. Then forget about that list and delete the trades, selecting them by ticket.
I would like, of course, to believe that the ordering in the modifiable list is preserved at least for this case of deleting several orders from the end of an unordered list, but the developers are against it... Now it works, and if a new build comes out, "we warned you".
As a good idea (considering that there can be several Expert Advisors + trader working on the account in parallel), you can't perform trades in a loop at all. The necessary order is received, the operation is executed, the entire OnTick() is executed again (not necessarily with arrival of a new tick). And so on, until all necessary operations are executed.
Thus, forming an array to delete orders is equivalent to deleting orders in the loop.
There is a "Stop" button, how do I change its text to "Start" once pressed?
See my expert example
Look at my Expert Advisor example
Thank you, just what I needed.
Might be helpful to know, there is an error in missing positions--- ToFile EURUSD,H1: zero divide in 'ToFile.mq4' (62,39)
The text does not change in the tester, there is no such option?