Saturday 9 February 2013

MQL4 OrderSelect, OrdersHistoryTotal, OrdersTotal


OrderSelect
OrdersHistoryTotal
OrdersTotal
Examples

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.


OrdersHistoryTotal takes no parameters but returns the number of closed orders and trades in the account history.  As the number of orders returned depends on the MT4 terminal settings under the Account History tab, all trades should be selected by right clicking within the Account History tab and selecting All History as shown in the picture to the left.
int OrdersHistoryTotal()

OrdersTotal takes no parameters but returns the total number of open orders and open trades in the trade log.
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();
    }
}

No comments:

Post a Comment