Position selection in MQL 4 - The #1 Blog on trading, personal investing! Best Tips for Beginners

Header Ads

Position selection in MQL 4

You need to select open, closed or pending order to revise or cancel them according to your program flow. This can be achieved by OrderSelect(...) function.
bool OrderSelect(
   int index,               // index or order ticket
   int select,              // selection method
   int pool = MODE_TRADES   // selection mode
   );

Parameters
Ticket: [in]  Order index or order ticket depending on the second parameter.
Select: [in]  Selecting flags. It can be any of the following values:
SELECT_BY_POS - index in the order pool,
SELECT_BY_TICKET - index is order ticket.
Pool:=MODE_TRADES [in]  Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:
MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
MODE_HISTORY - order selected from history pool (closed and canceled order).
Returned value
It returns true if the function succeeds, otherwise falses. To get the error information, one has to call the GetLastError() function.
After selection completed once, user can reach any detail about that order. User can reach details with following functions;
• OrderSymbol() – Gets the parity of the selected order
• OrderType() – Gets the type of order such as buy, sell, buyStop, sellStop, buyLimit, sellLimit• OrderOpenPrice() – Gets the open price of order• OrderLots() – Gets the volume of order in lots.• OrderStopLoss() – Gets the stop loss level of the order.• OrderTakeProfit() – Gets the take profit level of the order.• OrderTicket() – Gets the ticket number of the order.• OrderMagicNumber() – Gets the magic number of the order which is used to distinguish your order.• OrderComment() – Gets the text comment of the order which is used to distinguish your order.• OrderClosePrice() – Gets the close price of the closed orders.• OrderOpenTime() – Gets the open time of the selected order.• OrderCloseTime() – Gets the close time of the selected order.
• OrderProfit() – Gets the profit of the selected order.