MT5 error 10045: Closing allowed only by FIFO rule (TRADE_RETCODE_FIFO_CLOSE)
The account must close positions in the order they were opened (FIFO). Close the oldest position on that symbol first.
What it means
You see this code in the retcode of a trade result, from OrderSend() in MQL5 or order_send() in Python.
Some accounts follow a first in, first out rule. When there are several positions on a symbol, the oldest must be closed first. Closing a newer one is refused with 10045.
The rule is common on accounts regulated in the United States.
Common causes
- Closing a newer position while an older one on the same symbol is open.
- Strategies that manage each position on its own.
How to fix it
- Check
account_info().fifo_close. - When it is true, sort positions by open time and close the oldest first.
Example in Python:
import MetaTrader5 as mt5
if mt5.account_info().fifo_close:
positions = sorted(mt5.positions_get(symbol="EURUSD") or (), key=lambda p: p.time_msc)
oldest = positions[0] if positions else None
print("close this one first:", oldest.ticket if oldest else None) Is it safe to retry?
After you close in the right order.
Could the order have executed?
No. The close was refused.
How Tickwire handles it
MT4 error 150 comes back as 10045.
Related codes
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.