Download MetaTrader 5

sorting Trades by opening time

To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
bah12ram
76
bah12ram 2016.10.09 10:30 

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
Marco vd Heijden
Moderator
4706
Marco vd Heijden 2016.10.10 08:31  

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.

To add comments, please log in or register