Summary: A practical walkthrough of a surprisingly effective but rarely mentioned method to speed up backtesting in MetaTrader by clearing on-chart trade graphics, plus other optimization tips from experience.




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:

  • Run the backtest in <strong>non-visual mode</strong> (that's the default setting anyway).

  • Periodically – and this part is manual, unfortunately – switch to visual mode just for a moment, hit the "Delete" button to clear the accumulated trade arrows and lines, then switch back to non-visual mode.

  • The performance improvement is immediate. On that four-hour test, I started doing this every 30 minutes, and the total time dropped to about 2 hours and 20 minutes.


  • 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:

  • Reduce maximum bars in history – Already mentioned earlier, but it's worth repeating. Setting these to a lower number reduces the data load.

  • Close unnecessary charts – If you have other charts open while running a backtest, close them. Each chart consumes CPU cycles.

  • Use control points instead of every tick – This is a setting in the Strategy Tester. "Every tick" is more accurate but significantly slower. For initial parameter screening, control points mode is much faster.


  • 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.