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.

      for(uint i = uint(HistoryDealsTotal()-1); i >= 0; i--)
            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());



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: