Hi Eduardo,
to share code use the 'Code' button. I have corrected this for this time.
How to ensure that positions get cleaned after executing the opposite pending order??
- You don't close pending orders, you delete them.
- Placing a new order does not automatically delete another. You have to code that separately.
Don't worry.
I advise you to read the rules to avoid misunderstandings in the future. It will only take you 1 minute.
https://www.mql5.com/en/forum/443428
Read Fernando's answer carefully. He has hit the nail on the head (once again). <3
-
You can't close pending orders, they are not open. You delete them.
-
There is no need to create pending orders in code.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
-
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
- You don't close pending orders, you delete them.
- Placing a new order does not automatically delete another. You have to code that separately.
Hello Fernando,
Thank you for your help. My problem is not related to order removal but to position removal after order (buy+close) completion. If I complete a long order and then a short order of the same instrument and same lot size the resulting position should be 0 and this is not happening with PENDING orders.
Sharing some screenshots:
-
You can't close pending orders, you delete them.
-
There is no need to create pending orders in code.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
-
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

- 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,
I am trying to close a PENDING BUY STOP order by placing a PENDING SELL STOP order. I am using Python. Both orders get executed (deals done appear in the Journal tab) and the position gets removed from the Exposure tab but long and short trades still appear in the Trade tab and mt5.positions_get() also show them. The same thing does not happen if I use DEAL instead of PENDING orders.
How to ensure that positions get cleaned after executing the opposite pending order??
This is a snippet of the code:
Thanks