Blog / Fix MT5 errors · MQL4 · MQL5 · Trade errors

“OrderSend – Wrong Parameters Count” and Other Porting Errors

Learn why MQL4 OrderSend calls fail in MQL5 and how to convert trade requests using MqlTradeRequest, MqlTradeResult and CTrade.

· 6 min read

One of the most common problems developers encounter when converting an Expert Advisor from MetaTrader 4 to MetaTrader 5 is the compiler error:

wrong parameters count

This often happens when an EA uses the MQL4 version of OrderSend() inside an MQL5 program.

Although both platforms have a function called OrderSend(), their interfaces are different. MQL4 uses multiple positional arguments to describe a trade, while MQL5 uses request and result structures.

Copying an MQL4 OrderSend() call directly into MetaEditor 5 therefore produces a compilation error.

The solution is to rebuild the trade request using the MQL5 interface or use the standard CTrade class for simpler operations.

1. Why MQL4 OrderSend() Produces a Wrong Parameters Count Error

In MQL4, OrderSend() accepts several individual parameters describing the trade.

For example:

MQL4
int ticket = OrderSend(
   Symbol(),
   OP_BUY,
   0.10,
   Ask,
   slippage,
   stopLoss,
   takeProfit,
   "My EA",
   12345,
   0,
   clrBlue
);

These arguments specify the symbol, order type, volume, requested price, slippage, stop-loss, take-profit, comment, magic number, expiration and chart arrow colour.

MQL5 uses a different function signature:

MQL5
bool OrderSend(
   MqlTradeRequest& request,
   MqlTradeResult& result
);

The first argument describes the requested operation. The second receives information about the server's response.

This is why the MQL4-style call produces a parameter-count error in MQL5: the compiler expects two structures rather than the individual arguments used by the older interface.

2. Understanding MqlTradeRequest and MqlTradeResult

Before converting the function, understand the two structures used by MQL5.

MqlTradeRequest

This structure contains the details of the operation you want to perform.

Important fields include:

  • action: The type of trading operation.
  • symbol: The instrument being traded.
  • volume: Requested trading volume.
  • type: Order direction or type.
  • price: Requested price, where applicable.
  • sl: Stop-loss price.
  • tp: Take-profit price.
  • deviation: Permitted price deviation, where applicable.
  • magic: EA's magic number.
  • comment: Order comment.
  • type_filling: Requested filling policy.
  • type_time: Order time-in-force setting.

MqlTradeResult

This structure receives information about the server's response.

Important fields include:

  • retcode: Trade server return code.
  • deal: Resulting deal ticket, where applicable.
  • order: Order ticket, where applicable.
  • volume: Executed volume.
  • price: Execution price.
  • comment: Response description.

The distinction is straightforward: MqlTradeRequest describes what the EA wants to do, while MqlTradeResult helps establish how the trading server processed the request.

3. Convert an MQL4 Buy Order Using CTrade

For many EA developers, the simplest way to replace an MQL4 market-order call is to use the MQL5 CTrade class.

First, include the trading library and create a trade object:

MQL5
#include <Trade/Trade.mqh>

CTrade trade;

Then submit a Buy request:

MQL5
void OpenBuy()
{
   double lotSize = 0.10;
   double stopLoss = 0.0;
   double takeProfit = 0.0;

   trade.SetExpertMagicNumber(12345);

   if(!trade.SetTypeFillingBySymbol(_Symbol))
   {
      Print("Unable to determine supported filling mode.");
      return;
   }

   bool sent = trade.Buy(
      lotSize,
      _Symbol,
      0.0,
      stopLoss,
      takeProfit,
      "My EA"
   );

   uint retcode = trade.ResultRetcode();

   Print("Buy request result: ", retcode);
   Print("Description: ", trade.ResultRetcodeDescription());

   if(!sent ||
      (retcode != TRADE_RETCODE_DONE &&
       retcode != TRADE_RETCODE_DONE_PARTIAL))
   {
      Print("Buy was not confirmed as executed.");
      return;
   }

   Print("Executed volume: ", trade.ResultVolume());
   Print("Deal ticket: ", trade.ResultDeal());
}

