DislikedHi, i would like to know if it is possible to export a csv file that is created after a backtest. I have been told that it is only possible to create a csv file on live chart, but not in backtest. Is there someone that could confirm this? Thanks!Ignored
You don't mention which platform.
I have done this on MT5.
You can export data to CSV during a backtest.
Just in case you are referring to MT5, here is the code block:
Notes:
1: It is the "FileWrite" section that will be most relevant to you; (I Have just copied what I do, you will have your own variables to export)
2: Its just looking for a specific filename, writing to it, by appending to existing file, then closing it.
3: The PrintFormt bits can be ignored, as I just used them as markers to see what was happening during the process of testing.
4: If you wanted MT4, I dont thnk I have any examples anymore, as I have migrated over to mT5.
5: Use the MT Help documentation to lift worked examples out and play with them.
Hope the bits below help.
Good luck!
(need to define variables at top of code, name your file whatever you want)
string InpFileName = "testfile001";
string InpDirectoryName;
//--- outout bar data
//--- open the file for writing the indicator values (if the file is absent, it will be created automatically)
ResetLastError();
int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);
if(file_handle!=INVALID_HANDLE)
{
PrintFormat("%s file is available for writing",InpFileName);
PrintFormat("File path: %s\\Files",TerminalInfoString(TERMINAL_DATA_PATH));
//--- first, write the number of signals
// FileWrite(file_handle,"111");
//--- write the time and values of signals to the file
// for(int i=0;i<sign_size;i++)
FileSeek(file_handle,0,SEEK_END);
FileWrite(file_handle,_Symbol,_Period,rt[0].time,rt[0].open,rt[0].close,ma[0], Stochs[0]);
FileFlush(file_handle);
FileClose(file_handle);
PrintFormat("Data is written, %s file is closed",InpDirectoryName, InpFileName);
}
else
PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());