OrderSelect selects a single order and enables the Order Information functions to return information about the selected order. Because so many order information functions rely on OrderSelect, you should be familiar with this function and how it works. Note: in MT4 the term "order" refers to open orders, closed orders, open trades and closed trades.
bool OrderSelect(int index, int select, int pool=MODE_TRADES)
OrderSelect selects a specific order to allow other trading functions to access information about the order.
Return value: The return value is TRUE if the function succeeds at selecting the order with the specified index and FALSE if the function fails. Error information may be retrieved in the case of a failure with the GetLastError function.
Parameters:
int index An index number or a ticket number, depending on the select parameter.
int select A flag that determines what index represents. There are two possible values:
SELECT_BY_POS index uses a sequential index number in the order pool.
SELECT_BY_TICKET index uses the order ticket number (assigned via OrderSend)
int pool Optional flag that may be used when the select parameter is set to SELECT_BY_POS.
MODE_TRADES (default) Selected orders will be drawn from open or pending orders.
MODE_HISTORY Selected orders will be drawn from closed or cancelled orders.
int OrdersHistoryTotal()
int OrdersTotal()
Examples
Usage: loops through all open orders and trades and prints out order details to the log:
for (int i =0; i < OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
OrderPrint();
}
}
Usage: loops through all historical orders and trades and prints out order details to the log:
for (int i =0; i < OrdersHistoryTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
OrderPrint();
}
}
For updates