With much experimenting, I have come to similar conclusions. I don't know why it took me so long to find this article and discussion.
I started with a problem where my break out and trend riding strategies tended to fit themselves to a few super profitable trades. So much profit from these few that the optimizer only "cared" about these few trades and used wide stops and far away take profit and making sure its signal caught and milked these few trades to the maximum. this occurred even on 20 year samples with 100's of trades. Even when optimizing with a dd to profit ratio, it still went after the runs with these trades at all costs cause the runs were 90% of its profit. I wanted to limit this behavior in some way without cutting the head off of the breakout/trend ride strat. I found that optimizing for relative dd percent (NOT dd ratio to profit, just dd relative percent only and nothing much else) gives good results going forward as long as minimum trades and minimum profit factor (about 1.3) are met.
//............... sinputdouble mint; //minimum trades for optimization purposes. Will impose a penalty on runs with fewer trades. sinputdouble minpf; //minimum profit factor for optimization purposes. Will impose a penalty on runs with less pf.//...............doubleOnTester()
{
double dd=TesterStatistics(STAT_BALANCE_DDREL_PERCENT);//equity instead of balance also worked well going forwarddouble pf=TesterStatistics(STAT_PROFIT_FACTOR);
int tt=TesterStatistics(STAT_TRADES);
double custom=(100-dd);
if (mint>t) custom=custom*(tt/mint); // imposes a penalty if minimum trades not metif (minpf>minpf) custom=custom*((pf-1)/(minpf-1)) // this line also causes losing runs to be negative as well as imposing a penalty lesser pf.return(custom);
}
It seems wrong to not have profit involved but by having a pf minimum criteria, mostly quite profitable runs are appearing at the top. Cropping out dd from profitable runs is usually increasing profits. In any case, by selecting the more profitable trades and doing the final touch-ups carefully manually by hand (such as near the end of this excellent article https://www.mql5.com/en/articles/156), I can allow the optimizer to do a lot of the initial work while avoiding a lot of curve fitting. Ive experimented and had mixed results with code such as the following. (Experiments should include changing risk and starting balance too once you begin put additional weights in on top of a percent based score)
This article explains the step by step process of identifying and resolving code errors as well as the steps in testing and optimizing of the Expert Advisor input parameters. You will learn how to use Strategy Tester of MetaTrader 5 client terminal to find the best symbol and set of input parameters for your Expert Advisor.
Can anyone tell me if this article will be applicable for MT4? It seems that it has already adopted many properties from MT5.
In general, my task is to get just the values of LR Correlation and LR Standard Error in the MT4 tester, as it can be easily seen in the MT5 tester.
I just want to read these values in the deinit() function at the end of the test run and write them to a file together with the value of the optimised parameter.
Maybe someone has already done such things and will share with me the ready result (the necessary function for calculating LR Correlation and LR Standard Error values) so that I don't have to reinvent the wheel?
Can anyone tell me if this article will be applicable for MT4? It seems that it has already adopted many properties from MT5.
In general, my task is to get just the values of LR Correlation and LR Standard Error in the MT4 tester, as it can be easily seen in the MT5 tester.
I just want to read these values in the deinit() function at the end of the test run and write them to a file together with the value of the optimised parameter.
Maybe someone has already done such things and will share with me the ready result (the necessary function for calculating LR Correlation and LR Standard Error values) so that I don't have to reinvent the wheel?
An example of calculating LR Correlation and LR Standard Error on trades in history is available in AlgLib (MQL4\Scripts\Alglib\UseAlglib.mq4).
Automated-Trading: An example of calculating LR Correlation and LR Standard Error for trades in history is available in AlgLib (MQL4\Scripts\Alglib\UseAlglib.mq4).
There are simply no orders with type 6 in the tester.
That is, when running in the MT4 tester and using the code from UseAlglib.mq4, which is included in the downloaded zip file, through a call from the deinit() function.
balance remains equal to 0. And then the error"Trading operations with zero balance" is printed.
I had to simply insert the necessary value of the initial balance in the MT4 tester into the code itself and then everything was counted perfectly.
Perhaps the developers can take this point into account in future versions of the library.
Well, here I am again, the lone wolf in this universe :-)
I have been trying the straightness Custom Criteria trying to get the slope of the calculated straight line into the equation. As is it can give you a very hgh rating on a very feeble profit. Just adding the end profit
into the caculation does not make it any better In an attempt to add the actual slope into the equation I changed the code lilke seen below.
It is not a perfect solution but it is closer to what I want to see. Using result together wit balance or profit works fine for me with this code
I know it's been so long since you posted this but in case you are still playing with this or someone else are looking for the same straightness criteria implementation.
An underrated feature of Metatrader’s Backtester is its ability to define a custom fitness function for the genetic optimization process. Meaning that you no longer are limited to rather simple metrics like final balance or profit factor but can evaluate the quality of each test run with your own individual calculations. To give a quick...
The relating tutorial has too much info, such as specifically about programming an EA, which is in other tutorial, and non-applicable to average punter, who, will buy their EA and has minimal programming ability.
I find, that by default, the only useful criterions for MT5 in genetic algo is the "balance max", then have to repeat that a few times, and fish through results til find low drawdown, as for use on multiple pairs.
What criterions I need :- Max balance with <20 Drawdown, MaxBalance with <10 Drawdown
To all you 'lone wolves' out there: you're on the right track, creating rigorous testing criteria and the automation of the same. There are of course several different ways of looking at the same challenge, and reading the comments herein, the consensus seems to be on a trade-off between balance, drawdown, RRR and some measure of profit (profit factor, Kelly Criterion, etc). I came to this article attempting to do the same, and wanting the Strategy Tester to do it for me; glad I'm not alone :)
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
With much experimenting, I have come to similar conclusions. I don't know why it took me so long to find this article and discussion.
I started with a problem where my break out and trend riding strategies tended to fit themselves to a few super profitable trades. So much profit from these few that the optimizer only "cared" about these few trades and used wide stops and far away take profit and making sure its signal caught and milked these few trades to the maximum. this occurred even on 20 year samples with 100's of trades. Even when optimizing with a dd to profit ratio, it still went after the runs with these trades at all costs cause the runs were 90% of its profit. I wanted to limit this behavior in some way without cutting the head off of the breakout/trend ride strat. I found that optimizing for relative dd percent (NOT dd ratio to profit, just dd relative percent only and nothing much else) gives good results going forward as long as minimum trades and minimum profit factor (about 1.3) are met.
It seems wrong to not have profit involved but by having a pf minimum criteria, mostly quite profitable runs are appearing at the top. Cropping out dd from profitable runs is usually increasing profits. In any case, by selecting the more profitable trades and doing the final touch-ups carefully manually by hand (such as near the end of this excellent article https://www.mql5.com/en/articles/156), I can allow the optimizer to do a lot of the initial work while avoiding a lot of curve fitting. Ive experimented and had mixed results with code such as the following. (Experiments should include changing risk and starting balance too once you begin put additional weights in on top of a percent based score)
Can anyone tell me if this article will be applicable for MT4? It seems that it has already adopted many properties from MT5.
In general, my task is to get just the values of LR Correlation and LR Standard Error in the MT4 tester, as it can be easily seen in the MT5 tester.
I just want to read these values in the deinit() function at the end of the test run and write them to a file together with the value of the optimised parameter.
Maybe someone has already done such things and will share with me the ready result (the necessary function for calculating LR Correlation and LR Standard Error values) so that I don't have to reinvent the wheel?
Can anyone tell me if this article will be applicable for MT4? It seems that it has already adopted many properties from MT5.
In general, my task is to get just the values of LR Correlation and LR Standard Error in the MT4 tester, as it can be easily seen in the MT5 tester.
I just want to read these values in the deinit() function at the end of the test run and write them to a file together with the value of the optimised parameter.
Maybe someone has already done such things and will share with me the ready result (the necessary function for calculating LR Correlation and LR Standard Error values) so that I don't have to reinvent the wheel?
An example of calculating LR Correlation and LR Standard Error for trades in history is available in AlgLib (MQL4\Scripts\Alglib\UseAlglib.mq4).
Thank you! I'll look into it.
I got it. The correlation seems to be calculated.
The only thing I had to think about is the fact that this point does not work in the MT4 Build 670 tester:
There are simply no orders with type 6 in the tester.
That is, when running in the MT4 tester and using the code from UseAlglib.mq4, which is included in the downloaded zip file, through a call from the deinit() function.
balance remains equal to 0. And then the error"Trading operations with zero balance" is printed.
I had to simply insert the necessary value of the initial balance in the MT4 tester into the code itself and then everything was counted perfectly.
Perhaps the developers can take this point into account in future versions of the library.
I have tested Kelly Criterion (Strategy), using the following code:
I am not sure if Metatrader Strategy Tester computes 0 (zero) profit trades as profit trades. Anyone?
Well, here I am again, the lone wolf in this universe :-)
I have been trying the straightness Custom Criteria trying to get the slope of the calculated straight line into the equation. As is it can give you a very hgh rating on a very feeble profit. Just adding the end profit
into the caculation does not make it any better In an attempt to add the actual slope into the equation I changed the code lilke seen below.
It is not a perfect solution but it is closer to what I want to see. Using result together wit balance or profit works fine for me with this code
I know it's been so long since you posted this but in case you are still playing with this or someone else are looking for the same straightness criteria implementation.
I found a working public solution here https://community.darwinex.com/t/equity-curve-straigthness-optimization-with-metatrader/3976
The relating tutorial has too much info, such as specifically about programming an EA, which is in other tutorial, and non-applicable to average punter, who, will buy their EA and has minimal programming ability.
I find, that by default, the only useful criterions for MT5 in genetic algo is the "balance max", then have to repeat that a few times, and fish through results til find low drawdown, as for use on multiple pairs.
What criterions I need :- Max balance with <20 Drawdown, MaxBalance with <10 Drawdown
To all you 'lone wolves' out there: you're on the right track, creating rigorous testing criteria and the automation of the same. There are of course several different ways of looking at the same challenge, and reading the comments herein, the consensus seems to be on a trade-off between balance, drawdown, RRR and some measure of profit (profit factor, Kelly Criterion, etc).
I came to this article attempting to do the same, and wanting the Strategy Tester to do it for me; glad I'm not alone :)