Discussion of article "Step-by-Step Guide to Writing an Expert Advisor in MQL5 for Beginners" - page 31
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
First I would like to say that I read this article and I copied the code because I wanted to learn MQL5 coding. Second I feel I learnt a lot, and I have written 7 EAs now and a few indicators. So I feel I am well on my way to learn it to such a degree that I can code my own ideas.
Furthermore. I got really curious about the strategy tester. First I thought it was just too basic, and that it could never work. That is not true. It can work. However. For my sake it worked only for people with enormous patience. So I tested it on USDCAD, daily timeframe and I optimized take profit, stop loss and ADX period. The short story is. Just put ADX in the middle. Above 29 and below 60. You will be fine. Take profit. Quite much as high as possible. Between 300 and 500. Stop loss. For sure a lot less. A recurring number was either 155 or 30. Then comes the big problem. I tested it from 2019 until early 2025. It gave from 75 trades till about 45 for the highest ADX settings. I looked at the graph from 5 of these tests. It hovers around 0 until 2024. Then all the gain comes in the last year. Profit factor I looked at was from 1.77 till 2.61. A lot of problems all over. All shorts were losses. 86% of longs were profitable. A lot of trades had a long duration. A lot more than 10 days in general. I think I saw 3440 hours as longest holding time. Average was 846 hours. Payoff could also get very high I felt, but who wants to be limited to less than 20 trades after 6 years?
I spent days getting through all 33000 combinations. Now I will test further and reduce the tasks a lot. I don't need ADX values above 55. Stop loss at 30 is just too low even if I have seen a lot of profitability with that too. As a last point. I read one can connect several PCs/laptops in a LAN to increase speed. I recommend that.
I agree that validation should go beyond selecting the best optimization result. One additional concern I have is that the validation procedure itself can become overfit.
For example, if we repeatedly change the walk-forward window, Monte Carlo assumptions, parameter perturbation range or trading-cost assumptions after seeing the results, we may eventually optimize the validation process itself.
I think a stronger approach is to define the validation protocol before looking at the final OOS results, then keep a completely untouched final period that is used only once.
For adaptive EAs, I am also wondering whether the regime-detection parameters should be validated separately from the trading parameters. Has anyone tested this approach?
First I would like to say that I read this article and I copied the code because I wanted to learn MQL5 coding. Second I feel I learnt a lot, and I have written 7 EAs now and a few indicators. So I feel I am well on my way to learn it to such a degree that I can code my own ideas.
Furthermore. I got really curious about the strategy tester. First I thought it was just too basic, and that it could never work. That is not true. It can work. However. For my sake it worked only for people with enormous patience. So I tested it on USDCAD, daily timeframe and I optimized take profit, stop loss and ADX period. The short story is. Just put ADX in the middle. Above 29 and below 60. You will be fine. Take profit. Quite much as high as possible. Between 300 and 500. Stop loss. For sure a lot less. A recurring number was either 155 or 30. Then comes the big problem. I tested it from 2019 until early 2025. It gave from 75 trades till about 45 for the highest ADX settings. I looked at the graph from 5 of these tests. It hovers around 0 until 2024. Then all the gain comes in the last year. Profit factor I looked at was from 1.77 till 2.61. A lot of problems all over. All shorts were losses. 86% of longs were profitable. A lot of trades had a long duration. A lot more than 10 days in general. I think I saw 3440 hours as longest holding time. Average was 846 hours. Payoff could also get very high I felt, but who wants to be limited to less than 20 trades after 6 years?
I spent days getting through all 33000 combinations. Now I will test further and reduce the tasks a lot. I don't need ADX values above 55. Stop loss at 30 is just too low even if I have seen a lot of profitability with that too. As a last point. I read one can connect several PCs/laptops in a LAN to increase speed. I recommend that.
That's a well detailed summary of your initial experience with the Strategy Tester.
If I may make a few suggestions:
Step #1 should really be checking the quality of your broker-dealer's tick data. There is a very good script that automates that process at:
Code Base
Tick Audit - check real tick history and backtest quality month by month
Ayaz, 2026.09.05 06:13
Reports, month by month, whether your symbol really has ticks or only bars - so you know which part of your backtest ran on generated ticks before you trust the curve. The Strategy Tester gives you one History Quality figure after the test has finished, and it never says which months were the problem. This script asks first.Step #2 should be testing on "Every tick based on real ticks" of your specific broker-dealer's historic data (just in case you're not doing so). Depending on your pc specs, you may need to do that in chunks─especially on older machines.
Step #3 should be evaluation of the Tester Report which you've already started. Pay close attention to the average count of consecutive losses and the maximum count of consecutive losses. You may want to adjust your position size down after your count of consecutive losses in real-time exceed your average count of consecutive losses (a full explanation is posted on my Profile wall). Also pay attention to the times (hours, days, and months) during which your EA is profitable. Trade entry hours are not supported natively, so I created a utility that generates an auxiliary report (https://www.mql5.com/en/blogs/post/774010). You may want to implement a trading time filter (https://www.mql5.com/en/blogs/post/770147).
As a side note, there are plenty of profitable positional (long-term) traders. If your personal goals are aligned with that style of trading, I wouldn't worry too much about trading frequency. IMHO, it is much easier to create a profitable LFT strategy than an HFT or even an MFT strategy.