MT5 Python error -2: Invalid parameters (RES_E_INVALID_PARAMS)
The function got arguments of the wrong type or value, such as a volume passed as an int. Fix the call; nothing was sent.
What it means
You see this code in mt5.last_error() in Python, after a package call returns None or False.
The package checks argument types before it talks to the terminal. If an argument has the wrong type or an impossible value, the call fails with -2.
The package is strict about types. A volume must be a float, and tickets and counts must be ints.
Common causes
"volume": 1instead of"volume": 1.0in anorder_sendrequest.- A symbol passed as something other than a string.
- A count of 0 or a negative number in a
copy_*call. - A numpy type, such as
numpy.float64, where a plain Python number is expected.
How to fix it
- Cast values yourself:
float(volume),int(ticket),str(symbol). - Convert numpy values with
.item()orfloat()before building the request. - Print the request with the type of each value while you debug.
Example in Python:
import MetaTrader5 as mt5
request = {
"action": mt5.TRADE_ACTION_DEAL,
"symbol": str(symbol),
"volume": float(lots), # 1 would fail, 1.0 is fine
"type": mt5.ORDER_TYPE_BUY,
"price": float(mt5.symbol_info_tick(symbol).ask),
"deviation": int(20),
}
print({k: type(v).__name__ for k, v in request.items()})
r = mt5.order_send(request)
if r is None:
print(mt5.last_error()) Is it safe to retry?
Only after you fix the arguments.
Could the order have executed?
No. The call failed before anything reached the terminal's trade logic.
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 -1: Generic failure (RES_E_FAIL)
- MT5 error 10013: Invalid request (TRADE_RETCODE_INVALID)
- MT5 error 10014: Invalid volume (TRADE_RETCODE_INVALID_VOLUME)
Related MT5 Python functions
- mt5.login() in MetaTrader5 Python: log in to a trading account
- mt5.last_error() in MetaTrader5 Python: find out why the last call failed
- mt5.symbols_get() in MetaTrader5 Python: list symbols, with an optional filter
- 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
- mt5.orders_get() in MetaTrader5 Python: read pending orders
- mt5.positions_get() in MetaTrader5 Python: read open positions
- mt5.order_calc_margin() in MetaTrader5 Python: work out the margin for an order
- mt5.order_calc_profit() in MetaTrader5 Python: work out profit between two prices
- mt5.history_orders_total() in MetaTrader5 Python: count orders in history
- mt5.history_orders_get() in MetaTrader5 Python: read past orders
- mt5.history_deals_total() in MetaTrader5 Python: count deals in history
- mt5.history_deals_get() in MetaTrader5 Python: read past deals and fills
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.