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

  }
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
A purchased licensed version allows at least 5 activations. The number of activations is specified by seller. Seller may increase the allowed number of activations
 
tradesbyjames:

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

The manual page on TesterStatistics mentions that the results are only available during OnTester() or OnDeinit(). In other words, once the test is running or has completed. You are using it during OnInit(), but at that time does it not yet have any value. So your handle_dd parameter has an undefined value.

https://www.mql5.com/en/docs/common/testerstatistics

Documentation on MQL5: Common Functions / TesterStatistics
Documentation on MQL5: Common Functions / TesterStatistics
  • www.mql5.com
Common Functions / TesterStatistics - Reference on algorithmic/automated trading language for MetaTrader 5
 
WindmillMQL:

The manual page on TesterStatistics mentions that the results are only available during OnTester() or OnDeinit(). In other words, once the test is running or has completed. You are using it during OnInit(), but at that time does it not yet have any value. So your handle_dd parameter has an undefined value.

https://www.mql5.com/en/docs/common/testerstatistics


Thanks for the insight here!
Do you/anyone know if what I am looking for is possible? With this function or maybe another one?

Stay safe!

Documentation on MQL5: Common Functions / TesterStatistics
Documentation on MQL5: Common Functions / TesterStatistics
  • www.mql5.com
Common Functions / TesterStatistics - Reference on algorithmic/automated trading language for MetaTrader 5
 
Nobody?
 
tradesbyjames:
WindmillMQL:

The manual page on TesterStatistics mentions that the results are only available during OnTester() or OnDeinit(). In other words, once the test is running or has completed. You are using it during OnInit(), but at that time does it not yet have any value. So your handle_dd parameter has an undefined value.

https://www.mql5.com/en/docs/common/testerstatistics


Thanks for the insight here!
Do you/anyone know if what I am looking for is possible? With this function or maybe another one?

Stay safe!

I think that you need to think again about when you need the drawdown data. You are now using it in OnInit(), which means before you even started any testing or trading. Do you think that you already have drawdown before the very first trade?

If you read the documentation page which I provided you can see what standard functions you'll need to include in your code if you want to use it during or after a backtest or optimization.

If you want to use it during live trading or paper trading, you may have to write your own function to calculate drawdown while trading is ongoing.

 
Anyone that could offer some more insights? What function should I work in? Ontester? 
Reason: