sorting Trades by opening time

 

how can I get time1 and time2 to sort orders by time?


//+------------------------------------------------------------------+

//|                                                       rrrrrr.mq4 |
//|                                                             test |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "test"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return;
  // write header
  FileWrite(handle,"#","open price","open time","symbol","lots");
  int total=OrdersTotal();
  // write open orders
 
   

for (int i = 0; i <= total; i ++)
      {
      
        {
        if(OrderSelect(i,SELECT_BY_POS)==false) continue;
        
       string time1 = TimeToStr(OrderOpenTime());
     string time2 = TimeToStr(OrderOpenTime());
      if (time1 < time2) continue;
        
     FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots());
           
        }
     }
  FileClose(handle);
 
  }
//+------------------------------------------------------------------+
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

You can just use

if(OrderOpentime_1 > OrderOpentime_2)
 {
  //...
 }

Etc..

So you first store all times in a datetime array and then sort them.

Maybe ArraySort() can also help.

Reason: