Slawa: Index order of closed trade history

 
Hello,

I'm trying to run totals on the closed trade history for all orders that opened after a certain datetime.

I thought I would save program cycles by working backwards through the history, starting from the most recent closed trade and going backwards, like this:

// step backwards through history so only relevant recent history is analyzed.
for(int i=OrdersHistoryTotal();i>=0;i--) 
     {
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
     if(OrderCloseTime()==0) continue;
     
     // have now hit orders earlier than current trade group, stop analyzing.
     if(OrderOpenTime()<earliestOpenOrderTime) break; 
     
     // ... do some stuff here
     
     }



The problem is that it seems that the order of the trades in the history is something different than the ticket number or the order open time because I'm breaking out of the for loop before I've analyzed all the trades I want.

Have I made a mistake here or is the only way to do this to cycle through ALL of the trade history?

Thank you very much,

Christian

 
Order of closed positions list is undefined. In common cases list ordered by close time.
 
That explains it.

Thank you for your answer.
Reason: