Enable "custom" optimized parameter in the tester properties.
Add something like the following code into your EA:
{
return TesterStatistics(STAT_PROFIT) / TesterStatistics(STAT_EQUITY_DD);
}
Please note that this is just a draft - you should choose/substitute the proper statistics constants according to your needs and handle possible errors (such as division by zero in case drawdown is 0).
If you don't have a source code, I don't think you can apply a custom criterion for optimization.
- www.metatrader4.com
Here's a tidbit for the community. I squared the profit and divided by the drawdown. This ranks the most profitable optimizations with the most minimal of drawdowns.
{
if(STAT_EQUITY_DD == 0) {
return 9999999;
} else if(TesterStatistics(STAT_PROFIT) < 0) {
return 0;
}
else {
return pow(TesterStatistics(STAT_PROFIT),2) / TesterStatistics(STAT_EQUITY_DD);
}
}
Squaring is going to Rank both Winning and Loosing results at similar levels. For example, a Profit +$200 (with $400 drawdown) will be rated the same as a Loss -$200 (with $400 Drawdown).
Instead of inventing a Metric, why not just use a well know public one, that is also used by MT5 and the Signals in the Market:
- Recovery factor (Calmar ratio): Calculated as net profit divided by the maximum drawdown. Measures the ability of a trading system to recover from losses.
Squaring is going to Rank both Winning and Loosing results at similar levels. For example, a Profit +$200 (with $400 drawdown) will be rated the same as a Loss -$200 (with $400 Drawdown).
Just a small note: he takes the square for positive value ONLY. Negatives are processed in other branch of if.
Did not notice, but then note to OP - Why square the value then?
This is my optimization formula, to obtain. Great benefits, with minimal DrawDown
double OnTester(){ return (TesterStatistics(STAT_PROFIT)-TesterStatistics(STAT_EQUITY_DD)) * TesterStatistics(STAT_PROFIT_FACTOR); }
Actually it is very simple:
( STAT_PROFIT - STAT_EQUITY_DD ) * STAT_PROFIT_FACTOR
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I've Googled for tutorials but have been unable to find one. I would like to use custom optimization to optimize by EA. Specifically, I want to maximize profit/drawdown$ ratio to minimize risk. Does anyone have an example of doing this?