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:
For a handy reference, a description of the above parameters can be found in the table below:
|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:
|Pool||An optional constant indicating the order pool: pending/open orders, or closed orders.
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:
ticket = OrderSend(Symbol(),OP_BUY,NormalizeDouble(Lots,LotDigits),
Ask,vSlippage,0,0,EAName, MagicNumber, 0, Green);
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:
|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.|