//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                                  Copyright 2025, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
//--- display the window of input parameters when launching the script
#property script_show_inputs
//--- parameters for data reading
input string InpFileName="Time.txt"; // file name

#define UniqueID  "t:"

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   ObjectsDeleteAll(0,UniqueID);

   string sDelimiter2 = "\n";
   ushort uDelimiter2 = StringGetCharacter(sDelimiter2, 0); 
   string sResult2[];
   string sDelimiter = ";";
   ushort uDelimiter = StringGetCharacter(sDelimiter, 0); 
   string sResult[];
   string sDelimiter0 = " ";
   ushort uDelimiter0 = StringGetCharacter(sDelimiter0, 0); 
   string sResult0[];
   int    iDirection = 1;

//--- open the file
   ResetLastError();
   int file_handle=FileOpen(InpFileName,FILE_READ|FILE_BIN|FILE_ANSI);
   if(file_handle!=INVALID_HANDLE)
     {
      string str2,str,str0;
      //--- read data from the file
      while(!FileIsEnding(file_handle))
        {
         //--- read the string
         str2=FileReadString(file_handle);
         int nSubStrings2 = StringSplit(str2, uDelimiter2, sResult2); 
         for (int i = 0; i < nSubStrings2; i++) {
            str=sResult2[i];
            int nSubStrings = StringSplit(str, uDelimiter, sResult); 
            for (int j = 0; j < nSubStrings; j++) {
               str0=sResult[j];
               int nSubStrings0 = StringSplit(str0, uDelimiter0, sResult0); 
               //--- show as event
               if(iDirection==1) EventCreate(0,UniqueID+sResult[j],0,sResult0[1],StringToTime(sResult[j]),clrDeepSkyBlue);
               if(iDirection==-1) EventCreate(0,UniqueID+sResult[j],0,sResult0[1],StringToTime(sResult[j]),clrRed);
               //Print(iDirection," ",sResult0[0]," ",sResult0[1]);
            }
            iDirection = (iDirection==1) ? -1 : 1;
         }
         //--- print the string
         //Print(str);
        }
      //--- close the file
      FileClose(file_handle);
      PrintFormat("Data is read, %s file is closed",InpFileName);
     }
   else
      PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
  }
//+------------------------------------------------------------------+
//| Create Event object on the chart                                 |
//+------------------------------------------------------------------+
bool EventCreate(const long            chart_ID=0,      // chart's ID
                 const string          name="Event",    // event name
                 const int             sub_window=0,    // subwindow index
                 const string          text="Text",     // event text
                 datetime              time=0,          // time
                 const color           clr=clrRed,      // color
                 const int             width=1,         // point width when highlighted
                 const bool            back=false,      // in the background
                 const bool            selection=false, // highlight to move
                 const bool            hidden=true,     // hidden in the object list
                 const long            z_order=0)       // priority for mouse click
  {
//--- if time is not set, create the object on the last bar
   if(!time)
      time=TimeCurrent();
//--- reset the error value
   ResetLastError();
//--- create Event object
   if(!ObjectCreate(chart_ID,name,OBJ_EVENT,sub_window,time,0))
     {
      Print(__FUNCTION__,
            ": failed to create \"Event\" object! Error code = ",GetLastError());
      return(false);
     }
//--- set event text
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set anchor point width if the object is highlighted
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving event by mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
