Download MetaTrader 5
To add comments, please log in or register
Interested in MQL5 features? Find them in documentation!
Carl Schreiber
5939
Carl Schreiber 2014.02.17 13:59 

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

Carl Schreiber
5939
Carl Schreiber 2014.02.17 15:50  

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.

Alain Verleyen
Moderator
28550
Alain Verleyen 2014.02.17 17:49  
I guess you have to wait a little for the bugs in new features to be corrected.
kariboo92
49
kariboo92 2014.02.20 12:16  

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.

Rogerio Figurelli
Moderator
36127
Rogerio Figurelli 2014.03.07 03:22  

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).

/
To add comments, please log in or register