MT5 error 10039: A close order already exists (TRADE_RETCODE_CLOSE_ORDER_EXIST)
A close order for this position is already working. Your new close may duplicate it, so check the position before sending another.
What it means
You see this code in the retcode of a trade result, from OrderSend() in MQL5 or order_send() in Python.
On hedging accounts a close is an order of its own. 10039 says there is already a close order for the position, or that your close plus the existing ones would be more than the position's volume.
It often means an earlier close is still in progress.
Common causes
- A second close sent while the first is still being processed.
- Close by requests pending against the same position.
- A retry after an unclear answer to the first close.
How to fix it
- Look at pending orders for the position and at its current volume.
- Wait for the first close to finish rather than sending more.
Example in Python:
import MetaTrader5 as mt5
pos_id = close_request["position"]
working = [o for o in mt5.orders_get(symbol=close_request["symbol"]) or ()
if o.position_id == pos_id]
print("close orders already working:", [o.ticket for o in working])
print("still open:", bool(mt5.positions_get(ticket=pos_id))) Is it safe to retry?
Only after checking. An earlier close may still complete.
Could the order have executed?
Maybe. Your new close didn't go through, but the existing close order may already be closing the position.
How Tickwire handles it
Tickwire treats 10039 as an unclear result. It doesn't resend; it reads the account and reports applied, rejected or unknown. See idempotency.
Related codes
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.