Hello,
i try to write a file in the file section. The should be created.
The folder exists. Can check it with explorer an print out to console.
What is wrong ?
Thank you
What is wrong ?. The wrong part is that you read the wrong example. Here's the example from FileOpen
void OnStart() { //--- incorrect file opening method <<== PLEASE READ THIS 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); if(filehandle<0) { Print("Failed to open the file by the absolute path "); Print("Error code ",GetLastError()); } //--- correct way of working in the "file sandbox" <<== PLEASE READ THIS ResetLastError(); filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV); if(filehandle!=INVALID_HANDLE) { FileWrite(filehandle,TimeCurrent(),Symbol(),PERIOD_CURRENT); FileClose(filehandle); Print("FileOpen OK"); } else Print("Operation FileOpen failed, error ",GetLastError()); //--- another example with the creation of an enclosed directory in MQL5\Files\ string subfolder="Research"; filehandle=FileOpen(subfolder+"\\fractals.txt",FILE_WRITE|FILE_CSV); if(filehandle!=INVALID_HANDLE) { FileWrite(filehandle,TimeCurrent(),Symbol(),PERIOD_CURRENT); FileClose(filehandle); Print("The file most be created in the folder "+terminal_data_path+"\\"+subfolder); } else Print("File open failed, error ",GetLastError()); }
New problem, file reading:
My file has 2 ANSI lines:
ABCD
EFGH
int filehandle=FileOpen("myexistingfile",FILE_READ|FILE_TXT|FILE_ANSI); if(filehandle != INVALID_HANDLE) { string content=FileReadString(filehandle,-1); }
content is only ABCD.
(content was written (ANSI) to file with "\r\n" to separate rows).
How to get the whole content, please ?
Thank you
New problem, file reading:
My file has 2 ANSI lines:
ABCD
EFGH
content is only ABCD.
(content was written (ANSI) to file with "\r\n" to separate rows).
How to get the whole content, please ?
Thank you
So you have more than 1 line. How about also more than 1 column ? like this :
ABCD, EXGH, IJKL
MNOP, QRST, ,
UVWX, YZ12, 3456, 7890
Stay tune, I'll be back ! ;D
... or use mql5 search
string filename=terminal_data_path+"\\MQL5\\Files\\"+"myfile.txt";
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)
Creation date of Indicator - Expert Advisors and Automated Trading - MQL5 programming forum (2021.05.12)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
i try to write a file in the file section. The should be created.
The folder exists. Can check it with explorer an print out to console.
What is wrong ?
Thank you