MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading Language Documentation

Subscribe to signal
Rem
10.32%, 110.30 USD
Screenshot
GOLD., H1
Real
Mercury FreeMercury Free Try product
Mercury Free
Author: nasdaq
The Binary Wave Indicator
The Binary Wave
Author: GODZILLA
Event handling in MQL5: Changing MA period on-the-fly Event handling in MQL5: Changing MA period on-the-fly
MQL5 ReferenceTrade FunctionsPositionGetInteger 

PositionGetInteger

The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. The position property should be of datetime, int type. There are 2 variants of the function.

1. Immediately returns the property value.

long  PositionGetInteger(
   ENUM_POSITION_PROPERTY_INTEGER  property_id      // Property identifier
   );

2. Returns true or false, depending on the success of the function execution. If successful, the value of the property is placed in a receiving variables passed by reference by the last parameter.

bool  PositionGetInteger(
   ENUM_POSITION_PROPERTY_INTEGER  property_id,     // Property identifier
   long&                           long_var         // Here we accept the property value
   );

Parameters

property_id

[in]  Identifier of a position property. The value can be one of the values of the ENUM_POSITION_PROPERTY_INTEGER enumeration.

long_var

[out]  Variable of the long type accepting the value of the requested property.

Return Value

Value of the long type. If the function fails, 0 is returned.

Note

For each symbol, at any given moment of time, only one position can be open, which is the result of one or more deals. Do not confuse positions with current pending orders, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal.

To ensure receipt of fresh data about a position, it is recommended to call PositionSelect() right before referring to them.

Example:

//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
//--- check if a position is present and display the time of its changing
   if(PositionSelect(_Symbol))
     {     
//--- receive position ID for further work
      ulong position_ID=PositionGetInteger(POSITION_IDENTIFIER);
      Print(_Symbol," postion #",position_ID);
//--- receive the time of position forming in milliseconds since 01.01.1970
      long create_time_msc=PositionGetInteger(POSITION_TIME_MSC);
      PrintFormat("Position #%d  POSITION_TIME_MSC = %i64 milliseconds => %s",position_ID,
                  create_time_msc,TimeToString(create_time_msc/1000));
//--- receive the time of the position's last change in seconds since 01.01.1970
      long update_time_sec=PositionGetInteger(POSITION_TIME_UPDATE);
      PrintFormat("Position #%d  POSITION_TIME_UPDATE = %i64 seconds => %s",
                  position_ID,update_time_sec,TimeToString(update_time_sec));
//--- receive the time of the position's last change in milliseconds since 01.01.1970
      long update_time_msc=PositionGetInteger(POSITION_TIME_UPDATE_MSC);
      PrintFormat("Position #%d  POSITION_TIME_UPDATE_MSC = %i64 milliseconds => %s",
                  position_ID,update_time_msc,TimeToString(update_time_msc/1000));
     }
//---
  }

See also

PositionGetSymbol(), PositionSelect(), Position Properties


Updated: 2013.03.15