![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
yes, sorry about that. I misunderstood what you needed.
I'm not sure what's wrong in your code snippet; maybe the expectation that the "fired" pending order appears last in the order history?
You can adapt my code snippet for pending orders as follows:
The idea is still to pair up trades by virtue of iBarShift(..) i.e. which bar the order is opened at, and then delete all pending orders that are singletons on their bars.
Thanks Richplank,
But your code is deleting the other pending order when one of them get triggered, what I need is delete the other pending order when the other order closed because of it's SL or TP. Or there's any other way to use your code?
Thanks for the code Richplank, I do it this way
But I'm still curious why my own code doesn't work, if anybody could fix it, we can control it using magic number.
Thanks
Your method is good, but requires a trace-back from the recently closed buy/sell order to the pending order that seeded it, and then a trace-back from that to the order it was paired with. The first trace-back could perhaps be done by matching the open time of the buy/sell order with the close time of the pending order, while the second could be done using magic number. Alternatively you might be able to use the comment field for both trace-backs, if (as I think) the comment is inherited from a pending order to the seeded order, although MT4 will add to and change the tail part of the comment.
Or, if you are sure about the account activity, you might be able to rely on that the pending order is the one closed before the most recently closed buy/sell order, and thus look at and use the magic of last_trade-2 instead. That would probably work no less incidentally than the current solution.
Btw, My code is working fine now, i've change it a little bit, although I don't quiet understand why a minor change could make it works.
This is the correct code
Be careful with Select by position, as it is affected by the sorting order of your trades in the terminal window.
***********
I may be confused about this, sorry.. Will retest
***********
Be careful with Select by position, as it is affected by the sorting order of your trades in the terminal window.
Or if you don't mind give me an example please?
Thank you