Mql5 - Fileopen cannot read file when debugging with historical data

 

Hello all.

I have a set of txt files my EA reads to get external data, but it does not work when debugging with historical data on MT5 version 5.00, build 2980. It works when debugging in real time instead.

  • I have been trying to include the tester_file.
  • I am using the FILE_COMMON flag on my program.
  • I have also copied the files to the Tester/files
  • Tried copying the files to each of the Tester/<terminal>/<agent>/MQL5/Files folders.
  • Copied the files to ./Terminal/Common folder.
  • Since I was unsure of how to use the tester_file flag, I just tried with one file and then with two file names, separated by commas, just to try more combinations.

And I am now, after a few hours of research, stuck.

When I run the real-time debugger it works, see:

But when running the debugger using historical data, it does not.

Two of these file names are:

input string daily_variance_file_name="daiy_variance_est_dst.txt";
input string hourly_variance_file_name="hourly_variance_gmt_plus_3.txt";

and this is one of the methods that read files:

void readCSVHourlyVariance(){

   ushort u_sep;    
   u_sep=StringGetCharacter(csv_delimiter,0);
   string fileContents;
   
   ArrayResize(hourlyVariances.date_hour,24);
   ArrayResize(hourlyVariances.delta_height,24);
   ArrayResize(hourlyVariances.mean_height,24);
   ArrayResize(hourlyVariances.stdev_height,24);
   
   ArrayResize(hourlyVariances.stdev_phi,24);
   ArrayResize(hourlyVariances.mean_phi,24);
   
   hourlyVariances.symbol=Symbol();
   

   int file_handle=FileOpen(hourly_variance_file_name,FILE_COMMON|FILE_SHARE_READ|FILE_ANSI);
   
   if (file_handle!=INVALID_HANDLE && !IsStopped()){
          int    str_size;
      string str;

      while(!FileIsEnding(file_handle))
        {
         str_size=FileReadInteger(file_handle,INT_VALUE);
         str=FileReadString(file_handle,str_size);
         string string_array[];
         StringSplit(str,u_sep ,string_array);
         string symbol=string_array[0];
         
         if (Symbol()==symbol){
            int date_year= StringToInteger(string_array[1]);
            int date_hour= StringToInteger(string_array[2]);
            double mean_height= StringToDouble(string_array[3]);
            double stdev_height= StringToDouble(string_array[4]);
            double delta_height= StringToDouble(string_array[5]);
            double mean_phi = StringToDouble(string_array[6]);
            double stdev_phi = StringToDouble(string_array[7]);
            
            int index=date_hour;
            hourlyVariances.date_year=date_year;
            hourlyVariances.date_hour[index]=date_hour;
            hourlyVariances.mean_height[index]=mean_height;
            hourlyVariances.stdev_height[index]=stdev_height;
            hourlyVariances.delta_height[index]=delta_height;
            hourlyVariances.mean_phi[index]=mean_phi;
            hourlyVariances.stdev_phi[index]=stdev_phi;
         }
         
        }
      FileClose(file_handle);
   }
  
}

I tried before wihtout FILE_COMMON and using only FILE_READ (originally). I have just changed it because I am trying to fix this problem.

Now, the files are loaded during the OnInit event:

int OnInit()

   
  {
   [...]
 
   readCSVDailyVariance();
   readCSVHourlyVariance();
 
  [...]

   return(INIT_SUCCEEDED);
  }

I also tried OnTesterInit(), but it made no difference. There are so many possible things to check that I am a bit confused after a few hours trying over and over and reading the forum threads.

So, I would really appreciate some light on this. 

Thank you in advance.

Documentation on MQL5: Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
Documentation on MQL5: Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
  • www.mql5.com
File Opening Flags - Input/Output Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Gonzalo Sanchez:

Hello all.

I have a set of txt files my EA reads to get external data, but it does not work when debugging with historical data on MT5 version 5.00, build 2980. It works when debugging in real time instead.

  • Thank you in advance.


Get external data? From the txt files. 

Works on realtime debug (so code is fine and well programmed), but not on historic debug..


Will the data exists on those files to be read for such past time?

 
rrocchi #:


Get external data? From the txt files. 

Works on realtime debug (so code is fine and well programmed), but not on historic debug..


Will the data exists on those files to be read for such past time?


Does this not work on historical data at all? Like tester..