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.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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);
}
//+------------------------------------------------------------------+