how to use the function:double TesterStatistics(ENUM_STATISTICS statistics_value)?

 

MetaTrader 5 Client Terminal build 430 

 10. MQL5: Added the TesterStatistics function for getting the data of the calculated statistics after testing. The function can be called inside OnTester and OnDeinit.

 double TesterStatistics(ENUM_STATISTICS statistics_value);

I didn't find any  interpretation about this function how to use in the MQL5 help file,what is the ENUM_STATISTICS ?

 
We are adding this information into documentation on Monday. Sorry.
 
The TesterStatistics function has been added in the MQL5 Documentation.
 
Rosh:
The TesterStatistics function has been added in the MQL5 Documentation.

Hi Rosh,

Is it working also during Optimization process or only when optimization is disabled?

Regards,

Olivier 

 

According to text:

Note

The function can be called inside OnTester() or OnDeinit() in the tester. In other cases the result is undefined.

Try yourself, please.


 
Rosh:

According to text:

Try yourself, please.


Hi Rosh,

I did. I tried the following code in both OnTester() and OnDeInit(), nothing happen : 

void OnTester()

{

  int m_filehandle;

  string Stat_Log;

  

  Stat_Log = DoubleToString(TesterStatistics(STAT_DEALS),0) + "," + DoubleToString(TesterStatistics(STAT_PROFIT),2);

  m_filehandle = FileOpen("Stats_Log.log",FILE_WRITE|FILE_CSV);

  if(m_filehandle!=INVALID_HANDLE)

     {

      FileWrite(m_filehandle,Stat_Log);

      FileClose(m_filehandle);

     }

}

I tried during optimization process enable.

Regards,

Olivier 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties - Documentation on MQL5
 
och:

void OnTester()

{

}

Congratulations!

Why did you write the void type instead of the double one as it must be?

double OnTester()
  {
   return(TesterStatistics(STAT_DEALS));
  }
 
Rosh:

Congratulations!

Why did you write the void type instead of the double one as it must be?

OK indeed I made a mistake, using double instead of void, it does generate a file. I undestood I made a mistake. Thanks for your congratulations.

Can you please explain how does it works when we are using optimization (slow or fast). Is OnTester() run only once. I have only one line in two generated files (one by agent). I am asking if we can use TesterStatistics() to generate the cache file you used to save in (tester\cache) before 430 build.

Regards,

 

Firstly, insert code properly, please.


Secondly, you should read about File Opening Flags:

One or several flags can be specified when opening a file. This is a combination of flags. The combination of flags is written using the sign of logical OR (|), which is positioned between enumerated flags. For example, to open a file in CSV format for reading and writing at the same time, specify the combination FILE_READ|FILE_WRITE|FILE_CSV.

Example:

   int filehandle=FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV);

There are some specific features of work when you specify read and write flags:

  • If FILE_READ is specified, an attempt is made to open an existing file. If a file does not exist, file opening fails, a new file is not created.
  • FILE_READ|FILE_WRITE – a new file is created if the file with the specified name does not exist.
  • FILE_WRITE –  the file is created again with a zero size.
See also example for the FileOpen() function.
 
Rosh:

Firstly, insert code properly, please.


Secondly, you should read about File Opening Flags:

See also example for the FileOpen() function.

OK so I read your comment and will try to follow your instruction to insert MQL code.

I add the FILE_READ option to my code  : I even add a counter passcount is a global variable but is not increasing.

double OnTester()
{
  string Stat_Log;
  m_filehandle = FileOpen("Stats_Log.log",FILE_WRITE|FILE_READ|FILE_CSV);
  Stat_Log = DoubleToString(TesterStatistics(STAT_DEALS),0) + "," + 
             DoubleToString(TesterStatistics(STAT_PROFIT),2) + " " +
             IntegerToString(m_dema_timeframe) + " " + 
             IntegerToString(passcount);
  if(m_filehandle!=INVALID_HANDLE)
     {
      FileWrite(m_filehandle,Stat_Log);
      FileClose(m_filehandle);
     }
  passcount++;   
  return(0);
}

Maybe, you can just answer the questions :

1. What happen with TesterStatistics or OnTester() event when we are using Optimization Mode (Slow or fast)? How does it works?

2. You decided not to  generate xml file in tester\cache folder or at least not to include lines if process is less that 1 second. I can undestand, but the test I am conducting let appears that I am not able anymore to have xml result file in cache folder. What sould I do to have this file generated as in 425 build? I opened a service desk and have been told to add some heavy calculation in OnTester() even to have each pass during more than 1 second, but even in adding a sleep(1010) does not help me to generate an xml file. I have been told that you decided to reduce the time level https://www.mql5.com/servicedesk/view/77635?p_comment_id=191284#comment_191284 to 250ms in which release and when?

Regards,

Olivier 

 
och:

OK so I read your comment and will try to follow your instruction to insert MQL code.

I add the FILE_READ option to my code 


You must use function FileSeek() if you want time from time to add new records in existing file:

double OnTester()
{
  string Stat_Log;
  m_filehandle = FileOpen("Stats_Log.log",FILE_WRITE|FILE_READ|FILE_CSV);
  Stat_Log = DoubleToString(TesterStatistics(STAT_DEALS),0) + "," + 
             DoubleToString(TesterStatistics(STAT_PROFIT),2) + " " +
             IntegerToString(m_dema_timeframe) + " " + 
             IntegerToString(passcount);
  if(m_filehandle!=INVALID_HANDLE)
     {
      FileSeek(m_filehandle,0,SEEK_END);
      FileWrite(m_filehandle,Stat_Log);
      FileClose(m_filehandle);
     }
  passcount++;   
  return(0);
}