Want to select the last opened trade

 
If positions total is greater than 0 I want to select last trade opened. I used the logic below but doesn't seem to work. Can someone kindly assist
if(position_number>0)
   { 
    for(int b=position_number;b>=0;b--)
      {
       PositionSelectByTicket(PositionGetTicket(position_number-1));
       ulong ticket=PositionGetTicket(position_number-1);
       datetime OpeningTime=PositionGetInteger(POSITION_TIME);
       
       MqlDateTime MyOpeningTimeStruct;
       TimeToStruct(OpeningTime,MyOpeningTimeStruct);
       OpeningHour= MyOpeningTimeStruct.hour;
       OpeningDate=MyOpeningTimeStruct.day;
     }
    }
 
Jones John:
If positions total is greater than 0 I want to select last trade opened. I used the logic below but doesn't seem to work. Can someone kindly assist
Ok
 
Jones John:
If positions total is greater than 0 I want to select last trade opened. I used the logic below but doesn't seem to work. Can someone kindly assist

Search for the most recent position and display information about it

 

Vladimir, you're really great!

You have posted so much useful code over the time and still find the right post immediately - respect!

Reason: