User Name:  
Forgot Password?
Sign up with

Join now (it's free)

User Name:
First Name:
Last Name:

Retrieving Order Information with the OrderSelect() Function

Once we have successfully placed an order, we will need to gather information about the order, particularly if we want to modify or close it. All this is done through the OrderSelect() function. To use the OrderSelect(), we can ether use the ticket number of the order, or we can loop through the pool of open orders and select each of them in order. 

Here is the syntax for the OrderSelect() function:

bool OrderSelect(int Index, int Select, int Pool=MODE_TRADES)

For a handy reference, a description of the above parameters can be found in the table below:

Params Description
Index Either the ticket number of the order we want to select, or the position in the order pool. The Select parameter indicates which one. 
Select A constant indicating whether the Index parameter is a ticket number or an oder pool position
  • SELECT_BY_TICKET-  The value of the Index parameter is an order ticket number
  • SELECT_BY_POS-  The value of the Index parameter is an order pool position
Pool An optional constant indicating the order pool: pending/open orders, or closed orders. 
  • MODE_POOL-  By default, refers to the pool of currently opened orders
  • MODE_HISTORY- Examines the closed order pool (the order history)

Here is an example of an OrderSelect() function using the an order ticket number. It is set up for the modification of the of stop loss and take profit after a buy order has taken place:

if (OrdersTotalMagicOpen()==0 && OpenBuy==true)
ticket = OrderSend(Symbol(),OP_BUY,NormalizeDouble(Lots,LotDigits), Ask,vSlippage,0,0,EAName, MagicNumber, 0, Green);
return (ticket);
OrderModify(OrderTicket(),OrderOpenPrice(),Bid - Stop_Loss * vPoint, Ask+TakeProfit * vPoint,0,Green);

In the above example, we used the OrderSelect() to select by ticket number, and then conjoined it with the OrderModify() function, so we could modify the StopLoss and TakeProfit. This example is particularly useful for ECN brokers. In an ECN broker you cannot place your stoploss and takeprofit values in their corresponding parameters within the OrderSend() function. Instead, these parameters must remain as 0. Only after the trade has been placed, can the order stoploss and takeprofit be modified via the OrderSelect() and OrderModify() functions, as in the illustration above. 

While the above OrderSelect() conjoins with the OrderModify() function, there is actually a range of order information functions that one can deploy to retrieve information about an order. There is a complete listing of these functions in the MLQ Reference. Here is a list of the commonly used order information functions: 

Functions Description
OrderSymbol() The symbol of the instrument that the order was placed on. 
OrderType() The type of order: buy or sell; market, stop or limit.
OrderOpenPrice() The opening price of the selected order.
OrderLots() The lot size of the selected order.
OrderStopLoss() The stop loss price of the selected order. 
OrderTakeProfit() The take profit of the selected order. 
OrderTicket() The ticket number of the selected order. 
OrderMagicNumber() The magic number of the selected order. 

An e-mail with your verification code has been sent to your e-mail address. Please access your in-box and use the verification button or verification code to complete your registration.
You already have an account linked with this E-mail (it maybe standard or social login). Please, sign in with it.
Please, provide us your e-mail so we can verify your account.