Strategy validation (min number of trades)

Avatar
  • updated
  • Completed

I hope everything is alright. I have a specific request for optimizing our strategy in MetaTrader 5. I would like to introduce a minimum sampling filter or a minimum number of trades filter. What does this mean? I want to ensure that optimized strategies are validated by a sufficient number of trades for the results to be considered statistically significant. In other words, avoid a strategy with just one or two operations (with 100% accuracy) being considered valid, as this may simply be a coincidence and not an indication of a truly effective strategy. How should it be implemented? input variable to the EA to set the minimum number of trades.During the backtest process, check the total number of trades using OrdersTotal().Penalize or discard strategies that do not meet the minimum trades criteria.Why is this important?Robustness: Ensures that the strategy is tested in various market conditions and not just specific situations. Reliability: Reduces the risk of overfitting by ensuring that we are not just picking up statistical anomalies. Consistency: Ensures that the strategy has a solid foundation and is not simply a "lucky break".I am confident that the introduction of this filter will allow us to obtain more reliable and robust optimization results. Thank you in advance for your attention and implementation of this feature. Please let me know if you need further details or clarification. Thanks and regards,

Avatar
0
Ulises Cune

Image 5156

You can obtain the value of trades at the end of the backtesting in the "backtest" tab "interactively" and/or you can obtain it "automatically" if you export the result as HTML using the "terminal.exe" command line, and obtain the result, if it does not meet the number of trades you need, discard the result.

https://www.metatrader5.com/en/terminal/help/start_advanced/start

Avatar
0
Ulises Cune

https://www.mql5.com/en/blogs/post/725257

Here you have how to transform the optimization XML file into a table and be able to take only the values that have trades higher than what you need.

Avatar
1
Andrey Khatimlianskyi
  • Under review

Discussion started here -- https://t.me/CommunityPowerEA/79148

We can add a "Min trades per year" parameter and filter out results with low number of trades. 

Results with low number of trades will have 0 score, so genetic algorithm will continue with different parameters.

We can also multiply score by some coefficient based on number of trades, it will also lead to better number of trades in the next generations. For example, 100 trades per year and more will have coefficient equal to 1, and 10 trades per year and less will have coefficient 0.1.


----------

Let’s say we just finished optimization and got R2 in a range from 0.5 to 0.9. And a new ‘deals_number_coefficient’ from 0.1 to 1.0.

Now we can multiply each R2 with corresponding deals_number_coefficient.

For example, if we have R2 0.9 with only 10 trades per year (0.1 coeff), we will have 0.9 * 0.1 = 0.09 final score.

For set with R2 = 0.8 and 55 trades per year (0.5 coeff) it will be 0.4.

The only question is how to define the right ranges for this deals_number_coefficient. It probably shouldn’t be linear..

I wouldn’t choose R2 0.5 with deals_number_coefficient = 1 (100 trades per year) with final score = 0.5 * 1 = 0.5. I’d prefer R2 0.8 with 55 trades per year. What do you think?

Avatar
1

Yes, exactly the discussion started within a Telegram group, so I decided to formalize it through a post

Avatar
0
Giamma

Ciao Gabriel! Have you considered the possibility of optimizing by utilizing a loop that start with the complex criterion initially and finish with a manual selection of the best results, with which you can reinitiate the loop? The complex criterion, which considers factors like the number of deals, drawdown, recovery factor, expected payoff, and Sharpe Ratio, can offer valuable insights and adress robustness, as it is multidimensional and dynamic. I use this approch and it works pretty well. Just a thought to consider! ^_^

Avatar
0

In practice we don't know if this really works like this, the idea is really something brilliant, you know, to bring the reliability of the strategy to manual selection after it's ready, we all have personal techniques to do it but genetic selection during optimization is something that is in question here

Avatar
0
Giamma
Quote from gabriel decsters (Opçoês Desco

In practice we don't know if this really works like this, the idea is really something brilliant, you know, to bring the reliability of the strategy to manual selection after it's ready, we all have personal techniques to do it but genetic selection during optimization is something that is in question here

Yes, I believe it works in that way. When keeping optimization possibilities to a reasonable number (under circa 10k), genetic selection with C.C. proved to be an effective approach. However, Andrey's trades filter will undoubtedly prove invaluable for more extensive optimization tasks. A warm welcome to this feature! ^^

Avatar
0
Andrey Khatimlianskyi
  • Started
Avatar
3
Andrey Khatimlianskyi
  • Completed

It is done in 2.55.8.

Will publish it soon with the updated documentation.

Avatar
0
mel

Yes, this is part of the problem I am also having where it'll optimize to a high R2 but trades are open for weeks or months thus causing a low number of trades executed. It won't exactly solve this problem but it'll help to mitigate it. I can't wait to run it and see.