Indicator - Error code 5004: File open

 

Hi mates,


I've got a problem with the FileOpen(), I'm triying to read a csv text file, i've got the text error "Error code 5004" I know that this code tell me that metatraer cannot open my file. I've seen another posts and they said that the problem is with the path. But I follow all the instructions and i'm having the same result.



I let you my code here:

With that method I want to read the file "Symbol()+.'csv' " and put all the objects that i'm reading in that file. In the write of the file i don't have problems with the path and the information is save correctly.


Thx for you'r time.


Naitrisc. 

void readFile(){

   
   string filename=Symbol(); 
   int filehandle=FileOpen(filename+".csv",FILE_READ|FILE_CSV, ","); 
   
   Print("filename: "+filename);
   string nameObj;
   int tipo;
   
   double price1, price2, price3, fibolvl;
   datetime time1, time2, time3;
    
   int with, color, corner, ray, style, timeframe, x, y, with, selected, fill;
   string font, description;
   
   int obj_total = ObjectsTotal();
   string name3;   
      
      for(int w = 0; w <= obj_total; w++)
      {
         name3 = ObjectName(w);
         ObjectDelete(0, name3);
         ObjectDelete(0,StringSubstr(name3,1,0));
         //permisoBorrar = false;
      }
      
   
   while(FileIsEnding(filehandle)==false) // While the file pointer..
   { // ..is not at the end of the file
      nameObj = FileReadString(filehandle); // symbol
      type= StrToInteger(FileReadString(filehandle)); 
      price1 = StrToDouble(FileReadString(filehandle));
      price2 = StrToDouble(FileReadString(filehandle));
      price3 = StrToDouble(FileReadString(filehandle));
      time1 = StrToTime(FileReadString(filehandle));
      time2 = StrToTime(FileReadString(filehandle));
      time3 = StrToTime(FileReadString(filehandle));
      color1= StrToInteger(FileReadString(filehandle));
      with = StrToInteger(FileReadString(filehandle));
      corner= StrToInteger(FileReadString(filehandle));
      ray= StrToInteger(FileReadString(filehandle));
      style= StrToInteger(FileReadString(filehandle));
      timeframe = StrToInteger(FileReadString(filehandle));
      x = StrToInteger(FileReadString(filehandle));
      y = StrToInteger(FileReadString(filehandle));
      fibolvl = StrToInteger(FileReadString(filehandle));
      font= FileReadString(filehandle);
      fontwith= StrToInteger(FileReadString(filehandle));
      descripcion = FileReadString(filehandle);
      selected= StrToInteger(FileReadString(filehandle));
      fill = StrToInteger(FileReadString(filehandle));
      
      
       
       ObjectCreate(0,nameObj,tipo,0,time1,precio1,time2,precio2,time3,precio3);
       ajustarTiempo(nameObj);
        if(Period() == 1 || Period() == 5 || Period() == 15)
        {
            ObjectSet(nameObj, OBJPROP_WIDTH, 1);
            ObjectSetInteger(0, nameObj, OBJPROP_STYLE, estilo);
        }
        else
        {
            ObjectSet(nameObj, OBJPROP_WIDTH, anchura);
        }
        ObjectSet(nameObj, OBJPROP_SELECTED, True);
        ObjectSet(nameObj, OBJPROP_COLOR, tonalidad);
        
        
      /-- Creation of the objects that i read --/ //I don't put the code here, a lot of lines defining what my indicator must create
      
      
      
   }
   
   FileClose(filehandle);
   

}
FileOpen - File Functions - MQL4 Reference
FileOpen - File Functions - MQL4 Reference
  • docs.mql4.com
[in]  The name of the file can contain subfolders. If the file is opened for writing, these subfolders will be created if there are no such ones. [in]  value to be used as a separator in txt or csv-file. If the csv-file delimiter is not specified, the default delimiter is ";". If the txt-file delimiter is not specified, then no separator is...
 
Naitrisc::

With that method I want to read the file "Symbol()+.'csv' " and put all the objects that i'm reading in that file. In the write of the file i don't have problems with the path and the information is save correctly.

1) For the writing you stated that you are using a path. But your code is reading without a path...

2) Are your trying to read from another MT client? If so, they don't share the same file sandbox I guess (I know for sure that this is true with MT5)...

Cheers!

;)

 

@Minions Labs Thx for your comment, today I can resolve the issue, the code that I posted is ok. The problem was with the for, was declared after the file open (when i delete an object i actualize the file so i make the call without close the file) because of that i have the error 5004. Mt4 cannot open a file that has not been closed. 


Thx for you'r time!

Reason: