Broker API HubMenu

MQL5 PositionSelectByTicket()

functionPositionSelectByTicket()MQL5Positions

Selects an open position by its ticket, so that PositionGetDouble(), PositionGetInteger() and PositionGetString() read it.

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 unofficialmql5.comchecked

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

The page says the function copies the position's data, and later reads return that copy even if the position has since changed or closed. It recommends calling the function again just before the data is used.

Signature

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

bool PositionSelectByTicket(
  ulong ticket
)

Arguments

NameTypeDescription
ticketrequiredulongThe position's ticket.

Return value

Type
bool
What comes back
True when the position was selected, false when not. On failure 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 ShowPosition(const ulong ticket)
  {
   if(PositionSelectByTicket(ticket))
      PrintFormat("#%I64u %s %.2f lots",ticket,PositionGetString(POSITION_SYMBOL),PositionGetDouble(POSITION_VOLUME));
   else
      PrintFormat("PositionSelectByTicket error %d",GetLastError());
  }