Genetic optimization. Variable that depends on the value of another.

 
I have an EA with 2 Timeframes of 2 different indicators, both are in the input variable I want to optimize

input ENUM_TIMEFRAMES timeframeIND1 = PERIOD_M10;
input ENUM_TIMEFRAMES timeframeIND2 = PERIOD_M30;
but there is a condition:   timeframeIND1 < timeframeIND2.

Actually to get out of the way I put a condition in OnInit() that closes the EA and gives way to the next pass.

  //PROTECTION FOR TESTER
  if (timeframeIND1 >= timeframeIND2){
      ExpertRemove();
      }

 which gives me an error in the journal:

2025.03.09 16:46:03.723 Core 16 genetic pass (3, 503) tested with error “expert removed itself in OnInit function” in 0:00:00.00.008
but it still evaluates the EA with next pass. 


This solution improves the time in the test, by preventing to evaluate with those values, but it DOES NOT IMPROVE THE TOTAL EVALUATION, since the passes that closes the EA are counted with result 0.



Is there any possibility to condition the value of variable 2 in function of variable 1 in the genetic test?



As a concept, also I had thought of putting the variable timeframeIND1 and a variable varIND2 but I don't know how to implement it as they are different variables.

input ENUM_TIMEFRAMES timeframeIND1 = PERIOD_M10; // PERIOD_M10 to PERIOD_D1
input ????    varIND2 = ?? ; //times greater than timeframeIND1

timeframeIND2 = timeframeIND1 + N;    //timeframeIND1 to PERIOD_D1

 
rubengarber:
I have an EA with 2 Timeframes of 2 different indicators, both are in the input variable I want to optimize

but there is a condition:   timeframeIND1 < timeframeIND2.

Actually to get out of the way I put a condition in OnInit() that closes the EA and gives way to the next pass.

 which gives me an error in the journal:

but it still evaluates the EA with next pass. 


This solution improves the time in the test, by preventing to evaluate with those values, but it DOES NOT IMPROVE THE TOTAL EVALUATION, since the passes that closes the EA are counted with result 0.



Is there any possibility to condition the value of variable 2 in function of variable 1 in the genetic test?



As a concept, also I had thought of putting the variable timeframeIND1 and a variable varIND2 but I don't know how to implement it as they are different variables.


you can return INIT_PARAMETERS_INCORRECT if the timeframes are not the way you want them 

 
Lorentzos Roussos # :

you can return INIT_PARAMETERS_INCORRECT if the timeframes are not the way you want them 

both order 

   if timeframeIND1 >= timeframeIND2){
       return ( INIT_SUCCEEDED );

      }

who does not give any comment in the newspaper, and

   if timeframeIND1>= timeframeIND2){
       return ( INIT_PARAMETERS_INCORRECT );      
      }

which is given in the newspaper:

 2025.03 .10 12 : 59 : 28.515 Core 1   genetic pass ( 0 , 2 ) tested with error "incorrect input parameters" in 0 : 00 : 00.004

In both cases, results with 0 operations still appear (as with ExpertRemove() ).

I really want to eliminate that situation and improve the efficiency of genetic optimization by changing those "0 operations" to evaluations.

 
rubengarber #:

both order 

who does not give any comment in the newspaper, and

which is given in the newspaper:

In both cases, results with 0 operations still appear (as with ExpertRemove() ).

I really want to eliminate that situation and improve the efficiency of genetic optimization by changing those "0 operations" to evaluations.

I see , maybe you can go the custom criterion type of test and return INT_MIN for those cases as a score.

 
rubengarber:
I have an EA with 2 Timeframes of 2 different indicators, both are in the input variable I want to optimize

but there is a condition:   timeframeIND1 < timeframeIND2.

Actually to get out of the way I put a condition in OnInit() that closes the EA and gives way to the next pass.

 which gives me an error in the journal:

but it still evaluates the EA with next pass. 


This solution improves the time in the test, by preventing to evaluate with those values, but it DOES NOT IMPROVE THE TOTAL EVALUATION, since the passes that closes the EA are counted with result 0.

Is there any possibility to condition the value of variable 2 in function of variable 1 in the genetic test?

Yes, this is a known drawback of the optimization process how it's implemented in MT5.

You can find a workaround in the algotrading book.

MQL5 Book: Trading automation / Testing and optimization of Expert Advisors / Auto-tuning: ParameterGetRange and ParameterSetRange
MQL5 Book: Trading automation / Testing and optimization of Expert Advisors / Auto-tuning: ParameterGetRange and ParameterSetRange
  • www.mql5.com
In the previous section, we learned how to pass an optimization criterion to the tester. However, we missed one important point. If you look into...
 
Stanislav Korotky # :

Yes, this is a known drawback of the optimization process how it's implemented in MT5.

You can find a workaround in the algotrading book .

Just what I need, thanks.