- void OnStart()
- {
- //--- incorrect file opening method
- string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
- string filename=terminal_data_path+"\\MQL4\\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"
- ResetLastError();
- filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV);
- if(filehandle!=INVALID_HANDLE)
- {
- FileWrite(filehandle,TimeCurrent(),Symbol(), EnumToString(ENUM_TIMEFRAMES(_Period)));
- FileClose(filehandle);
- Print("FileOpen OK");
- }
- else Print("Operation FileOpen failed, error ",GetLastError());
- //--- another example with the creation of an enclosed directory in MQL4\Files\
- string subfolder="Research";
- filehandle=FileOpen(subfolder+"\\fractals.txt",FILE_WRITE|FILE_CSV);
- if(filehandle!=INVALID_HANDLE)
- {
- FileWrite(filehandle,TimeCurrent(),Symbol(), EnumToString(ENUM_TIMEFRAMES(_Period)));
- FileClose(filehandle);
- Print("The file most be created in the folder "+terminal_data_path+"\"+subfolder);
- }
- else Print("File open failed, error ",GetLastError());
- }
复制代码
|