Error Code 5004

 

I am trying to migrate to MT5 and have had a few struggles.  The following I don't quite understand.

I get an ERROR 5004 when using the following code:-

2020.03.30 14:04:20.165    Message    My_error: 5004 File opening error

   fname = path_name +strfname+".csv";
   if (!FileIsExist(fname)) strMsg = strMsg+ "\n\n105 "+fname+" NOT FOUND";   
   if(FileIsExist(fname)) 
      {  int iFieldCounter = 1;
         bool DescriptorsRead = false;       
         Read_Handle2 = FileOpen(fname,FILE_READ|FILE_ANSI|FILE_CSV,","); //FILE_TXT  ); //
         int My_error=GetLastError();
         string st_99999 = "\nMy_error: "+IntegerToString(My_error)+" "+ErrorDescription(My_error);   
         strMsg = strMsg + st_99999;
         if ( Test_ReadFile == true) MessageBox(strMsg);
         ResetLastError();
         strMsg = "106 \n"+fname+"\n is LOCATED & Read_Handle2 = "+IntegerToString(Read_Handle2)+
         " DescriptorsRead = "+DescriptorsRead;

Is there any practical limit to the number of open files

The code works on some charts but not on others - a factor I haven't figured out.

The file EXISTS - i.e. gets down to strMsg = "106......

The 5004 Error isn't too helpful (to me here).  The code appears to work for other similar files

I has 5008 Error and changed the code to refer to Read_Handle2

I tried with and without "," delimiter and using FILE_TXT but appears to be same


Any help appreciated

 
fname = path_name +strfname+".csv";
What is path_name? The code reads <dataFolder>/Files/<strfname>.csv or <dataFolder>/Tester/Files/… You shouldn't have a path unless you are trying to read a sub-folder of Files.
          Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 2014.02.03
 
Peter Williams:

I am trying to migrate to MT5 and have had a few struggles.  The following I don't quite understand.

I get an ERROR 5004 when using the following code:-

2020.03.30 14:04:20.165    Message    My_error: 5004 File opening error

Is there any practical limit to the number of open files

The code works on some charts but not on others - a factor I haven't figured out.

The file EXISTS - i.e. gets down to strMsg = "106......

The 5004 Error isn't too helpful (to me here).  The code appears to work for other similar files

I has 5008 Error and changed the code to refer to Read_Handle2

I tried with and without "," delimiter and using FILE_TXT but appears to be same


Any help appreciated

have changed CSV to TXT and seem to have a work round

 
William Roeder:
What is path_name? The code reads <dataFolder>/Files/<strfname>.csv or <dataFolder>/Tester/Files/… You shouldn't have a path unless you are trying to read a sub-folder of Files.
          Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 2014.02.03

Many thanks.  I think I am compliant

path_name   = "Weights\\WeightsMT5Input\\";

The index file contains a list of files which are in the same directory.

Each contain the 'weights' for appropriate currency pair and are the output from the Strategy Tester.


I now read the txt file file and use StringSplit()

Reason: