MT5 Python error -1: Generic failure (RES_E_FAIL)
A MetaTrader5 package call failed without a more specific reason. Check the arguments, the terminal and the account state.
What it means
You see this code in mt5.last_error() in Python, after a package call returns None or False.
-1 is the package's general failure code. The function didn't work, and the package didn't pick a more precise code.
Functions that fail return None or False. Calling mt5.last_error() straight after gives you the code and a short message.
Common causes
- A call that the terminal refused for a reason the package doesn't report in detail.
- A login or initialize call that failed partway.
- A request for data the terminal couldn't produce at that moment.
How to fix it
- Log
mt5.last_error()right after every call that returnsNoneorFalse, before any other call resets it. - Check the terminal's Journal tab, which often says more.
- Try the same call by hand in the terminal to rule out an account or symbol problem.
Example in Python:
import MetaTrader5 as mt5
rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M5, 0, 100)
if rates is None:
code, message = mt5.last_error() # read it at once
print(f"copy_rates_from_pos failed: {code} {message}") Is it safe to retry?
Maybe, once you know which call failed and why. A blind loop rarely helps.
Could the order have executed?
Maybe. If the failing call was order_send, check positions and orders before sending again.
Without the Python package
With Tickwire your code calls a REST API from any operating system, so this package error doesn't come up. See the MT5 Python API page.
Related codes
- MT5 Python error -2: Invalid parameters (RES_E_INVALID_PARAMS)
- MT5 Python error -10000: IPC internal error (RES_E_INTERNAL_FAIL)
- MT5 Python error -4: Not found (RES_E_NOT_FOUND)
Related MT5 Python functions
- mt5.initialize() in MetaTrader5 Python: connect Python to the terminal
- mt5.version() in MetaTrader5 Python: read the terminal's version and build
- mt5.last_error() in MetaTrader5 Python: find out why the last call failed
- mt5.account_info() in MetaTrader5 Python: read balance, equity and margin
- mt5.market_book_add() in MetaTrader5 Python: subscribe to market depth
- mt5.market_book_get() in MetaTrader5 Python: read the order book of a symbol
- mt5.market_book_release() in MetaTrader5 Python: stop a market depth subscription
- mt5.copy_rates_from() in MetaTrader5 Python: get bars back from a date
- mt5.copy_rates_from_pos() in MetaTrader5 Python: get the latest bars by position
- mt5.copy_rates_range() in MetaTrader5 Python: get bars between two dates
- mt5.copy_ticks_from() in MetaTrader5 Python: get ticks forward from a date
- mt5.copy_ticks_range() in MetaTrader5 Python: get ticks between two dates
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.