Set input for Max DD in optimization run?

 

Dear all,


In MT4 we were able to hard set for example a max of 10% equity DD for the optimization process.

In MT5 they do not have a direct feature for this so I was figuring out how to code it.

Right now I have been using the following code but getting an error.

"Genetic pass 0,506) tested with error " incorrect input parameters" in 0:00:00.000"

Once the INIT PARAMETERS INCORRECT has been triggered the entire optimization directly stops in the first 5 seconds.

Why does the optimization not continue? Is there a way so I can set as an input the max drawdown I would like to realize?

Help is greatly appreciated <3

input double               maxdd=0.1;
-------------------------------------------



int OnInit(){
handle_dd= TesterStatistics(STAT_EQUITYDD_PERCENT);

 
 
 if (handle_dd >  maxdd) return(INIT_PARAMETERS_INCORRECT);


      return(INIT_SUCCEEDED);

  }
 
To code it, you should be measuring the Drawdown inside the ontick function... and if it reaches your max, then you can use ExpertRemove()... this will stop the current backtest run ad take the optimizer to the next run... optionally, before using expert remove, check that you are in a testing enviroment, rather than a production enviroment, to prevent EAremoval on production enviroment.
Reason: