MT4 Backtesting and Optimization: Compare Parameters Without Overfitting
MT4 optimization compares an Expert Advisor under different input settings on the same historical data. The highest-ranked pass is a selected result, not an independent estimate of future performance. A useful workflow preserves a baseline, documents every search and evaluates the chosen rules on data that did not influence their selection.
Establish a Baseline Before Searching
Open the desktop Strategy Tester with Ctrl+R and run one fixed configuration. Record the EA version, symbol, period, date interval, initial deposit, trading direction, spread and input values. Inspect a short visual run and its Journal before spending time on a large parameter search.
For the initial platform setup, see the MT4 backtesting setup guide. This page focuses on how to compare and evaluate optimization results once a baseline exists.
Check What the Historical Model Can Represent
Standard MT4 Every tick generates modeled ticks from available lower-timeframe history. It does not inherently replay recorded real ticks. Control points is an approximation; Open prices only needs careful scrutiny when an EA has intrabar stops or management even if entries occur at bar open.
A modeling-quality percentage is not a probability of correct performance. Check the underlying coverage and whether the execution assumptions represent the strategy. An 8% versus 22% drawdown difference cannot be asserted without the actual paired tests, and no such measured comparison is supplied here.
Set Up a Deliberate Search
In Expert properties, use Inputs to choose the parameters included in optimization and specify Start, Step and Stop. Use Testing for the optimization criterion and genetic-search option; Optimization supplies pass constraints. Then enable Optimization in the main tester settings. MetaQuotes documents these controls here.
For a hypothetical grid, a moving-average period from 10 through 50 in steps of 5 has nine values. A stop multiplier with five values produces 45 combinations when all pairs are tested. Adding parameters multiplies the search space. Even a small grid can overfit when repeatedly redesigned after inspecting results.
Genetic search samples the space selectively rather than exhaustively evaluating every combination. Record the search method and ranges so another test does not appear contradictory merely because it examined different candidates.
Understand the Objective's Tradeoffs
| Objective | Question to ask after ranking |
|---|---|
| Final balance | Did higher exposure or a few exceptional trades drive the result? |
| Profit factor | Is the denominator small, or are there too few losses to estimate it well? |
| Expected payoff | Is average profit dominated by rare outliers or different position sizes? |
| Drawdown | Did the selected setting reduce risk mainly by trading very little? |
| Custom criterion | Does the formula match the intended economic objective and handle edge cases? |
Expected payoff is a sample average, not a consistency measure. Minimum drawdown is not a guarantee of safety. Keep trade count, exposure, loss size and net return visible beside the ranking criterion.
Look for Sensitivity, Not Just the Top Row
Compare the selected setting with nearby values. If one isolated combination looks exceptional while adjacent settings fail, investigate whether a small timing or fill change drives the difference. A broad region of similar results is useful descriptive evidence, but still does not prove persistence.
Re-run finalists as ordinary single tests and inspect their trade lists. Confirm that optimization constraints did not truncate a pass in a way that makes its summary incomparable. Preserve rejected candidates and the reason for rejection in the log.
Reserve Later Data Before Selection
Choose development and evaluation periods before optimization. An 80/20 split is only one possible design; its usefulness depends on trade frequency and market coverage. A fixed number of years or 100 trades does not automatically establish statistical reliability.
For a walk-forward exercise, define a development window, a subsequent evaluation window and a parameter-selection rule. Repeat that schedule through time and combine only the evaluation segments. Retain the costs of switching parameters and prevent later information from influencing earlier choices.
If you revise the method after viewing the evaluation results, record that revision and seek new evidence. Calling repeatedly reused data “out of sample” does not restore its independence.
Stress Costs and Market Assumptions
The standard tester's Current spread is the spread at test start, not a historical series. Record spread in the interface's units and translate points to pips only using the relevant symbol specification. Gold, indices and forex pairs need not share the same convention.
Compare a baseline cost assumption with plausible higher costs. Check commission and swap treatment in the actual results. Increasing spread is not identical to modeling slippage or latency; it may be a rough sensitivity exercise, but label it as such.
Test other periods or markets when the strategy claims to generalize to them. Failure on an unrelated instrument does not by itself disprove a deliberately instrument-specific rule; conversely, selecting a winning instrument after examining many is another source of selection bias.
Preserve a Review Package
Save the EA source/version, input .set, complete tester settings, data provenance, reports and Journal observations. The input file alone cannot recreate the historical environment. Keep a table of experiments showing what changed and why.
Pineify can assist with MQL4 code drafts or with a separate Pine Script implementation. Equivalent-looking rules on MT4 and TradingView can produce different results because data and execution models differ. Validate each implementation in its intended environment.
Frequently Asked Questions
Does the best optimization pass identify the best future parameters? No. It identifies the best tested pass under a chosen criterion and historical sample.
How many parameters may I optimize? There is no universal safe count. Restrict the search to justified choices, document all variants and preserve independent evaluation data.
Does a higher modeling-quality score remove overfitting? No. Data fidelity and selection bias are separate problems.
Can I optimize a manual description directly? The EA tester evaluates implemented rules. Manual observation requires a separate log and cannot be measured by an unrelated EA's report.