In this example:

  • lotSize specifies the requested volume.
  • _Symbol identifies the current chart instrument.
  • 0.0 requests the current market price.
  • stopLoss and takeProfit specify protective price levels.
  • SetExpertMagicNumber() assigns the EA's magic number.
  • SetTypeFillingBySymbol() selects a filling policy based on the symbol's settings.
  • ResultRetcode() and ResultRetcodeDescription() provide information about the trade server's response.

The important point is that a successful CTrade::Buy() function return does not automatically mean the trade was executed. Always inspect the server return code and verify the resulting trade where appropriate.

4. Using the MQL5 OrderSend() Function Directly

If you need more control over the trade request, you can use the raw MQL5 OrderSend() function.

The following example demonstrates a basic market Buy request, including a check for a supported filling policy:

MQL5
bool GetFillingMode(string symbol, ENUM_ORDER_TYPE_FILLING &filling)
{
   long executionMode = 0;
   long fillingModes = 0;

   if(!SymbolInfoInteger(symbol, SYMBOL_TRADE_EXEMODE, executionMode) ||
      !SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE, fillingModes))
   {
      Print("Unable to retrieve symbol execution settings.");
      return false;
   }

   if((fillingModes & SYMBOL_FILLING_FOK) != 0)
   {
      filling = ORDER_FILLING_FOK;
      return true;
   }

   if((fillingModes & SYMBOL_FILLING_IOC) != 0)
   {
      filling = ORDER_FILLING_IOC;
      return true;
   }

   if(executionMode != SYMBOL_TRADE_EXECUTION_MARKET)
   {
      filling = ORDER_FILLING_RETURN;
      return true;
   }

   Print("No supported filling policy was identified.");
   return false;
}

void OpenBuy()
{
   MqlTradeRequest request = {};
   MqlTradeResult result = {};
   MqlTradeCheckResult check = {};
   MqlTick tick;

   if(!SymbolInfoTick(_Symbol, tick))
   {
      Print("Unable to retrieve current market prices.");
      return;
   }

   ENUM_ORDER_TYPE_FILLING filling;

   if(!GetFillingMode(_Symbol, filling))
      return;

   request.action = TRADE_ACTION_DEAL;
   request.symbol = _Symbol;
   request.volume = 0.10;
   request.type = ORDER_TYPE_BUY;
   request.price = tick.ask;
   request.sl = 0.0;
   request.tp = 0.0;
   request.magic = 12345;
   request.comment = "My EA";
   request.type_filling = filling;

   if(!OrderCheck(request, check))
   {
      Print("OrderCheck failed: ", check.retcode,
            " - ", check.comment);
      return;
   }

   bool sent = OrderSend(request, result);

   Print("OrderSend returned: ", sent);
   Print("Server retcode: ", result.retcode);
   Print("Server comment: ", result.comment);
   Print("Order ticket: ", result.order);
   Print("Deal ticket: ", result.deal);
}

This example demonstrates the request structure, filling-policy selection and preliminary request validation.

The volume is illustrative. A production EA must validate the requested volume against the symbol's specifications and include appropriate margin, stop-distance and execution checks.

Also note that the required price fields depend on the symbol's execution mode. The example supplies the latest Ask price, but a production implementation should follow the requirements for the broker's execution model.

Do not confuse a successful function return with a completed trade. OrderSend() returning true means the request passed the function's basic checks and was accepted for further processing. It does not guarantee execution.

Inspect result.retcode to determine the server's response. Common outcomes include:

Return code Meaning
TRADE_RETCODE_DONE (10009) Request completed
TRADE_RETCODE_DONE_PARTIAL (10010) Request partially completed
TRADE_RETCODE_PLACED (10008) Order placed

For operations where execution may be delayed or produce multiple trade events, use OnTradeTransaction() to track subsequent changes.

5. Other Common MQL4-to-MQL5 Porting Errors

The OrderSend() parameter-count error is only one of several compatibility problems developers encounter. Predefined variables such as Ask, Bid and Point are another; see MQL4 compile errors in MT5 and MQL4 vs MQL5: the differences that matter.

Common differences include:

MQL4 function or constant MQL5 approach
OP_BUY ORDER_TYPE_BUY
OP_SELL ORDER_TYPE_SELL
OrderSend() with positional arguments OrderSend(request, result) or CTrade
OrderClose() CTrade::PositionClose() or an appropriate trade request
OrderModify() CTrade::PositionModify() or an appropriate trade request
OrderDelete() CTrade::OrderDelete()
OrderMagicNumber() POSITION_MAGIC or ORDER_MAGIC, depending on the object (magic numbers in MT5)
OrderTicket() Use the appropriate order, deal or position ticket

These are conceptual replacements, not always direct one-to-one substitutions.

For example, MQL4's OrderClose() is commonly used to close an active market trade. In MQL5, closing a position requires working with the position model. The correct method depends on the position being managed and the account's trading mode.

Similarly, an MQL4 pending order and an MQL5 open position are not interchangeable concepts.

Do not replace function names mechanically. Review what the original operation was intended to accomplish.

6. Understand the Difference Between Orders, Deals and Positions

One of the most important parts of MQL5 conversion is understanding its distinction between orders, deals and positions.

  • Orders: Instructions submitted to the trading system. These can be market requests or pending instructions.
  • Deals: Actual trade executions. One order can result in multiple deals.
  • Positions: The resulting market exposure held in an account.

MQL4 developers often use the word "order" to refer to an active market trade. MQL5 treats these as distinct objects.

For example, submitting a market Buy request does not mean the EA should automatically assume a position has been opened. The request could be rejected, partially filled or accepted for further processing.

When converting an EA, review how it:

  • Identifies open positions.
  • Selects individual trades.
  • Tracks order and deal tickets.
  • Modifies stop-loss and take-profit levels.
  • Closes positions.
  • Handles partial executions.

Ignoring these differences can produce an EA that compiles successfully but manages trades incorrectly.

7. How to Fix OrderSend and Other Porting Errors Systematically

When an MQL4 EA produces multiple errors after being opened in MetaEditor 5, avoid changing individual lines without understanding the underlying incompatibility.

Work through the conversion in stages.

Step 1: Identify the original MQL4 function.

Locate the affected function and determine what it was designed to do.

Step 2: Check the MQL5 function signature.

Compare the original function with the correct MQL5 interface. For OrderSend(), remember that MQL5 requires MqlTradeRequest and MqlTradeResult.

Step 3: Rebuild the operation.

Use CTrade for straightforward trade operations or construct an MqlTradeRequest when you need more direct control.

Step 4: Review the order-management logic.

Check whether the original code assumes MQL4-style order handling. Convert its position selection, modification and closing logic appropriately.

Step 5: Compile and resolve the remaining errors.

Address each error systematically, paying attention to data types, function signatures and missing identifiers.

Step 6: Test actual trading behaviour.

After compilation, use the Strategy Tester and appropriate demo forward testing to confirm that the converted EA behaves as intended.

A clean compilation is only the beginning. The converted program must also preserve the original strategy's intended behaviour.

Conclusion

The MQL5 OrderSend() wrong parameters count error usually occurs when developers attempt to use the MQL4 function signature inside an MQL5 program.

The solution is not to remove an argument or rearrange the parameters. MQL5 uses a different request-and-result structure, and its trading architecture distinguishes between orders, deals and positions.

For straightforward operations, the CTrade class simplifies trade submission. For more customised operations, MqlTradeRequest and MqlTradeResult provide direct control over the request and its response.

If you are converting an older Expert Advisor, review the entire trading workflow rather than fixing individual compiler errors in isolation. PositionAlpha's MQL4 to MQL5 converter takes the whole MT4 file and returns it as an .mq5, with a report of what converted exactly, what had to change for MT5 and what couldn't be converted. Compile it in MetaEditor and test it in the Strategy Tester and on a demo account before you rely on it.

Build a bot from your idea

Describe your trading idea and the AI writes MT4 or MT5 code for you to review and test, with a plain-English explanation and setup steps. Your first bot is free.

More from the blog