MT4 error 4051: Invalid function parameter value (ERR_INVALID_FUNCTION_PARAMVALUE)

An MQL4 function got an argument it can't use, such as 0 lots, a negative number or a bad ticket. Nothing was sent.

4051ERR_INVALID_FUNCTION_PARAMVALUE
After a fixSafe to retry?
NoCould it have executed?

What it means

You see this code in GetLastError() in MQL4, raised inside the terminal.

4051 is a runtime error, not a server answer. The terminal checked the arguments of a function and refused one of them before doing anything.

With trade functions it often means a lot size of 0, a bad ticket in OrderClose(), or a value out of range.

Common causes

  • A lot size that rounded down to 0.
  • OrderClose() with a ticket of 0 or -1, often from a failed OrderSend().
  • A negative slippage or a wrong mode constant.
  • An uninitialized variable passed as an argument.

How to fix it

  • Check values before the call: lots above 0, ticket above 0.
  • Stop when OrderSend() returns -1, instead of passing -1 on.
  • Print the arguments when the error appears, to see which one is wrong.

Example in MQL4:

double lots = NormalizeDouble(riskLots, 2);
if(lots <= 0)
{
   Print("Lot size rounded to 0, order skipped");
   return;
}
int ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 0, "", 4711);
if(ticket < 0)
{
   Print("send failed, error ", GetLastError());
   return;                     // don't pass -1 to OrderClose or OrderModify
}

Is it safe to retry?

After you fix the argument.

Could the order have executed?

No. The terminal refused the call before sending.

How Tickwire handles it

Tickwire treats it like MT5 10013, and the MT4 code stays in the message. See trade results.

All MetaTrader error codes

One API for MT4 and MT5

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