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 5004Alert("done");
} elseAlert("Operation FileOpen failed, error ",GetLastError(), TerminalInfoString(TERMINAL_DATA_PATH));
return filehandle;
}
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.
//+------------------------------------------------------------------+//| Get the symbols |//+------------------------------------------------------------------+void TProgram::GetSymbolsFromFile(conststring filePath, conststring 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);
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
hey
it seems error 5004 is related to not closing file!
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.
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:
I tried many different parameters and filePaths
1 - Tried to use the therminal file path and none of this works.
I got the errors: 5002 e 5004
ERR_WRONG_FILENAME
5002
Invalid file name
ERR_CANNOT_OPEN_FILE
5004
File opening error