MT4 error 139: Order is locked (ERR_ORDER_LOCKED)
The order is already being processed, so your request couldn't act on it. The first request may still complete; check first.
What it means
You see this code in GetLastError() in MQL4, after a trade function fails on the server side.
MT4 has a request for this order in progress. Until it finishes, the order is locked.
Whatever the first request was, it may complete after your new one is refused.
Common causes
- A close or modify sent while another one is still in flight.
- Two programs working on the same order.
How to fix it
- Wait, then select the order again and read its state.
- Have one part of your code own each order.
Example in MQL4:
if(!OrderClose(ticket, lots, Bid, 3) && GetLastError() == ERR_ORDER_LOCKED)
{
Sleep(2000);
if(OrderSelect(ticket, SELECT_BY_TICKET) && OrderCloseTime() > 0)
Print("Already closed by the earlier request");
} Is it safe to retry?
Only after reading the order again.
Could the order have executed?
Maybe. The earlier request on the order may have executed.
How Tickwire handles it
Tickwire treats it like MT5 10031, and the MT4 code stays in the message: it looks for the effect instead of resending. 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.