|
按照官方给的案例,FileOpen总是出报错,5002错误。
- 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(),PERIOD_CURRENT);
- FileClose(filehandle);
- Print("FileOpen OK");
- }
- else Print("Operation FileOpen failed, error ",GetLastError());
复制代码
后来查看了官方给的案例,总结修改成这样就可以运行了:
- filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_READ|FILE_CSV);
复制代码
另外,不要用绝对路径,用相对路径,会自动生成一个文件在MQL4/file下面。
|
|