57 lines
2.0 KiB
Markdown
57 lines
2.0 KiB
Markdown
# OrderSend
|
|
|
|
[Trade Functions](https://docs.mql4.com/trading)
|
|
|
|
The main function used to open an order or place a pending order.
|
|
|
|
```mq4
|
|
int OrderSend(
|
|
string symbol, // symbol
|
|
int cmd, // operation
|
|
double volume, // volume
|
|
double price, // price
|
|
int slippage, // slippage
|
|
double stoploss, // stop loss
|
|
double takeprofit, // take profit
|
|
string comment=NULL, // comment
|
|
int magic=0, // magic number
|
|
datetime expiration=0, // pending order expiration
|
|
color arrow_color=clrNONE // color
|
|
);dg
|
|
```
|
|
|
|
## Order Properties (CMD)
|
|
|
|
| ID | Value | Description |
|
|
| -- | ----- | ----------- |
|
|
| OP_BUY | 0 | Buy operation |
|
|
| OP_SELL | 1 | Sell operation |
|
|
| OP_BUYLIMIT | 2 | Buy limit pending order |
|
|
| OP_SELLLIMIT | 3 | Sell limit pending order |
|
|
| OP_BUYSTOP | 4 | Buy stop pending order |
|
|
| OP_SELLSTOP | 5 | Sell stop pending order |
|
|
|
|
## Market Order
|
|
|
|
There are three types of orders that can be placed in MetaTrader: market, stop and limit orders. Being the most common, a market order opens a position immediately at the nearest Bid or Ask price.
|
|
|
|
### Buy
|
|
|
|
OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Bid-15*Point,Bid+15*Point);
|
|
|
|
double bid =MarketInfo("GBPUSD",MODE_BID); // Request for the value of Bid
|
|
double ask =MarketInfo("GBPUSD",MODE_ASK); // Request for the value of Ask
|
|
double point =MarketInfo("GBPUSD",MODE_POINT);//Request for Point
|
|
// Opening BUY
|
|
OrderSend("GBPUSD",OP_BUY,0.1,ask,2,bid-15*Point,bid+15*Point);
|
|
Alert (GetLastError()); // Error message
|
|
return; // Exit start()
|
|
|
|
|
|
OrderSend (Symbol(), OP_BUY, Lots, Ask, Slippage, Bid-StopLoss *Point, Bid+TakeProfit*Point, “EAName”, MagicNumber, 0, Blue)
|
|
Here is an example of a sell market order:
|
|
|
|
### Sell
|
|
|
|
OrderSend (Symbol(), OP_SELL, Lots, Bid, Slippage, Ask+StopLoss *Point, Ask-TakeProfit*Point, “EAName”, MagicNumber, 0, Blue)
|