Common Folder in OnInit() and the Dbugger/Indicator => 5002 error??

 

Is there a mistake of mine (b.2615) or is it impossible to access the Common folder from the debugger and/or indicator?

This little piece of code at the end of OnInit():

Oninit() {
   ...   
   string t = TerminalInfoString(TERMINAL_COMMONDATA_PATH);
   string Fcsv = t+"\\MA\\Test.csv";
   // Fcsv => C:\Users\cas\AppData\Roaming\MetaQuotes\Terminal\Common\MA\Test.csv
   int h = FileOpen(Fcsv,FILE_WRITE|FILE_BIN|FILE_COMMON);
   Print("FName: ",Fcsv," Common: ",t," Hdl: ",h," err: ",_LastError);
   ResetLastError();
   FileClose(h);
   Print("FName: ",Fcsv," Common: ",t," Hdl: ",h," err: ",_LastError);
}

causes:

2020.09.22 11:59:52.828   myIndi (EURUSD,M5)   FName: C:\Users\cas\AppData\Roaming\MetaQuotes\Terminal\Common\MA\Test.csv Common: C:\Users\cas\AppData\Roaming\MetaQuotes\Terminal\Common Hdl: -1 err: 5002
2020.09.22 11:59:52.838   myIndi (EURUSD,M5)   FName: C:\Users\cas\AppData\Roaming\MetaQuotes\Terminal\Common\MA\Test.csv Common: C:\Users\cas\AppData\Roaming\MetaQuotes\Terminal\Common Hdl: -1 err: 5008

5002 = ERR_WRONG_FILENAME      5002  Invalid Filename
5008 = ERR_WRONG_FILEHANDLE  5008  Invalid handle

PS: Of course the Common folder exists and is accessible.

PPS: Even without using the path to Common I get this error:

Oninit() {
   ...   
   string t = TerminalInfoString(TERMINAL_COMMONDATA_PATH);
   string Fcsv = "\\MA\\Test.csv";
   // Fcsv => \MA\Test.csv
   int h = FileOpen(Fcsv,FILE_WRITE|FILE_BIN|FILE_COMMON);
   Print("FName: ",Fcsv," Common: ",t," Hdl: ",h," err: ",_LastError);
   ResetLastError();
   FileClose(h);
   Print("FName: ",Fcsv," Common: ",t," Hdl: ",h," err: ",_LastError);
}


 
   string t = TerminalInfoString(TERMINAL_COMMONDATA_PATH);
   string Fcsv = t+"\\MA\\Test.csv";

No, NO, NO! Do not add path to filenames.

File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 2020.06.12
and FolderDelete using TERMINAL_DATA_PATH - General - MQL5 programming forum 2017.12.13

 

Thanks and ok!

Haven't done it for some time and I copied the example from the reference of FileOpen:

   string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH); 
   string filename=terminal_data_path+"\\MQL5\\Files\\"+"fractals.csv"; 
   int filehandle=FileOpen(filename,FILE_WRITE|FILE_CSV); 
Reason: