Download MetaTrader 5
To add comments, please log in or register
Freelance service: the safe way to order a trading robot. Try it!
Franco
374
Franco 2011.03.04 13:27 

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
Rashid Umarov
Admin
11706
Rashid Umarov 2011.03.04 14:43  
Use files operations in OnDeinit()

Franco
374
Franco 2011.03.04 14:50  
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? 

Rashid Umarov
Admin
11706
Rashid Umarov 2011.03.04 19:20  
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.
Franco
374
Franco 2011.03.06 10:10  
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 

Rashid Umarov
Admin
11706
Rashid Umarov 2011.03.07 13:21  

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));
     }

Franco
374
Franco 2011.03.07 19:04  
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 ? 

Pawel Wojnarowski
685
Pawel Wojnarowski 2011.03.07 19:12  

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.
Franco
374
Franco 2011.03.07 19:30  
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
Rashid Umarov
Admin
11706
Rashid Umarov 2011.03.08 11:02  
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.
/
To add comments, please log in or register