Broker API HubMenu

MQL4 OrderSelect()

functionOrderSelect()MQL4Finding orders

Selects one order, by its place in a list or by its ticket, so that the functions which read an order's properties read that one.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialdocs.mql4.comchecked

This is an MQL4 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 4 terminal, in a program written in MQL4.

The page says the pool argument is ignored when selecting by ticket, and that an order's close time tells which list it came from: 0 means it is open or pending. Open trades, pending orders and history are all reached through this one function, which is why it is listed under three tasks.

Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

bool OrderSelect(
  int index,
  int select,
  int pool=MODE_TRADES
)

Arguments

NameTypeDescription
indexrequiredintThe order's index or its ticket, depending on the second argument. The page's own parameter list calls this argument ticket.
selectrequiredintHow the first argument is read: SELECT_BY_POS for an index in the order pool, SELECT_BY_TICKET for a ticket.
poolintWhich pool to index into when selecting by position: MODE_TRADES for open and pending orders, MODE_HISTORY for closed and cancelled ones. Default: MODE_TRADES.

Return value

Type
bool
What comes back
True when the order was selected, false otherwise. The page points to GetLastError() for the reason.

Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.

void OnStart()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         PrintFormat("#%d %s %.2f lots",OrderTicket(),OrderSymbol(),OrderLots());
     }
  }