write file in tester mql5

 

i want create a file from candle information in strategy tester

But my code does not create the file

this is my code :

void OnTick()
  {
  
         if(iVolume(Symbol(),PERIOD_CURRENT,0) <= 1)
         { 
            string file_name= "DATA.csv";
            int file_handle = -1;
            file_handle=FileOpen(file_name,FILE_WRITE|FILE_READ|FILE_CSV|FILE_SHARE_READ|FILE_ACCESS_DATE|FILE_IS_WRITABLE|FILE_IS_READABLE);
            if(file_handle==INVALID_HANDLE)
               Print("Error opening rep-file: "+file_name);
         //---
            FileSeek(file_handle,0,SEEK_END);
            FileWrite(file_handle,TimeToString(iTime(Symbol(),PERIOD_CURRENT,1)),
            DoubleToString(iOpen(Symbol(),PERIOD_CURRENT,1)),DoubleToString(iHigh(Symbol(),PERIOD_CURRENT,1)),DoubleToString(iLow(Symbol(),PERIOD_CURRENT,1)),DoubleToString(iClose(Symbol(),PERIOD_CURRENT,1)));
            FileFlush(file_handle);
            FileClose(file_handle);
            
         
         
         }
   
  }
 

the file is not generated? or is it generated with incorrect information?

try to add FILE_ANSI to FileOpen command.

 
FXreedom:

the file is not generated? or is it generated with incorrect information?

try to add FILE_ANSI to FileOpen command.

It works well on live charts

but when i run it on strategy tester The file not be generated

 
ms239: It works well on live chartsbut when i run it on strategy tester The file not be generated
Look in the correct place. Live: <data folder>\MQL4\Files. Tester: <data folder>\tester\Files.
          Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 17.02.2014
 
whroeder1:
Look in the correct place. Live: <data folder>\MQL4\Files. Tester: <data folder>\tester\Files.
          Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 17.02.2014

when i run it on live chart the file be generated in this folder(MQL5\Files)

but when i run it on strategy tester The file not be generated  in this folder (tester\Files) Or in any other folder

Can you tell exactly what i must add to the code till works on the tester?

 
ms239:

when i run it on live chart the file be generated in this folder(MQL5\Files)

but when i run it on strategy tester The file not be generated  in this folder (tester\Files) Or in any other folder

Can you tell exactly what i must add to the code till works on the tester?

I have the same issue 
 
I am having the same problem.

I converted an indicator from MT4 to MT5, when I run it in strategy tester in MT4, the indicator generates a .csv file that is saved in tester\files (in MT4)

In MT5 there is no "files" folder inside the tester folder. But if you load the indicator in a live chart, it saves in MQL5\Files.

Where is the file being saved in MT5 when running in strategy tester?
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 

I discovered the folder path


C:\Users\(Your PC)\AppData\Roaming\MetaQuotes\Tester\ Agent

 
Anthony Eric Gillon Dawson:

I have the same problem but for reading in a file rather than writing it out during EA initialization in strategy tester. All works fine when running live but when using the ST file not found.

If I put the file in  C:\Users\(Your PC)\AppData\Roaming\MetaQuotes\Tester\Agent  the first thing the agent does on running is clear the directory of any files so this doesn't resolve my problem unfortunately.

Did anyone find a solution?

If you want to read it upon start-up then use the "Common" area as you never know which agent will be used for the testing. Use the "FILE_COMMON" flag (location of the file in a shared folder for all client terminals \Terminal\Common\Files). Please also read the comment on your original thread as well.
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
Reason: