Running a multi-year backtest on a tick-by-tick dataset is one of those things that sounds good in theory and then you actually do it. You hit "Start", go make coffee, come back, and the progress bar is still sitting at 3%. Come back after lunch, it's at 12%. You start wondering if your VPS is just underpowered or if the EA is doing way too much math.
I spent about a week last month wrestling with a particularly heavy grid-based EA. The strategy itself wasn't that complex, but the backtest across five years of EURUSD tick data was taking almost four hours to complete. That's not sustainable when you need to run through a few parameter sets.
I tried all the usual suspects first. I dropped the visual mode, obviously. I adjusted the "maximum bars in chart" and "maximum bars in history" settings under Tools > Options > Charts. That helped a little, maybe shaved off 10 minutes. I even disabled the news feed in Tools > Options > Server. Marginal gains at best.
Then I stumbled onto something in a forum thread that I'd never seen in any official MetaQuotes documentation. Someone mentioned that during backtesting, MetaTrader automatically generates trade entry and exit arrows plus equity lines directly on the test chart. And here's the kicker – those graphics eat CPU resources, and they keep accumulating as the test runs. The longer the test, the more trade events, the more graphics need to be rendered, the slower the whole thing gets.
The MQL4 documentation covers the
OnCalculate() function for indicators and the general structure of Expert Advisors[docs.mql4.com], but it doesn't say a word about how the Strategy Tester handles graphic rendering. This is one of those things you only find out by sitting through painfully slow tests.The method that actually worked
I found that if you let the backtest run in visual mode for a while, then click the "Delete" button in the Strategy Tester toolbar – the one that removes all drawn objects from the chart – the speed picks up noticeably within seconds. But that only works for visual mode, and visual mode itself is already slower than non-visual because it's rendering the chart in real time.
So here's the workaround I pieced together:
This isn't documented anywhere official that I could find. MetaQuotes doesn't mention that on-chart objects generated during backtesting consume rendering resources even when the chart isn't visible. But the resource drain is real. The more trades your EA opens over the test period, the more objects the tester creates, and the slower the simulation runs.
Additional performance tweaks
After discovering this, I looked for other ways to reduce backtesting overhead. A few things that helped further:
The "Delete" trick isn't a replacement
To be clear, manually clearing objects during a backtest is a workaround, not a proper solution. It requires babysitting the test, which defeats some of the purpose of automation. But when you absolutely need accurate tick-by-tick results and you don't have a high-end machine, this trick can cut your waiting time by almost half.
I've since written a small script that uses the
ObjectsDeleteAll() function to remove chart objects programmatically during a backtest. The script runs on a timer, and it clears trade arrows and lines without needing to switch visual mode on and off. It's not a perfect fix – there's still some overhead from the script itself – but it gets the job done better than doing it by hand.Reference: MQL4 Documentation – Custom Indicators and Expert Advisors (docs.mql4.com), Exness Help Center – Performance Optimization for MetaTrader (get.exness.help).
This article is originally published on FXEAR.com, original content, reproduction without authorization is prohibited.