Download MetaTrader 5

What is the default folder for reading external csv file?

To add comments, please log in or register
Move from theory to practice. Code Base will help you!
nicolasxu 2015.05.03 14:54 

I understand MT5 can not write file to directories other than in its own sub directory for security reason. Here, I am trying to read a file. 

I am putting a csv file, "ssTestData.csv", to the folder "C:\Users\nick\AppData\Roaming\MetaQuotes\Terminal\158904DFD898D640E9B813D10F9EB397\Files\" in  my Windows 8 computer. 

The folder path is obtained by this code:

PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));


Here is the code I use to read file content, but the handle value is always -1.


int readDataTo(double &dataFromFile[]) {
   string directory = "C:\\Users\\nick\\AppData\\Roaming\\MetaQuotes\\Terminal\\158904DFD898D640E9B813D10F9EB397\\Files\\";
   string fileName = "ssTestData.csv";
   PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
   int fileHandle = FileOpen(directory + fileName, FILE_READ|FILE_CSV);
   if(fileHandle == INVALID_HANDLE) {
      printf("Open file: " + fileName + " error, with handle value %d", fileHandle);
      return -1;
   // preform file reading and data assemble
   return 1;


I suspect the problem is because of the wrong path and the code couldn't find the file. I also tried to use fileName directly without the "directory+", but handle value is always -1.


Can you please tell me where I should put the "ssTestData.csv", and how to specify the path for reading?


Thanks a lot!

Drazen Penic
Drazen Penic 2015.05.03 17:48  

You don't need to specify folder. 

If file exists in "Files" folder, this is enough:


int fileHandle = FileOpen(fileName, FILE_READ|FILE_CSV);
To add comments, please log in or register