MetaTrader 5 error 10038 · TRADE_RETCODE_INVALID_CLOSE_VOLUME
The close volume is larger than the current position volume.
Check an order against MetaTrader 5 rules before sending it (free)
What the venue says
- A close volume exceeds the current position volume
Source: trade server return codes (MqlTradeResult.retcode), read 2026-11-28. Market: all.
Usual causes
- Closing more lots than are open (after a partial close)
How to fix it
- Read POSITION_VOLUME and close at most that amount
Also known as: invalid close volume.
Stop this error before the order leaves your bot
The free order check tests size, price, tick, lot step and venue rules for one order and returns the venue error code it would hit. The free EA code check reads MQL5 and Python bot code for the rule checks that stop codes like this one. Both are free; the full EA list is US$19 with a 30-day refund.
Free order check Free EA code check
This page explains an error message. It is information for developers, not financial advice and not a recommendation to trade. Codes and texts come from the venue's official documentation on the date shown; venues change them, so check the source before relying on it. Register built 2026-11-28; the receipt id for this entry is rcp_f46dbbd415c049339e83.