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
-1RES_E_FAILA generic failure. The docs call it “generic fail”.What to do Check terminal is running and logged in, then retry.Single code page for RES_E_FAIL no page of its own on this build-2RES_E_INVALID_PARAMSThe function was called with invalid arguments. The docs call it “invalid arguments/parameters”.What to do Check argument types and values against the function docs.Single code page for RES_E_INVALID_PARAMS no page of its own on this build-3RES_E_NO_MEMORYThe terminal ran out of memory. The docs call it “no memory condition”.What to do Request smaller ranges of data.Single code page for RES_E_NO_MEMORY no page of its own on this build-4RES_E_NOT_FOUNDNo history was found for the request. The docs call it “no history”.What to do Check the symbol is in Market Watch and the date range has data.Single code page for RES_E_NOT_FOUND no page of its own on this build-5RES_E_INVALID_VERSIONVersion mismatch. The docs call it “invalid version”.What to do Update the MetaTrader5 package and terminal.Single code page for RES_E_INVALID_VERSION no page of its own on this build-6RES_E_AUTH_FAILEDLogin to the trade account failed. The docs call it “authorization failed”.What to do Check login, password and server name.Single code page for RES_E_AUTH_FAILED no page of its own on this build-7RES_E_UNSUPPORTEDThe method is not supported. The docs call it “unsupported method”.What to do Use a supported function or update the package.Single code page for RES_E_UNSUPPORTED no page of its own on this build-10000RES_E_INTERNAL_FAILGeneral failure talking to the terminal. The docs call it “internal IPC general error”.What to do Restart the terminal and call initialize() again.Single code page for RES_E_INTERNAL_FAIL no page of its own on this build-10001RES_E_INTERNAL_FAIL_SENDSending to the terminal failed. The docs call it “internal IPC send failed”.What to do Restart the terminal and reinitialise.Single code page for RES_E_INTERNAL_FAIL_SEND no page of its own on this build-10002RES_E_INTERNAL_FAIL_RECEIVEReceiving from the terminal failed. The docs call it “internal IPC recv failed”.What to do Restart the terminal and reinitialise.Single code page for RES_E_INTERNAL_FAIL_RECEIVE no page of its own on this build-10003RES_E_INTERNAL_FAIL_INITIPC initialisation failed; the docs also list RES_E_INTERNAL_FAIL_CONNECT (internal IPC no ipc) under -10003. The docs call it “internal IPC initialization fail”.What to do Check the terminal path passed to initialize() and that the terminal can start.Single code page for RES_E_INTERNAL_FAIL_INIT-10005RES_E_INTERNAL_FAIL_TIMEOUTThe terminal did not respond in time. The docs call it “internal timeout”.What to do Increase the timeout in initialize() or check the terminal is responsive.Single code page for RES_E_INTERNAL_FAIL_TIMEOUT no page of its own on this build
Source MQL5 docs: last_error (Python), last checked 25 Sep 2026
More MetaTrader 5 pages
- All MetaTrader 5 error codesInternal codes and trade server return codes
- mt5.initialize()Connect Python to the terminal, and the codes it returns when it fails
- Every MetaTrader5 Python functionSignatures, returns and the traps to know
- MetaTrader 5 API guideAuth, limits and the brokers that offer it