OnInit - Controlling Optimization/Tester with Criteria Problem

 

Hi,

I would like to control the optimizer/strategy tester so it does not generate insane/crazy stop loss to take profit variations for when i select these for optimization (eg. stop loss of 100 and a take profit of 500). This is the code below that I have now in OnInit - any ideas? The optimization sometimes cuts out and does not even complete 1 min of testing with such code


int OnInit()
  {   
   
   if (Symb_StopLoss1 > Symb_TakeProfit1 * 1.4 || Symb_TakeProfit1 > Symb_StopLoss1 * 1.4)
   {
      return(INIT_FAILED); 
   }

   trade.SetExpertMagicNumber(InpMagic);
   Symb_handle_bb= iCustom(Symb_Symbol,_Period,"BB",Symb_BandsPeriod,Symb_BandsShift,Symb_BandsDeviations);
   
//---
   return(INIT_SUCCEEDED);
  }


Thanks.

Extract profit down to the last pip
Extract profit down to the last pip
  • www.mql5.com
The article describes an attempt to combine theory with practice in the algorithmic trading field. Most of discussions concerning the creation of Trading Systems is connected with the use of historic bars and various indicators applied thereon. This is the most well covered field and thus we will not consider it. Bars represent a very artificial entity; therefore we will work with something closer to proto-data, namely the price ticks.
 
in the input tab, change STOP value to whatever you think is not insane/crazy XD, then the Optimizer won't exceed that value
 
_MAHA_ #:
in the input tab, change STOP value to whatever you think is not insane/crazy XD, then the Optimizer won't exceed that value

Thanks - any suggestion as to how I could set the stop loss to be not more than 1.4 times of the take profit? The only other way that I can think of is to have a while loop set to on under ontick for every bar and then if the stop is bad, set it to off so it exits the EA

 
v88: I would like to control the optimizer/strategy tester so it does not generate insane/crazy stop loss to take profit variations for when i select these for optimization (eg. stop loss of 100 and a take profit of 500). This is the code below that I have now in OnInit - any ideas? The optimization sometimes cuts out and does not even complete 1 min of testing with such code

When the supplied inputs, are invalid according to your criteria or need, use the "INIT_PARAMETERS_INCORRECT" return code instead of "INIT_FAILED".

 
Fernando Carreiro #:

When the supplied inputs, are invalid according to your criteria or need, use the "INIT_PARAMETERS_INCORRECT" return code instead of "INIT_FAILED".

Thanks for this - I have a number of criteria in if-else statements within OnInit and I changed this to " INIT_PARAMETERS_INCORRECT" . The strategy then just cuts out after about 1 min, where I only see one result. Any ideas?

 
v88 #: Thanks for this - I have a number of criteria in if-else statements within OnInit and I changed this to " INIT_PARAMETERS_INCORRECT" . The strategy then just cuts out after about 1 min, where I only see one result. Any ideas?

Please explain in more details and show some screenshots.

Also, remember that if you are setting your inputs wildly without any concern for the inputs that you wish, then most of the passes will fail and the final optimisations will be very few.

Also make sure that you enable to view ALL results without filters so that you can see them even if they are not of interest to you.

Reason: