How to make csv file.....

 

Dear Friends,

I have made an EA  to make a sample csv file.

When I compiled it, everything okay. But I don't find the csv file anywhere, Why.

Can any one help me in this......... Thanks in advance.

Following is my complete code:


void OnTick ()
   {
   static double LasstHigh;
   static double LastLow;
      MqlRates PriceInfo[];
      ArraySetAsSeries(PriceInfo,true);
      int PriceData = CopyRates(_Symbol,_Period,0,3,PriceInfo);
      if ( (LasstHigh != PriceInfo[1].high) && (LastLow != PriceInfo[1].low))
        {
      string mySpreadsheet = " Spreadsheet.csv ";
      int mySpreadsheetHandle = FileOpen(mySpreadsheet,FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI);
      FileSeek(mySpreadsheetHandle,0,SEEK_END);
      FileWrite(mySpreadsheetHandle, "TIME DETAILS ", PriceInfo[1].time," HIGH ", PriceInfo[1].high," LOW  ", PriceInfo[1].low);
      FileClose(mySpreadsheetHandle);
      LasstHigh = PriceInfo[1].high;
      LastLow = PriceInfo[1].low;
         }
         Comment( " LAST HIGH = ", PriceInfo[1].high, " \n ",
         " LAST LOW = ", PriceInfo[1].low );
         }

     
Using spreadsheets to build trading strategies
Using spreadsheets to build trading strategies
  • www.mql5.com
The article describes the basic principles and methods that allow you to analyze any strategy using spreadsheets (Excel, Calc, Google). The obtained results are compared with MetaTrader 5 tester.
 

Is there any reason why your filename starts with a whitespace? " Spreadsheet.csv "

That may be the problem :)

 
  1. Remove the leading and trailing spaces!
  2. The file will be in the «DataFolder» subfolder. (File (Alt+F) → Open Data Folder). Either File or tester/file.
 
Plamen Zhivkov Kozhuharov #:

Is there any reason why your filename starts with a whitespace? " Spreadsheet.csv "

That may be the problem :)

Thank you Mr.Plamen Zhivkov K  for your response. But after corrected the white space also I don't find the .csv file anywhere......

 
William Roeder #:
  1. Remove the leading and trailing spaces!
  2. The file will be in the «DataFolder» subfolder. (File (Alt+F) → Open Data Folder). Either File or tester/file.

Thank you Mr.William Roeder for your response. I have removed the blank spaces. Still I don't see the .csv file anywhere.

Is there any other way to find out the solution?  Thanks.....

 
RDBS #: Thank you Mr.William Roeder for your response. I have removed the blank spaces. Still I don't see the .csv file anywhere. Is there any other way to find out the solution?  Thanks.....

Are you running the code on a live chart or in the Strategy Tester? If in the Tester, then look in the the "Tester" subfolder, as per the FileOpen() documentation:

The file is opened in the folder of the client terminal in the subfolder MQL5\files(or testing_agent_directory\MQL5\filesin case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals.

EDIT: One more thing, you are not checking your return handle if invalid (namely a file error) nor checking for error codes. How do you know the file was properly created or opened if you don't check?

Return Value: If a file has been opened successfully, the function returns the file handle, which is then used to access the file data. In case of failure returns INVALID_HANDLE.

Follow the example in the documentation so as to improve your implementation.

PS! Just to confirm, this is MT5/MQL5 you are using, right? Or is this a MT4/MQL4 issue?

Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Are you running the code on a live chart or in the Strategy Tester? If in the Tester, then look in the the "Tester" subfolder, as per the FileOpen() documentation:

EDIT: One more thing, you are not checking your return handle if invalid (namely a file error) nor checking for error codes. How do you know the file was properly created or opened if you don't check?

Follow the example in the documentation so as to improve your implementation.

PS! Just to confirm, this is MT5/MQL5 you are using, right? Or is this a MT4/MQL4 issue?

Thank you Mr.Fernando Carreiro for your response. I am trying this in MT5/MQL5. Now I tried with file error code also.It says file is opened.

But where the file is? I could not find it anywhere with all the searching ways.. Is there any file setting to be done ? Thank you in advance.

 
RDBS #: But where the file is? I could not find it anywhere with all the searching ways.. Is there any file setting to be done ? Thank you in advance.

You have already been told where it is:

... in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). 

The "live" data sub-folder can be opened from the MetaTrader terminal by pressing [Ctrl+Shift+D] or going to the menu option File → Open Data Folder. From there go to the "MQL\Files" subfolder. For the Strategy Tester, go to the "Tester\Agent-###.###.###.###-####\MQL5\Files".

Also you did not answer the question: Is this on a live chart or in the Strategy Tester?

Please note also, that in your code, you are not detecting for a new bar condition an so, you may be creating the file on every tick.

 
Fernando Carreiro #:

You have already been told where it is:

The "live" data sub-folder can be opened from the MetaTrader terminal by pressing [Ctrl+Shift+D] or going to the menu option File → Open Data Folder. From there go to the "MQL\Files" subfolder. For the Strategy Tester, go to the "Tester\Agent-###.###.###.###-####\MQL5\Files".

Also you did not answer the question: Is this on a live chart or in the Strategy Tester?

Please note also, that in your code, you are not detecting for a new bar condition an so, you may be creating the file on every tick.

Thanks a lot Mr.Fernando Carreiro for your correct response. Now I found the .csv file. Once again thanks a lot.

 
RDBS #: Thanks a lot Mr.Fernando Carreiro for your correct response. Now I found the .csv file. Once again thanks a lot.

We have been telling you where to find it from the beginning, but you did not pay attention.

  • William Post #2: "The file will be in the «DataFolder» subfolder. (File (Alt+F) → Open Data Folder). Either File or tester/file."
  • Me Post #5/#7: "... in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing)."
How to make csv file.....
How to make csv file.....
  • 2022.03.12
  • www.mql5.com
Dear Friends, I have made an EA to make a sample csv file. When I compiled it, everything okay. But I don't find the csv file anywhere, Why...
Reason: