OnTester Capabilities

 

Hey everyone,

 I was wondering if the following is possible:

 I would like to retrieve all trade data at the end of the test in my EA code, do some statistical calculations with the trade data, and export to a text or excel file.

For instance I would like to retrieve each executed trade's profit/loss, executon price, closed price and position of order. 

Any help will be greatly appreciated! 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
Use files operations in OnDeinit()

 
Rosh:
Use files operations in OnDeinit()

Hey thanks,

That solves one part of my question.  For the second part, how do I retrieve the trade data from the tester? 

 
Saidar:

Hey thanks,

That solves one part of my question.  For the second part, how do I retrieve the trade data from the tester? 

Read data from files with flag FILE_COMMON. Don't forget to write these data with same flag.
 
Rosh:
Read data from files with flag FILE_COMMON. Don't forget to write these data with same flag.

Thanks Rosh,

 I'm not a seasoned programmer so not sure where to start with this, can you maybe give me an example?  I don't understand where the data is stored?  I know the files have the flag FILE COMMON but not sure where they are and how to read the files to retrieve the trade results.

Remember I want to retrieve the following data of each backtest:

All positions, with profit/loss, price where the order was executed, price where the order was closed, time of opening of order, time of closing of order etc etc

Afterwards I want to do some statistical calculations and save the results in .csv files 

 

Use something like this

   int file=FileOpen(fname,FILE_READ|FILE_CSV|FILE_COMMON,";");
//--- check operation result
   if(file==INVALID_HANDLE)
     {
      PrintFormat("Reading of file %s failed. Error code=%d",fname,GetLastError());
      return;
     }
   else
     {
      PrintFormat("File will be read from folder %s",TerminalInfoString(TERMINAL_COMMONDATA_PATH));
     }

 
Rosh:

Use something like this


Thanks Rosh,

I don't think you understand what I want exactly or either I don't understand you correctly

I want to retrieve the trading results after a backtest, and use those results to construct my own csv file.

My question is how and where do I get the backtest information ? 

 

Saidar:

I want to retrieve the trading results after a backtest, and use those results to construct my own csv file.

My question is how and where do I get the backtest information ? 

You mean all the statistics included in the tester report? Forget it, I have once asked about it and have been told that it is impossible to retrieve them and that I should calculate all statistical measures on my own in the OnTester(). The only solution that I see is to write a piece of code capable of extracting such information from the report.
 
Enigma71fx:
You mean all the statistics included in the tester report? Forget it, I have once asked about it and have been told that it is impossible to retrieve them and that I should calculate all statistical measures on my own in the OnTester(). The only solution that I see is to write a piece of code capable of extracting such information from the report.

I don't really need the specific data in the tester report, I need the trade information.  Open and close price of each trade executed in the backtest.

I guess I can collect this info manually while the test is running, but thought it would be easier if there already existed some sort of way to retrieve the information since the tester displays all executed order information in the test results. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 
Saidar:

I don't really need the specific data in the tester report, I need the trade information.  Open and close price of each trade executed in the backtest.

I guess I can collect this info manually while the test is running, but thought it would be easier if there already existed some sort of way to retrieve the information since the tester displays all executed order information in the test results. 

Read article Creating and Publishing of Trade Reports and SMS Notification. It might help you.
Reason: