Download MetaTrader 5

Do HistoryDealGetTicket(index) is sort by HistoryDeal open time?

To add comments, please log in or register
LEE Chun Wing
831
LEE Chun Wing  

Do index of HistoryDealGetTicket(index)  is sort by HistoryDeal open time?

 

or close time?

 

if i use HistoryDealGetTicket(0)  , then it will select the latest one or oldest deal?

what the rules with the index , it is  descenting with the deal open time ?

if I want to get last 5 deals' profit, how to obtain them?

THANKS 

Wackena
648
Wackena  
kelly:

Do index of HistoryDealGetTicket(index)  is sort by HistoryDeal open time?

 

or close time?

 

if i use HistoryDealGetTicket(0)  , then it will select the latest one or oldest deal?

what the rules with the index , it is  descenting with the deal open time ?

if I want to get last 5 deals' profit, how to obtain them?

THANKS 

 

 

HistoryDealsGetTicket(index) should not be used as a stand alone call. As used in this example https://www.mql5.com/en/docs/trading/historydealgetticket , the index is sorted by ascending deals.

Here is example to find elapsed open deal time of last deal in an open position.

//+------------------------------------------------------------------+
//|   return elapsed time for last deal in current open position     |
//+------------------------------------------------------------------+
datetime LastDealElapsedTime()
  {
   uint pos_total=0;
   uint total=0;
   long pos_id=0;
   ulong HTicket=0; 
   datetime ETime=LONG_MAX;  
   pos_total=PositionsTotal();
   if(pos_total>0)
     { // continue if current open position

      if(PositionSelect(Symbol())) // continue if open position is for chart symbol
        {
         pos_id=(ENUM_POSITION_PROPERTY_INTEGER)PositionGetInteger(POSITION_IDENTIFIER);
         HistorySelectByPosition(pos_id);
         total=HistoryDealsTotal();
         HTicket=HistoryDealGetTicket(total-1); // get ticket number for last deal in position
         
         if(HTicket>0)
            ETime=TimeCurrent()-HistoryDealGetInteger(HTicket,DEAL_TIME);

         return(ETime);
        }

     }
   return(0);
  }
Documentation on MQL5: Trade Functions / HistoryDealGetTicket
  • www.mql5.com
Trade Functions / HistoryDealGetTicket - Documentation on MQL5
LEE Chun Wing
831
LEE Chun Wing  

HI, wackena

 

DO U MEAN THAT

FOR  HistoryDealGetTicket (index)

 

THE BIGGER OF  IN DEX IS , THE SMALLER OF ORDER SETUP TIME IS ?

 SMALLER OF ORDER SETUP TIME  =  older ORDER

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
Wackena
648
Wackena  
kelly:

HI, wackena

 

DO U MEAN THAT

FOR  HistoryDealGetTicket (index)

 

THE BIGGER OF  IN DEX IS , THE SMALLER OF ORDER SETUP TIME IS ?

 SMALLER OF ORDER SETUP TIME  =  older ORDER

 

Yes. Example: HistoryDealsTotal() = 10 completed deals.  HistoryDealGetTicket (1) = oldest deal.  HistoryDealGetTicket (10)  = newest deal.
To add comments, please log in or register