Backtesting - early quiting of agents' run.

 

While performing optimization of input parameters via backtesting feature in metatrader 5, I wish to use some condition to stop the agents run of a particular combination of input parameter early.

On reaching a certain condition while the agent is performing one such run, i wish to quit that run early if certain condition is met. By "quit" I don't mean stop trading (as it will still continue to process rest of the chart period which consumes time), I mean that run should stop altogether and some other parameter combination run should begin.

For example: 

For all my input parameters by using fast genetic algorithm, suppose the optimizer shows me that there are 1000000 runs that need to be executed. 

Many runs will end up in losses , many in profits. When my loss exceeds a certain threshold I wish to stop that run immediately instead of it continuing to execute on the remaining time period left. 
This should help me eliminate those useless parameter combinations with large drawdowns as well as reduce the optimization time taken as those runs will be quit early.

How can this be achieved? 
I could not find many topics related to this online.

 
 MT5 Tester built-in genetic algorithm does exactly that (terminates optimization run early, without need for any additional coding).
 
Oleksandr Medviediev #:
 MT5 Tester built-in genetic algorithm does exactly that (terminates optimization run early, without need for any additional coding).
I think you misunderstood my question.
To further clarify and elaborate .
Lets say each pass of EA over timeperiod of 1 year takes 5 mins each. 
Genetic algorithm saves time in backtesting by  reducing the number of passes , by avoiding exploring all possible combinations of inputs based on some logic.

What i am looking for is a way to reduce the time in exploring a single pass itself. 
Correct me if i am wrong but if genetic algorithm explores 10000 passes and while running each pass over period of 1 year data takes 5 minutes each then total time will be 50000 minutes. 

I want to cut that time down by stopping the pass while its executing, when it EA realises that it has violated a certain condition like max drawdown or max loss etc.

Is that something thats possible?

If genetic algorithm does terminate optimization run early, then on what basis does it do that?
And can i make it cut the run early based on custom criterea?
 

Hmm.. unfortunately, built-in genetic optimization does not provide a way to customize the early pass termination criteria based on user-defined conditions like max drawdown or max loss.

Built-in algorithm uses its own internal fitness functions and criteria to determine when to terminate an optimization run.

Must admit, genetic algorithm never takes longer than few hours (max number of optimized parameters 16) for 3-5yrs on 1minute OHLC, on decent hardware. 

 
Oleksandr Medviediev #:

Hmm.. unfortunately, built-in genetic optimization does not provide a way to customize the early pass termination criteria based on user-defined conditions like max drawdown or max loss.

Built-in algorithm uses its own internal fitness functions and criteria to determine when to terminate an optimization run.

Must admit, genetic algorithm never takes longer than few hours (max number of optimized parameters 16) for 3-5yrs on 1minute OHLC, on decent hardware. 

Well for me backtest shows 113 hours (on personal laptop using 6 cores) and i am still adding more features to EA which adds more inputs to explore and see if they help optimise the EA. Therefore I am trying to see how i can save time in any way possible.

 
Oleksandr Medviediev #:

Hmm.. unfortunately, built-in genetic optimization does not provide a way to customize the early pass termination criteria based on user-defined conditions like max drawdown or max loss.

Built-in algorithm uses its own internal fitness functions and criteria to determine when to terminate an optimization run.

Must admit, genetic algorithm never takes longer than few hours (max number of optimized parameters 16) for 3-5yrs on 1minute OHLC, on decent hardware. 

what if, i throw an error if max dd or max loss exceeds certain value, will that prematurely exit those passes and save time as a result?
 
Varun Maithani #:
what if, i throw an error if max dd or max loss exceeds certain value, will that prematurely exit those passes and save time as a result?

This is VALID approach, just add max dd as variable.

NOTE: MT5 termination criteria is sufficient already. Focus on your strategy, not logistics.

 
Varun Maithani:

Many runs will end up in losses , many in profits. When my loss exceeds a certain threshold I wish to stop that run immediately instead of it continuing to execute on the remaining time period left. 

This should help me eliminate those useless parameter combinations with large drawdowns as well as reduce the optimization time taken as those runs will be quit early.

How can this be achieved? 

MQL5 Book: Trading automation / Testing and optimization of Expert Advisors / Forced test stop: TesterStop
MQL5 Book: Trading automation / Testing and optimization of Expert Advisors / Forced test stop: TesterStop
  • www.mql5.com
If necessary, depending on the conditions observed, the developer can stop testing the Expert Advisor earlier. For example, this can be done when a...
 
Awesome thanks 
Reason: