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.

-1RES_E_FAIL
Check firstSafe to retry?
MaybeCould it have executed?

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 returns None or False, 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 MT5 Python functions

All MetaTrader error codes

All MetaTrader5 Python functions

One API for MT4 and MT5

Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.