Unable to open file - Always showing 5002 error

 
void OnTick()
  {   
      string filename = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\example.ini";
      int file_handle = FileOpen(filename, 1);
      if (file_handle == INVALID_HANDLE)
      {
          Comment("Failed to open file: " + filename + GetLastError());
          return;
      }
      
      string line;
      while (!FileIsEnding(file_handle))
      {
          line = FileReadString(file_handle);
          if (StringLen(line) > 0)
          {
              // Process the line
              Comment(line);
          }
      }
      
      FileClose(file_handle);

  }
 
try:


string filename = "example.ini";
 
moneykrishna:

void OnTick()    <<-- don't open the file every tick
  {   
      string filename = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Files\\example.ini";   <<-- incorrect path see documentation
      int file_handle = FileOpen(filename, 1);   <<---- what is this supposed to be?  don't use numerics for enumerations
      if (file_handle == INVALID_HANDLE)
      {
          Comment("Failed to open file: " + filename + GetLastError());
          return;
      }
      
https://www.mql5.com/en/docs/files/fileopen
Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Reason: