MT5 error 10040: Open positions limit reached (TRADE_RETCODE_LIMIT_POSITIONS)
The account has reached the broker's cap on open positions. Nothing was executed; close positions before opening more.
What it means
You see this code in the retcode of a trade result, from OrderSend() in MQL5 or order_send() in Python.
A broker can limit how many positions an account holds at once. At the limit, an order that could add a position is refused with 10040.
On netting accounts only the number of positions counts, so you can still trade symbols you already hold. On hedging accounts pending orders count too, because each one opens a new position when it triggers.
Common causes
- Many small positions from a grid or a basket strategy.
- Pending orders on a hedging account that count toward the limit.
- A low limit set for the account group.
How to fix it
- Count positions, and on hedging accounts pending orders too, before sending.
- Close or merge positions you no longer need.
- Ask the broker for the limit. It is a server setting.
Example in Python:
import MetaTrader5 as mt5
acc = mt5.account_info()
hedging = acc.margin_mode == 2 # 2 = retail hedging
count = mt5.positions_total() + (mt5.orders_total() if hedging else 0)
print("counts toward the limit:", count) Is it safe to retry?
After positions are closed.
Could the order have executed?
No. Nothing was opened.
Related codes
- MT5 error 10033: Pending orders limit reached (TRADE_RETCODE_LIMIT_ORDERS)
- MT5 error 10046: Hedging prohibited (TRADE_RETCODE_HEDGE_PROHIBITED)
- MT5 error 10034: Volume limit for the symbol reached (TRADE_RETCODE_LIMIT_VOLUME)
Related MT5 Python functions
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.