MT5 error 10022: Invalid expiration (TRADE_RETCODE_INVALID_EXPIRATION)

The pending order's expiration is not allowed for this symbol, or the time is wrong. Nothing was placed; change type_time or the date.

10022TRADE_RETCODE_INVALID_EXPIRATION
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.

Pending orders can last until canceled, until the end of the day, or until a set time. Each symbol allows only some of these, and the time must be in the future in server time.

10022 says the expiration type or time you sent doesn't pass those checks.

Common causes

  • ORDER_TIME_SPECIFIED on a symbol that doesn't allow it.
  • An expiration time in the past, often because it was built in UTC or local time instead of server time.
  • ORDER_TIME_SPECIFIED without an expiration value.
  • A broker that only accepts good till canceled orders.

How to fix it

  • Read symbol_info(name).expiration_mode. It is a bit mask: 1 GTC, 2 day, 4 specified time, 8 specified day.
  • Build expiration times from the server's clock, not your own.
  • Fall back to ORDER_TIME_GTC and cancel the order yourself if the broker refuses expirations.

Example in Python:

import MetaTrader5 as mt5

s = mt5.symbol_info("EURUSD")
can_specify = bool(s.expiration_mode & 4)    # 4 = specified time allowed
tick = mt5.symbol_info_tick("EURUSD")         # tick.time is server time

req = {
    "action": mt5.TRADE_ACTION_PENDING, "symbol": "EURUSD", "volume": 0.1,
    "type": mt5.ORDER_TYPE_BUY_LIMIT, "price": round(tick.ask - 0.003, s.digits),
}
if can_specify:
    req.update(type_time=mt5.ORDER_TIME_SPECIFIED, expiration=tick.time + 4 * 3600)
else:
    req.update(type_time=mt5.ORDER_TIME_GTC)     # cancel it yourself later

Is it safe to retry?

After you choose an allowed expiration.

Could the order have executed?

No pending order was created.

How Tickwire handles it

Tickwire never assumes the broker's server time is UTC. It measures it per server. See time zones.

MT4 error 147 comes back as 10022.

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.