MT5 error 10013: Invalid request (TRADE_RETCODE_INVALID)

The trade request is malformed or incomplete, so the server refused it. Nothing was executed; fix the fields and send again.

10013TRADE_RETCODE_INVALID
After a fixSafe to retry?
NoCould 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.

10013 is the catch-all for a request that doesn't make sense as written. A required field is missing, a value has the wrong meaning for the action, or two fields contradict each other.

More specific problems have their own codes, such as 10014 for volume and 10016 for stops. 10013 covers the rest.

Common causes

  • The wrong action for what you want, such as TRADE_ACTION_DEAL with a pending order type.
  • A close on a hedging account without the position ticket.
  • A modify or delete with an order ticket that is missing or wrong.
  • A stop limit order without stoplimit.

How to fix it

  • Compare the request with the field list for its action in the MQL5 reference.
  • Run order_check() and read its comment, which is often more specific.
  • Print the whole request dict before sending while you debug.

Example in Python:

import MetaTrader5 as mt5

# Closing one position on a hedging account: name the position.
pos = mt5.positions_get(symbol="EURUSD")[0]
tick = mt5.symbol_info_tick("EURUSD")
close = {
    "action": mt5.TRADE_ACTION_DEAL, "symbol": pos.symbol, "volume": pos.volume,
    "type": mt5.ORDER_TYPE_SELL if pos.type == mt5.POSITION_TYPE_BUY else mt5.ORDER_TYPE_BUY,
    "position": pos.ticket,
    "price": tick.bid if pos.type == mt5.POSITION_TYPE_BUY else tick.ask,
    "deviation": 20,
}
print(mt5.order_check(close).comment)
r = mt5.order_send(close)

Is it safe to retry?

Only after you change the request. The same fields get the same answer.

Could the order have executed?

No. The server didn't accept the request.

How Tickwire handles it

Tickwire validates the request before sending, and returns a 400 with an error message for fields it can check itself. Broker refusals come back as 10013 with outcome rejected.

MT4 error 3 and the MT4 runtime errors 4051, 4105, 4106 and 4108 come back as 10013, with the MT4 code in the message.

Related MT5 Python functions

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.