Saturday 9 February 2013

MQL4 Specific Order Information


OrderClosePrice
OrderCloseTime
OrderComment
OrderCommission
OrderExpiration
OrderLots
OrderMagicNumber
OrderOpenPrice
OrderOpenTime
OrderPrint
OrderProfit
OrderStopLoss
OrderSwap
OrderSymbol
OrderTakeProfit
OrderTicket
OrderType
Examples

 All MQL4 trading functions on this page require a successful call to the OrderSelect function before any information may be returned. These MQL4 trading functions return specific order information for the selected order.
Parameters: NONE
OrderClosePrice Returns the historical close price for the selected order. To reference the opening price see OrderOpenPrice.
double OrderClosePrice()

OrderCloseTime Returns the historical close time for the selected order.  If the return value is nonzero then the selected order has been closed and is from account history (see OrderSelect, MODE_HISTORY). Open and pending orders return zero. To reference open orders see OrderOpenTime.
datetime OrderCloseTime()

OrderComment Returns the comment for the selected order. Order comments are set at order creation with the OrderSend function.
string OrderComment()

OrderCommission Returns the commission (if any) for the currently selected order. This function returns one of the three possible profit and loss amounts from placing a trade. The other functions are OrderSwap and OrderProfit. The sum of these three functions is the total profit or loss incurred for a given selected order. OrderCommission is generated by the Metatrader broker.
double OrderCommission()


OrderExpiration Returns the expiration date (if any) for the selected pending or open order. OrderExpiration may be set with the OrderSend function. The default value is zero, meaning no expiration on the entered order.
datetime OrderExpiration()

OrderLots Returns the number of lots or the trade size for the selected order. OrderLots is set at order creation with the OrderSend function.
double OrderLots()

OrderMagicNumber Returns the magic number for the selected order. Magic number is a number used to differentiate between orders for a given symbol and account. In theory, all orders could be placed with a separate magic number and closed with a custom close routine. In practice, different strategies or different entry signals within the same strategy may use different magic numbers to open orders for reporting or for trade closure purposes.
int OrderMagicNumber()

OrderOpenPrice Returns the open price of the currently selected order. To reference closing price, see the OrderClosePrice function, which returns the price of historical (closed) orders.
double OrderOpenPrice()

OrderOpenTime Returns the open time for the selected order.
datetime OrderOpenTime

OrderPrint Prints information about the currently selected order in the experts log. The following information is returned:
OrderTicket, OrderOpenTime, OrderType, OrderLots, OrderStopLoss, OrderTakeProfit, OrderCloseTime, OrderClosePrice, OrderCommission, OrderSwap, OrderProfit, OrderComment, OrderMagicNumber, OrderExpiration
void OrderPrint()

OrderProfit Returns the net profit amount for the currently selected order, excluding swap and commission. For open positions, the return value is the open equity for the selected order. For closed positions, the return value is the closed net profit for the selected order.
double OrderProfit()

OrderStopLoss Returns the stop loss price for the currently selected order. If no stop loss price is set, the return value is zero. This value is typically set with the OrderModify function for U.S. brokers, and may be set with the OrderSend function for non-U.S. based brokers.
double OrderStopLoss()

OrderSwap Returns the swap amount (if any) charged to or credited to the account for the selected order. Swap represents an interest charge for carrying a position over night, or an interest payment for holding an interest bearing currency pair over night. Swaps are set by the broker, and are typically fixed at the same time every day, for instance 5:00 PM EST.
double OrderSwap()

OrderSymbol Returns the symbol used in the currently selected order. The OrderSymbol function and the OrderMagicNumber function provide two ways to differentiate between orders placed on a single account and may be useful in order closure routines when only certain symbols or certain magic numbers are to be closed out.
string OrderSymbol()

OrderTakeProfit Returns the take profit price for the currently selected order. If no take profit price is set, the return value is zero. As with OrderStopLoss, the value is typically set with the OrderModify function for U.S. brokers, and may be set with the OrderSend function for non-U.S. based brokers.
double OrderTakeProfit()

OrderTicket Returns the ticket number for the currently selected order. The ticket number is created using the OrderSend function.
int OrderTicket()

OrderType Returns the type of order currently selected. There are several possible values:
OP_BUY         buy position
OP_SELL        sell position
OP_BUYLIMIT    pending buy limit order
OP_BUYSTOP     pending buy stop order
OP_SELLLIMIT   pending sell limit order
OP_SELLSTOP    pending sell stop order
int OrderType()


Examples: Virtually all the functions on this page may be exchanged seamlessly into the examples below.
Usage: loops through all open orders and trades and sums up the total position profit into the double "profit" variable. Total position profit is the sum of OrderProfit, OrderSwap and OrderCommission.
double profit = 0.0;
for (int i =0; i < OrdersTotal(); i++) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
        profit += OrderProfit() + OrderSwap() + OrderCommission();
    }
}

Usage: loops through all historical orders and trades and sums up OrderLots into the Lots variable for those orders meeting the OrderMagicNumber() == 0 and OrderSymbol() == "EURUSD" criteria. MN is an integer variable containing a magic number, and sym is a string variable containing a symbol name.

double Lots = 0.0;
int MN = 0;
string sym = "EURUSD";
for (int i =0; i < OrdersHistoryTotal(); i++) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
        if (OrderMagicNumber() == MN && OrderSymbol() == sym) {
            Lots += OrderLots();
        }
     
    }
}

No comments:

Post a Comment