b610 backtests and OnTester ?

 

Hi,

I just have started an optimization with: Expert properties -Testing Tab: Optimized Parameter: Custom & Genetic algorithm,

and in the EA I wrote:

double iniAcct;
int init(){
        ...
        iniAcct = AccountBalance();
        ...
}
double OnTester(){
        return( (AccountBalance()-iniAcct) ); // to start simple
}

// even this creates only zeros:
double OnTester(){
  double  prf = TesterStatistics(STAT_PROFIT),
          bdd = TesterStatistics(STAT_BALANCE_DD);
  if(bdd > 0.0)  return( prf / bdd );
  double  edd = TesterStatistics(STAT_EQUITY_DD);
  if(edd > 0.0)  return( prf / edd );
  double  bim = TesterStatistics(STAT_BALANCEMIN);
  if(bim > 0.0)  return( prf / bim );
  return(10.0);
   
} 

But all the results of the optimization is 0 (Zero) in the Optimization Graph Tab. What is wrong?

The mql4 Reference writes

OnTester

The OnTester() function is the handler of the Tester event that is automatically generated after a history testing
of an Expert Advisor on the chosen interval is over. The function must be defined with the double type, with no parameters:

double OnTester();
 

The function is called right before the call of OnDeinit() and has the same type of the return value - double. 
OnTester() can be used only in the testing of Expert Advisors. Its main purpose is to calculate a certain value 
that is used as the Custom max criterion in the genetic optimization of input parameters.

In the genetic optimization descending sorting is applied to results within one generation. I.e. from the point 
of view of the optimization criterion, the best results are those with largest values 
(for the Custom max optimization criterion values returned by the OnTester function are taken into account). 
In such a sorting, the worst values are positioned at the end and further thrown off and do not participate 
in the forming of the next generation.

BTW it is a bit confusing to write: double OnTester(); as if this were a function without any body like double AccountBalance();

But my solution OnTester(){ ..} isn't rejected by the compiler but only zeros arrive in the Optimization Graph??

Any hint how to use this - or isn't this ready yet?

Gooly

 

I guess it should look like the mql5 version: https://www.mql5.com/en/articles/286

There even the Optimization Results changes if Custom-function is used to optimize but the mt4 b610 does do it yet :(

So I guess it's not working.

 
I guess you have to wait a little for the bugs in new features to be corrected.
 

I am using MT4 and tried the OnTester() function.

It seems also that it is not used in the optimisation windows,

even if OnTester result is correctly given and output in logs at the end of a backtest.

 

Looks like the problem is when we call any function inside OnTester().

Making testing without calling functions I could generate right returns (not just zero).

 

It seems that the bugs have not been updated


I want to use RoMad for my custom optimisation and the statistics returned by MQL4 OnTester() gives readings that do not make sense, for example, initial deposit I get 0 and profit gives me a result that is not on the report.


If anyone has come across this issue and has a resolution I would be grateful for the solution 

 

I got this to work with MT4 Version 4.00 Build 1220 (September 2019) by removing any call to ANY function in OnTester() and selecting "Custom" as the Optimized Parameter on the Testing tab in the Expert Properties window.

Luckily it turns out you can access global variables from the OnTester() event handler without breaking the rules.

For example, the code in OnTester() in a bot under construction calculates the "R Squared" statistic from a linear regression applied to the P/L curve at the end of each run so the curve must be pre-constructed from from OrderProfit() values as each trade closes and the values stored in a global array.  

In the case of RoMad it should be possible to store return and maximum drawdown over the period of the return on the fly so they're available as global variables when OnTester() is called. 

Reason: