# MQL4 OrderSend()

Independent and unofficial. Not affiliated with or endorsed by any broker or platform named here. Educational only: nothing here is advice, and nothing here recommends a broker or a trade.

This is the markdown version of https://openbrokerapi.com/platforms/metatrader-4/functions/mql4-ordersend, written from the same records as that page.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Opens a market order or places a pending order. The page calls it the main function for doing either.

- Function: `OrderSend()`
- Interface: MQL4
- Group: Sending orders
- Status: verified. Source: [docs.mql4.com](https://docs.mql4.com/trading/ordersend), checked 2026-10-12.

This is an MQL4 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 4 terminal, in a program written in MQL4. It is in no OpenAPI file on this site and the request builder does not list it.

Note: This function can place a real order on whichever account the terminal is logged in to, demo or live. The page says a market order can be opened only at the latest Bid, for a sell, or Ask, for a buy, that prices have to be normalised to the symbol's digits, that stop levels cannot sit closer to the market than the distance MarketInfo() returns for MODE_STOPLEVEL, and that some trade servers switch off expiry times or cap the number of open and pending orders.

## Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

```mql4
int OrderSend(
  string symbol,
  int cmd,
  double volume,
  double price,
  int slippage,
  double stoploss,
  double takeprofit,
  string comment=NULL,
  int magic=0,
  datetime expiration=0,
  color arrow_color=clrNONE
)
```

## Arguments

- `symbol` (type string, required): The symbol to trade.
- `cmd` (type int, required): The kind of operation, as one of the trade operation values, for example OP_BUY or OP_SELL.
- `volume` (type double, required): The number of lots.
- `price` (type double, required): The order price.
- `slippage` (type int, required): The most price slippage to accept on a buy or sell order.
- `stoploss` (type double, required): The stop loss level.
- `takeprofit` (type double, required): The take profit level.
- `comment` (type string, optional): A comment on the order. The page says the server can change its last part. Default: NULL.
- `magic` (type int, optional): The order's magic number, which a program can use as its own identifier. Default: 0.
- `expiration` (type datetime, optional): When the order expires. For pending orders only. Default: 0.
- `arrow_color` (type color, optional): The colour of the opening arrow on the chart. Left out or set to CLR_NONE, no arrow is drawn. Default: clrNONE.

## Return value

- Type: `int`
- What comes back: The ticket number the trade server gave the order, or -1 on failure. The page points to GetLastError() for the reason.

## Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.

```mql4
// Script. Run it only on a demo account: it sends a market order.
void OnStart()
  {
   int ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"sample",123456,0,clrNONE);
   if(ticket<0)
      Print("OrderSend failed with error #",GetLastError());
   else
      Print("OrderSend placed order #",ticket);
  }
```

## Return codes documented for this function

The page says the function returns -1 on failure and that GetLastError() gives the code. It names four of those codes in its notes, 129, 130, 147 and 148, and describes 148 as returned by the trade server. They are among MetaTrader 4's trade server return codes, each of which recorded here is below. Status: verified. Source: [docs.mql4.com](https://docs.mql4.com/trading/ordersend), checked 2026-10-12.

- [ERR_NO_ERROR (0)](https://openbrokerapi.com/errors/mt4/0-err-no-error): No error was returned.
- [ERR_NO_RESULT (1)](https://openbrokerapi.com/errors/mt4/1-err-no-result): No error was returned, but the result is unknown.
- [ERR_COMMON_ERROR (2)](https://openbrokerapi.com/errors/mt4/2-err-common-error): "Common error" is MetaQuotes' whole description of this code.
- [ERR_INVALID_TRADE_PARAMETERS (3)](https://openbrokerapi.com/errors/mt4/3-err-invalid-trade-parameters): "Invalid trade parameters" is MetaQuotes' whole description of this code.
- [ERR_SERVER_BUSY (4)](https://openbrokerapi.com/errors/mt4/4-err-server-busy): "Trade server is busy" is MetaQuotes' whole description of this code.
- [ERR_OLD_VERSION (5)](https://openbrokerapi.com/errors/mt4/5-err-old-version): "Old version of the client terminal" is MetaQuotes' whole description of this code.
- [ERR_NO_CONNECTION (6)](https://openbrokerapi.com/errors/mt4/6-err-no-connection): "No connection with trade server" is MetaQuotes' whole description of this code.
- [ERR_NOT_ENOUGH_RIGHTS (7)](https://openbrokerapi.com/errors/mt4/7-err-not-enough-rights): "Not enough rights" is MetaQuotes' whole description of this code.
- [ERR_TOO_FREQUENT_REQUESTS (8)](https://openbrokerapi.com/errors/mt4/8-err-too-frequent-requests): "Too frequent requests" is MetaQuotes' whole description of this code.
- [ERR_MALFUNCTIONAL_TRADE (9)](https://openbrokerapi.com/errors/mt4/9-err-malfunctional-trade): "Malfunctional trade operation" is MetaQuotes' whole description of this code.
- [ERR_ACCOUNT_DISABLED (64)](https://openbrokerapi.com/errors/mt4/64-err-account-disabled): "Account disabled" is MetaQuotes' whole description of this code.
- [ERR_INVALID_ACCOUNT (65)](https://openbrokerapi.com/errors/mt4/65-err-invalid-account): "Invalid account" is MetaQuotes' whole description of this code.
- [ERR_TRADE_TIMEOUT (128)](https://openbrokerapi.com/errors/mt4/128-err-trade-timeout): "Trade timeout" is MetaQuotes' whole description of this code.
- [ERR_INVALID_PRICE (129)](https://openbrokerapi.com/errors/mt4/129-err-invalid-price): "Invalid price" is MetaQuotes' whole description of this code.
- [ERR_INVALID_STOPS (130)](https://openbrokerapi.com/errors/mt4/130-err-invalid-stops): "Invalid stops" is MetaQuotes' whole description of this code.
- [ERR_INVALID_TRADE_VOLUME (131)](https://openbrokerapi.com/errors/mt4/131-err-invalid-trade-volume): "Invalid trade volume" is MetaQuotes' whole description of this code.
- [ERR_MARKET_CLOSED (132)](https://openbrokerapi.com/errors/mt4/132-err-market-closed): "Market is closed" is MetaQuotes' whole description of this code.
- [ERR_TRADE_DISABLED (133)](https://openbrokerapi.com/errors/mt4/133-err-trade-disabled): "Trade is disabled" is MetaQuotes' whole description of this code.
- [ERR_NOT_ENOUGH_MONEY (134)](https://openbrokerapi.com/errors/mt4/134-err-not-enough-money): "Not enough money" is MetaQuotes' whole description of this code.
- [ERR_PRICE_CHANGED (135)](https://openbrokerapi.com/errors/mt4/135-err-price-changed): "Price changed" is MetaQuotes' whole description of this code.
- [ERR_OFF_QUOTES (136)](https://openbrokerapi.com/errors/mt4/136-err-off-quotes): "Off quotes" is MetaQuotes' whole description of this code.
- [ERR_BROKER_BUSY (137)](https://openbrokerapi.com/errors/mt4/137-err-broker-busy): "Broker is busy" is MetaQuotes' whole description of this code.
- [ERR_REQUOTE (138)](https://openbrokerapi.com/errors/mt4/138-err-requote): "Requote" is MetaQuotes' whole description of this code.
- [ERR_ORDER_LOCKED (139)](https://openbrokerapi.com/errors/mt4/139-err-order-locked): "Order is locked" is MetaQuotes' whole description of this code.
- [140 ERR_LONG_POSITIONS_ONLY_ALLOWED](https://openbrokerapi.com/errors/mt4/140): Only buy orders are allowed.
- [ERR_TOO_MANY_REQUESTS (141)](https://openbrokerapi.com/errors/mt4/141-err-too-many-requests): "Too many requests" is MetaQuotes' whole description of this code.
- [ERR_TRADE_MODIFY_DENIED (145)](https://openbrokerapi.com/errors/mt4/145-err-trade-modify-denied): The modification was denied because the order is too close to the market.
- [ERR_TRADE_CONTEXT_BUSY (146)](https://openbrokerapi.com/errors/mt4/146-err-trade-context-busy): "Trade context is busy" is MetaQuotes' whole description of this code.
- [ERR_TRADE_EXPIRATION_DENIED (147)](https://openbrokerapi.com/errors/mt4/147-err-trade-expiration-denied): Expirations are denied by the broker.
- [ERR_TRADE_TOO_MANY_ORDERS (148)](https://openbrokerapi.com/errors/mt4/148-err-trade-too-many-orders): The number of open and pending orders has reached the limit set by the broker.
- [ERR_TRADE_HEDGE_PROHIBITED (149)](https://openbrokerapi.com/errors/mt4/149-err-trade-hedge-prohibited): The code tried to open an order opposite to an existing one while hedging is disabled.
- [ERR_TRADE_PROHIBITED_BY_FIFO (150)](https://openbrokerapi.com/errors/mt4/150-err-trade-prohibited-by-fifo): The code tried to close an order in a way that breaks the FIFO rule.

## Related MQL4 functions: Sending orders

- [OrderClose()](https://openbrokerapi.com/platforms/metatrader-4/functions/mql4-orderclose): Closes an open order, in full or for a given number of lots, at a price you pass.
- [OrderCloseBy()](https://openbrokerapi.com/platforms/metatrader-4/functions/mql4-ordercloseby): Closes an open order against another open order in the opposite direction.
- [OrderDelete()](https://openbrokerapi.com/platforms/metatrader-4/functions/mql4-orderdelete): Deletes a pending order that was placed earlier.
- [OrderModify()](https://openbrokerapi.com/platforms/metatrader-4/functions/mql4-ordermodify): Changes an open or pending order: its stop loss and take profit, and for a pending order its price and expiry too.

## More on MetaTrader 4

- [All MetaTrader 4 functions](https://openbrokerapi.com/platforms/metatrader-4/functions): 28 documented here, grouped by what they do.
- [Place an order: the call at each API](https://openbrokerapi.com/endpoints/place-order): The same job at every broker and platform API recorded here, HTTP or not.
- [All MetaTrader 4 error codes](https://openbrokerapi.com/errors/mt4)
- [MetaTrader 4 API page](https://openbrokerapi.com/platforms/metatrader-4): The full record: access, authentication, limits and the source for each.

## Licence and how to cite

The records behind this page are all rights reserved. This file is the page itself, at its own address, in another format. It is not part of the CC BY 4.0 downloads listed at https://openbrokerapi.com/data. Quote from it with a link to the page.

Cite as: MQL4 OrderSend(). Broker API Hub, https://openbrokerapi.com/platforms/metatrader-4/functions/mql4-ordersend, newest check 2026-10-12.

Where you rely on a single figure, cite the source and the checked date printed beside it as well. Where this page and a broker's own documentation differ, the documentation wins.
