How to get Position opening time?

 

Hi guys,

I'm just wondering if there is a function to get the position opening time here in MQL5? I've read the various trade functions and the data structures but can't seem to locate this function.  I'm intending to close a position based on a fixed time after being opened if the takeprofit and stoploss hasn't been triggered yet.  Thanks in advance!

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 
polymath:

Hi guys,

I'm just wondering if there is a function to get the position opening time here in MQL5? I've read the various trade functions and the data structures but can't seem to locate this function.  I'm intending to close a position based on a fixed time after being opened if the takeprofit and stoploss hasn't been triggered yet.  Thanks in advance!

PositionGetInteger(POSITION_TIME). Returns a datetime type.

For more info on position properties, click a green link in your post. 

 
Wow, that was fast :D Thanks Enigma71fx!
 
Enigma71fx:

PositionGetInteger(POSITION_TIME). Returns a datetime type.

For more info on position properties, click a green link in your post. 

Hi polymath,

... and you have to select first with PositionSelect() https://www.mql5.com/en/docs/trading/positionselect

 

Documentation on MQL5: Trade Functions / PositionSelect
Documentation on MQL5: Trade Functions / PositionSelect
  • www.mql5.com
Trade Functions / PositionSelect - Documentation on MQL5
 
Thanks onewithzachy, that's what I did :D
 

Hello guys,

I want to get last opened order ticket and it's entry time in MQL 5 but I couldn't do this , please help me 

I did this before in mql4 with bottom block code

ulong lastOpenTicket()
  {
   int lastOpenTime = 0, needleTicket = 0;
   for(int i = (OrdersTotal()-1); i >= 0; i --)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         int curOpenTime = OrderOpenTime();

         if(curOpenTime > lastOpenTime)
           {
            lastOpenTime = curOpenTime;
            needleTicket = OrderTicket();
           }
        }
     }
   return needleTicket;
  }

I want to change my codes to MQL 5 , please Help me , thanks 

 
atlas98:

Hello guys,

I want to get last opened order ticket and it's entry time in MQL 5 but I couldn't do this , please help me 

I did this before in mql4 with bottom block code

I want to change my codes to MQL 5 , please Help me , thanks 

Search for the most recent position and display information about it.

How to start with MQL5
How to start with MQL5
  • 2021.03.12
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
 
double SonPozKarHesapla()
  {
   double _karToplam=0;
   datetime _zaman=0;
   for(int i=0; i<PositionsTotal(); i++)
     {
      ulong bilet=PositionGetTicket(i);
      long sihirliIslem=PositionGetInteger(POSITION_MAGIC);
      if(PositionSelectByTicket(bilet) && sihirliIslem==1923)
        {
         double _kar=PositionGetDouble(POSITION_PROFIT);
         datetime _zamanim=(datetime)PositionGetInteger(POSITION_TIME);
         if(_zamanim>_zaman)
           {
            _karToplam=_kar;
            _zaman=_zamanim;
           }
        }
     }
   return _karToplam;
  }
Reason: