Broker API HubMenu

MetaTrader 5 Python internal error codes

Every negative code mt5.last_error() returns in the MetaTrader5 Python package, what each one means and what to do about it. One page rather than a dozen near identical ones.

Independent and unofficialLast reviewed

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Carried over from an earlier version of this site. The links below are the sources it was written from, but its statements have not been re-read at source since the date shown, so check anything you rely on.

How to read these codes

The MetaTrader5 Python package does not raise an exception when a call fails. It returns None or False, and the reason sits in mt5.last_error(), which gives a code and a short description. The codes below are the negative ones: they describe the package talking to the MetaTrader 5 terminal on your own computer, rather than anything a broker did. Codes from 10000 upward are trade server return codes and are decoded on their own pages.

A first check after any failure is worth writing once and reusing: call mt5.last_error(), print both the code and the description, and stop rather than retrying blindly. Most of the codes below are cured by the same three habits: start the terminal and log in before the script runs, keep the MetaTrader5 package and the terminal at versions that match, and ask for smaller ranges of history.

The codes

Source MQL5 docs: last_error (Python), last checked 25 Sep 2026

More MetaTrader 5 pages

Sections