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
double OrderClosePrice()datetime OrderCloseTime()string OrderComment()double OrderCommission()datetime OrderExpiration()double OrderLots()int OrderMagicNumber()double OrderOpenPrice()datetime OrderOpenTimeOrderTicket, OrderOpenTime, OrderType, OrderLots, OrderStopLoss, OrderTakeProfit, OrderCloseTime, OrderClosePrice, OrderCommission, OrderSwap, OrderProfit, OrderComment, OrderMagicNumber, OrderExpiration
void OrderPrint()double OrderProfit()double OrderStopLoss()double OrderSwap()string OrderSymbol()double OrderTakeProfit()int OrderTicket()OP_BUY buy positionOP_SELL sell positionOP_BUYLIMIT pending buy limit orderOP_BUYSTOP pending buy stop orderOP_SELLLIMIT pending sell limit orderOP_SELLSTOP pending sell stop orderint 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(); } }}For updates