Load and display trade data from CSV files on the chart

 

Hello everyone,

My MQL5 indicator is supposed to import trade data from a CSV file and display them on the chart. The CSV file is properly exported and placed in the Terminal/Common/Files folder, but the indicator keeps returning error 5002 saying the file doesn't exist. The file is definitely there, what could be causing this file access problem?

Thanks!

 
Abdeljalil El Kedmiri:

Hello everyone,

My MQL5 indicator is supposed to import trade data from a CSV file and display them on the chart. The CSV file is properly exported and placed in the Terminal/Common/Files folder, but the indicator keeps returning error 5002 saying the file doesn't exist. The file is definitely there, what could be causing this file access problem?

Thanks!

Depending on the way in which your indicator is coded to access the CSV file, e.g., via DLL, you might want to check your AppData folder permissions and/or CSV file permissions in Windows or whichever system you have... and any firewall settings.
 
Abdeljalil El Kedmiri:

Hello everyone,

My MQL5 indicator is supposed to import trade data from a CSV file and display them on the chart. The CSV file is properly exported and placed in the Terminal/Common/Files folder, but the indicator keeps returning error 5002 saying the file doesn't exist. The file is definitely there, what could be causing this file access problem?

Thanks!

Did you check what error 5002 means ?

Show your code if you need coding help.

 
Abdeljalil El Kedmirierror 5002 saying the file doesn't exist. The file is definitely there, what could be causing this file access problem?
Without knowing the actual path/filename of the file and the fileOpen call parameters, we can only guess. If you want answers, provide information, not opinions.
 

Thank you all! every time i get this error message below: 

"File does not exist: C:\Users\pc\AppData\Roaming\MetaQuotes\Terminal\Common\Files\TradeVisualizer_XAUUSD.csv Below the snippet code with File path Firewall settings checked no problem

   
   int OnInit()
{
commonPath = TerminalInfoString(TERMINAL_COMMONDATA_PATH) + "\\Files\\";
   string file_name = commonPath + FilePrefix + Symbol() + ".csv";

   Print("=== TradeVisualizer Initialization ===");
   Print("Target file: ", file_name);

   if(!FileIsExist(file_name))
   {
      Print(" File does not exist: ", file_name);
      Print("Please ensure the CSV file is in the correct location.");
      return INIT_FAILED;
   }

   int handle = FileOpen(file_name, 
                        FILE_READ|FILE_CSV|FILE_ANSI|FILE_SHARE_READ, 
                        ','); 
   
   if(handle == INVALID_HANDLE)
   {
      int error = GetLastError();
      Print(" Cannot open file: ", file_name);
      Print("Error code: ", error, " - ", ErrorDescription(error));
      return INIT_FAILED;
   }

   Print(" File opened successfully. Size: ", FileSize(handle), " bytes");
 
Abdeljalil El Kedmiri #:  Thank you all! every time i get this error message below: 

"File does not exist: C:\Users\pc\AppData\Roaming\MetaQuotes\Terminal\Common\Files\TradeVisualizer_XAUUSD.csv Below the snippet code with File path Firewall settings checked no problem

Don't use an explicit full path with the FileOpen or FileIsExist functions. They are sandboxed, so use relative paths instead.

Also, if it is in the "Common" folder, then use the "FILE_COMMON" flag.

Please read the documentation for more details.