Files
xMQL4/Docs/Samples/OrderSend.md
T
2024-01-25 04:03:36 +03:30

2.0 KiB

OrderSend

Trade Functions

The main function used to open an order or place a pending order.

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-15Point,Bid+15Point);

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-15Point,bid+15Point); Alert (GetLastError()); // Error message return; // Exit start()

OrderSend (Symbol(), OP_BUY, Lots, Ask, Slippage, Bid-StopLoss Point, Bid+TakeProfitPoint, “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-TakeProfitPoint, “EAName”, MagicNumber, 0, Blue)