MT5 Python error -5: Invalid version (RES_E_INVALID_VERSION)
The Python package and the MetaTrader 5 terminal don't agree on a version. Update the terminal and the package.
What it means
You see this code in mt5.last_error() in Python, after a package call returns None or False.
The package talks to the terminal using a protocol that changes over time. -5 means the two sides are at versions that don't match.
It usually follows an update of one side but not the other.
Common causes
- An old terminal build with a new package from pip.
- An old package with a newly updated terminal.
- A terminal that hasn't finished updating itself.
How to fix it
- Let the terminal update to its latest build and restart it.
- Run
pip install --upgrade MetaTrader5. - Print
mt5.version()andmt5.__version__to see what you have.
Example in Python:
import MetaTrader5 as mt5
print("package:", mt5.__version__)
if mt5.initialize():
print("terminal:", mt5.version()) # (version, build, release date)
else:
print(mt5.last_error()) Is it safe to retry?
After updating.
Could the order have executed?
Not a trade. It happens at connect time, before any trade.
How Tickwire handles it
With Tickwire your code calls a REST API from any operating system. You don't install this package or keep a terminal running yourself. See the MT5 Python API page.
Related codes
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.