File opening fails with error 5004 but succeeds in all other instances

 

Hi, I have an issue with file opening during optimization, if the test is ran on visual mode or EA is attached to a chart, the file opening always succeeds, if the file is less than 1.3MB out of 100 passes, the file opening may fail less than 7 times during optimization, with a file greater than 8MB, it never opens during optimization. I've checked the documentation, saw nothing related to max file size during optimization.

The file is always located at the common folder so it's accessible on any instance.

Here's the code responsible for opening the file

 string m_file_history = "short_file.bin";
 int handle = FileOpen(m_file_history,FILE_READ|FILE_BIN|FILE_ANSI|FILE_COMMON), str_size = 0;
 string data = "";
 if (handle != INVALID_HANDLE)
 {
  //.....
  FileClose(handle);
 }
 else 
 {
  string message = "Could not open file. Error code ="+string(GetLastError())+" file name "+m_file_history;
  Print(message);
  WriteToFile(message);
  return false;
 }


 The above code is called within OnInit(), since "Print" is disabled during optimization, I use "WriteToFile" to output the error to a file, the file opening always fails with error 5004

 
holocast:

Hi, I have an issue with file opening during optimization, if the test is ran on visual mode or EA is attached to a chart, the file opening always succeeds, if the file is less than 1.3MB out of 100 passes, the file opening may fail less than 7 times during optimization, with a file greater than 8MB, it never opens during optimization. I've checked the documentation, saw nothing related to max file size during optimization.

The file is always located at the common folder so it's accessible on any instance.

Here's the code responsible for opening the file


 The above code is called within OnInit(), since "Print" is disabled during optimization, I use "WriteToFile" to output the error to a file, the file opening always fails with error 5004


hi

I have the same issue

I've place my file in the "common" folder.

I can open the file in the single backtesting with no problem.

but it won't open during optimization!
anyoone has a solution to this?


THANKS!

 
ok so i discovered the solution is simply this:
include FILE_SHARE_READ flag when calling FileOpen function.
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