Expert and files

 

Hello,

I tried to search this topic, but I can't find anything in the forum. 

My question is very simple. I'm developing an EA and I would like to store some informations in a permanent way (i.e. to prevent Mt4 crashes or pc shutdown) . I heard about GV, but my EA should works on different symbols and with different informations for each one and GVs stores only a double value. So I thought to create a file (.txt for example) to store all the matching between symbols and informations or, easier, one file for each symbol. 

My problem is that I can't find anything about the creation of a file. Can an Expert create by itself a file ? How ?

Alternatively, are there other solutions ?

 
Usernamelessss: I can't find anything about ...
Perhaps you should read the manual.
          File Functions - MQL4 Reference
 
whroeder1:
Perhaps you should read the manual.
          File Functions - MQL4 Reference

Thanks whroeder1, 

I read something in the manual before post my request, but I didn't find the reply to my question. 

I didn't find any function for creating files. I just read something in FileWrite(), expecially here:

//--- open the file for writing the indicator values (if the file is absent, it will be created automatically)
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s file is available for writing",InpFileName);
      PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      //--- first, write the number of signals
      FileWrite(file_handle,sign_size);
      //--- write the time and values of signals to the file
      for(int i=0;i<sign_size;i++)
         FileWrite(file_handle,time_buff[i],sign_buff[i]);
      //--- close the file
      FileClose(file_handle);
      PrintFormat("Data is written, %s file is closed",InpFileName);
     }
   else
      PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
  }

but I didn't understand if it's what I need. If yes, I didn't understand the code: if FileOpen(...) miss to open a file (because it's absent), it should return INVALID_HANDLE. So this code, if the file is absent,  go to PrintFormat. 

Am I right ? Or are you thinking about another function?

 

Did you read File Opening Flags section ??:


One or several flags can be specified when opening a file. This is a combination of flags. The combination of flags is written using the sign of logical OR (|), which is positioned between enumerated flags. For example, to open a file in CSV format for reading and writing at the same time, specify the combination FILE_READ|FILE_WRITE|FILE_CSV.

Example:

   int filehandle=FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV);

There are some specific features of work when you specify read and write flags:

  • If FILE_READ is specified, an attempt is made to open an existing file. If a file does not exist, file opening fails, a new file is not created.
  • FILE_READ|FILE_WRITE — a new file is created if the file with the specified name does not exist.
  • FILE_WRITE —  the file is created again with a zero size.

When opening a file, specification of FILE_WRITE and/or FILE_READ is required.

https://docs.mql4.com/constants/io_constants/fileflags


Regards.

File Opening Flags - Input/Output Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
File Opening Flags - Input/Output Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Shared access for reading from several programs. Flag is used in FileOpen(), but it does not replace the necessity to indicate FILE_WRITE and/or the FILE_READ flag when opening a file. Shared access for writing from several programs. Flag is used in FileOpen(), but it does not replace the necessity to indicate FILE_WRITE and/or the FILE_READ...
 
Jose Francisco Casado Fernandez:

Did you read File Opening Flags section ??:


One or several flags can be specified when opening a file. This is a combination of flags. The combination of flags is written using the sign of logical OR (|), which is positioned between enumerated flags. For example, to open a file in CSV format for reading and writing at the same time, specify the combination FILE_READ|FILE_WRITE|FILE_CSV.

Example:

   int filehandle=FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV);

There are some specific features of work when you specify read and write flags:

  • If FILE_READ is specified, an attempt is made to open an existing file. If a file does not exist, file opening fails, a new file is not created.
  • FILE_READ|FILE_WRITE — a new file is created if the file with the specified name does not exist.
  • FILE_WRITE —  the file is created again with a zero size.

When opening a file, specification of FILE_WRITE and/or FILE_READ is required.

https://docs.mql4.com/constants/io_constants/fileflags


Regards.

That's exactly what I was looking for! Thank you very much both of you
 
Usernamelessss:
That's exactly what I was looking for! Thank you very much both of you
You are welcome.  Regards.
Reason: