Error Code 5004 - page 4

 
samoye:   Is there a solution to error 5004 please? I am getting the same error message trying to write to a file.  
Asked and answered. Open the file once before the loop. Close the file after the loop.
 

hey

it seems error 5004 is related to not closing file!


int readFileImg (string file_name) {

   int filehandle = FileOpen(file_name, FILE_READ|FILE_BIN);

   if (filehandle!=INVALID_HANDLE) {

      FileClose(filehandle);  // this line is important, without this line you will get 5004

      Alert("done");

   } else Alert("Operation FileOpen failed, error ",GetLastError(), TerminalInfoString(TERMINAL_DATA_PATH));

   return filehandle;

}

 

Please use the </> button to insert your code.


 

I have the same 5004 error popping up while testing the EA using Strategy Tester. It must be a bug in mt4 since it can open other files in in the same session but suddenly it cannot open files.

I use this for backtesting a machine learning algorithm.

Now I need another platform for backtesting the algorithm since mt4 doesn't work.

Any ideas on other backtesting platforms?

Preferably python based.

 
Try MT5.
 
kypa:
Try MT5.

I am trying to debug my program and I am having the same issue.

Based on the example in the FileOpen Docs, I created this function to read a symbol list from a file.

I included the file in the editor's "Files Directory" and I call the funcion like that:


GetSymbolsFromFile("carteiras","ibrx_100_2018_12_10.txt");
//+------------------------------------------------------------------+
//| Get the symbols                                                  |
//+------------------------------------------------------------------+
void TProgram::GetSymbolsFromFile(const string filePath, const string fileName)
{
   //--- additional variables 
   int    str_size; 
   string str;
   int    array_size;
   string terminal_data_path;
   
   //--- open the file 
   ResetLastError(); 
   //--- Release the symbol array
   ::ArrayFree(m_file_symbols);
   
   terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
   PrintFormat("File path: %s\\Files\\",terminal_data_path);
   
   bool  test1 = FileIsExist(fileName,0 );
   bool  test2 = FileIsExist(fileName,FILE_COMMON);
   
   int file_handle=FileOpen(fileName,FILE_READ|FILE_TXT|FILE_ANSI); 
   if(file_handle!=INVALID_HANDLE) 
   { 
      PrintFormat("%s file is available for reading",filePath); 
      //PrintFormat("File path: %s\\Files\\",terminal_data_path);
      //--- read data from the file 
      while(!FileIsEnding(file_handle)) 
        { 
         //--- find out how many symbols are used for writing the time 
         str_size=FileReadInteger(file_handle,INT_VALUE); 
         //--- read the string 
         str=FileReadString(file_handle,str_size); 
         
         array_size=::ArraySize(m_file_symbols);
         ::ArrayResize(m_file_symbols,array_size+1);
         m_file_symbols[array_size]=str;
         
         //--- print the string 
         PrintFormat(str); 
        } 
      //--- close the file 
      FileClose(file_handle); 
      PrintFormat("Data is read, %s file is closed",fileName); 
   }
   else
   {
      PrintFormat("Failed to open %s file, Error code = %d",fileName,GetLastError()); 
   }
}

I tried many different parameters and filePaths

1 - Tried to use the therminal file path and none of this works.

 int file_handle=FileOpen(fileName,FILE_READ|FILE_TXT|FILE_ANSI); 

I got the errors: 5002 e 5004

ERR_WRONG_FILENAME

5002

Invalid file name

ERR_CANNOT_OPEN_FILE

5004

File opening error

Files:
Reason: