Decreasing loop for history deals not work in MQL5

 
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.

Documentation on MQL5: Trade Functions / HistorySelect
Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
HistorySelect() creates a list of orders and a list of trades in a mql5-program, for further referring to the list elements using corresponding functions. The deals list size can be returned using the HistoryDealsTotal() function; the size of the list of orders in the history can be obtained using HistoryOrdersTotal(). Selection in the list of...
 
Tanvir Ahmed:
I want to count history deals from down to up. But my code not work perfectly. Please help me anyone.

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

 
nicholishen: 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] ...
}
 
nicholishen:

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


Thank you @nicholishen , your advice nice and it  works perfectly. :)


 
Leon Lam:

Your code is a single loop, how to decrease? May be you need overall loop times. For example: loop once in a minute.


Thank you
 
Jose Francisco Casado Fernandez:


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


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


Regards.


Thank you, I corrected the selection.