MT5 error 10023: Order state changed (TRADE_RETCODE_ORDER_CHANGED)

The order changed state while your request was on its way, for example it triggered. Read the order again before deciding what to do.

10023TRADE_RETCODE_ORDER_CHANGED
Check firstSafe to retry?
MaybeCould it have executed?

What it means

You see this code in the retcode of a trade result, from OrderSend() in MQL5 or order_send() in Python.

You asked to modify or delete an order, but by the time the server looked at it, the order was no longer in the state you expected. It may have triggered, filled in part, or been changed by something else.

The request was not applied to the old state. What matters now is the order's current state.

Common causes

  • A pending order that triggered just as you tried to move or delete it.
  • Two programs, or a person and a program, managing the same order.
  • A partial fill on an exchange order.

How to fix it

  • Read the order again with orders_get(ticket=...). If it is gone, look for the new position.
  • Make one part of your system responsible for each order.
  • Decide again from the fresh state, then send a new request if one is still needed.

Example in Python:

import MetaTrader5 as mt5

r = mt5.order_send({"action": mt5.TRADE_ACTION_REMOVE, "order": ticket})
if r is not None and r.retcode == mt5.TRADE_RETCODE_ORDER_CHANGED:
    still_pending = mt5.orders_get(ticket=ticket)
    if still_pending:
        print("order still pending, state", still_pending[0].state)
    else:
        print("order is gone; look for a position it opened")

Is it safe to retry?

Only after reading the order again. The right next step depends on what it turned into.

Could the order have executed?

Maybe. Your request didn't apply, but the order itself may have executed on its own, which is often why its state changed.

All MetaTrader error codes

One API for MT4 and MT5

Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.