HistorySelect loop through deals with descending order

I want to count history deals from down to up. But my code not work perfectly. Please help me anyone.

HistorySelect(TimeCurrent(),0);
   if(HistoryDealsTotal()>0)
     {
      for(uint i = uint(HistoryDealsTotal()-1); i >= 0; i--)
        {
         if(Deal.SelectByIndex(i)==true)
           {
            ulong deal_order_number=Deal.Order();
            ulong deal_position_number=Deal.PositionId();

            Print(Symbol(),": Serial: ",string(i)," --  Deal ID: ",string(deal_order_number),", Position ID: ",string(deal_position_number));

           }
        }
     }  
bool  HistorySelect(
   datetime  from_date,     // From date
   datetime  to_date        // To date
   );

If you want to check all the history, you have to set:

HistorySelect(0, TimeCurrent());

https://www.mql5.com/en/docs/trading/historyselect

Regards.

You’re using an unsigned integer than cannot be decremented below zero so your for loop will run continuously. Change to int.

Or use the form

for(uint x = ...; x > 0;){ --x; 
   Time[x] ...
}

Thank you all , your advices was nice and it works perfectly. :slight_smile: