Hello,
The following code always fails on OrderSelect() and the return error code is 0
<CODE DELETED>
I need to select the order again after OrderDelete() because there's some code between OrderDelete() and OrderSelect() (where the "..." is ) which may change the selected order.
I tried adding MODE_HISTORY to OrderSelect(), although it's not necessary, but the result is the same. Any help would be appreciated.
Please read some other posts before posting . . .
Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
Why do you think you should be able to select a pending order that you just deleted ? if the OrderSelect() returns true it has worked, please read the documentation . . . so then there is no error so the error code is 0.
Play videoPlease edit your post.
For large amounts of code, attach it.
- Perhaps it takes time before the history is updated.
- Select the order before deleting it. If you change the selected order (where the "..." is ) do the orderSelect there.
return(OrderType() <= OP_SELL); // Avoid cr/bal forum.mql4.com/32363#325360 // https://forum.mql4.com/30708 // Never select canceled orders.So I've assumed (based on other forum code) that canceled orders appear in the history list.
Because canceled orders appear in the history list?
Apologies for posting mistakes, this is my first post and thanks for your prompt replies.
To RaptorUK, there's nothing in the documentation that says you can't select a pending order that was just deleted. BTW, OrderSelect() return !true but GetLastError() returns 0.
To WHRoeder, one thing i failed to mention in my original post is that by adding a small delay after OrderDelete(), the following OrderSelect() succeeds. I have no explanation to this except it's a bug in MQL4, as I would assume that OrderDelete() should not return unless after the order is actually deleted and all orders lists are updated. If I'm mistaken, please let me know.
I just noticed the // Never selected canceled orders. comment in WHRoeder reply. Can you elaborate if this is a part of MQL4 documentation or rules? If this is true, how can I get information about past deleted orders?
I just noticed the // Never selected canceled orders. comment in WHRoeder reply. Can you elaborate if this is a part of MQL4 documentation or rules? If this is true, how can I get information about past deleted orders?
You may use OrderSelect() to select any order regardless of whether it is a market order, pending order, closed order, or canceled order. See the OrderSelect section in Closing and Deleting Orders. Can't speak directly for WHRoeder, but I believe he has chosen in his code to select only open/closed market orders. See Trade Constants/Enumerations. That doesn't mean that you can only select open/closed market orders...you may select any order using OrderSelect(). Again, see the OrderSelect section in Closing and Deleting Orders.
WHRoeder:
Select the order before deleting it. If you change the selected order (where the "..." is ) do the orderSelect there.
OrderType() <= OP_SELL <---- matches OP_BUY or OP_SELL only.
I just verified that orders list are not fully updated before OrderDelete() returns. I inserted some code between OrderDelete() and OrderSelect()
if (OrderDelete(TicketNum, CLR_NONE) == TRUE) { ClosedOrderCount = OrdersHistoryTotal(); WaitLoops = 0; while(ClosedOrderCount == OrdersHistoryTotal()) { WaitLoops++; } Print("Loops=", WaitLoops); if (OrderSelect(TicketNum, SELECT_BY_TICKET) != TRUE) { Alert("Server failed to select order ticket=", TicketNum, " Err=", GetLastError()); } }
The Loops= value ranged from 0 to about 400000. I did only 5 tests.
Any ideas?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
The following code always fails on OrderSelect() and the return error code is 0
I need to select the order again after OrderDelete() because there's some code between OrderDelete() and OrderSelect() (where the first "..." is ) which may change the selected order.
I tried adding MODE_HISTORY to OrderSelect(), although it's not necessary, but the result is the same. Any help would be appreciated.