FileOpen

 

/

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()); 

 }

The above code refers to FileOpen , In the case of Historical data, is there a way of extracing  ohlc data from MT4 programmatically .Thanks



 
Mary A Thompson: In the case of Historical data, is there a way of extracing  ohlc data from MT4 programmatically?

Yes!

Timeseries and Indicators Access - MQL4 Reference
Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
Timeseries and Indicators Access - MQL4 Reference
 
Mary A Thompson:
   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); 

You don't specify the path, /Files is implicit.

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

 

@William Roeder, the above code is not the OP's. It is code quoted from the FileOpen documentation example (to explain that very fact you have commented on).