MT4 Backtesting: How to Test and Optimize Strategies in MetaTrader 4
MetaTrader 4's Strategy Tester runs an Expert Advisor against modeled historical prices. A useful test checks whether the EA follows its rules and how its results depend on data and execution assumptions. It cannot establish future profitability or turn a manual trading description into an automated strategy without an implementation.
Start with a Reproducible Baseline
Write down the entry condition, exit condition, position size, maximum simultaneous orders and permitted trading hours. Resolve ambiguous instructions such as “buy a strong trend” before testing. Record the EA source or version, terminal build, broker server, symbol specification and timezone.
Compile the EA in MetaEditor and review the compiler messages. Open the desktop Strategy Tester with Ctrl+R, select the compiled EA and choose the intended symbol and timeframe. In Expert properties, configure initial deposit, currency, trading direction and the EA's input values. Enable Use date when you want a bounded test interval.
MetaQuotes' tester setup reference documents these controls. Keep the first test simple enough that you can manually explain several trades before launching optimization.
Choose a Modeling Method That Matches the Logic
| Method | What to check |
|---|---|
| Open prices only | Appropriate for investigating rules that depend only on completed bars; intrabar stops, pending orders or position management require separate scrutiny. |
| Control points | An approximate intrabar model using lower-timeframe data and interpolation. Treat its output as preliminary. |
| Every tick | Uses available lower-timeframe bars to model intermediate ticks. The standard mode is not a replay of recorded real ticks. |
Do not equate the mode's name with execution fidelity. An EA with a bar-open entry can still have intrabar exits, so entry timing alone does not establish that Open prices only is sufficient.
The modeling-quality field and colored band describe aspects of the historical model. They are not a probability that the results are correct. A reported 90% or 99% score does not prove realistic spreads, slippage, commissions or broker behavior. Third-party tick-data workflows require their own format, version and cost checks; no vendor is endorsed by a score alone.
Inspect Data and Costs
Use History Center to inspect the available history and its provenance. Check missing intervals, duplicated records, session boundaries and inconsistent OHLC values. A longer dataset is useful only if its coverage and market definitions fit the question being tested.
The standard tester models Ask from Bid history and the selected spread. The Current choice uses the spread available at test start; it does not mean historical variable spread. A zero spread removes that cost, while the current spread can be either higher or lower than an appropriate assumption.
Run a deliberate spread sensitivity test and inspect how commission and swap appear in the actual report. Do not assume the standard interface supplies a realistic latency or slippage model. If a cost is not represented, quantify it separately or use a testing environment that supports the required assumption.
Audit Trades Before Reading the Profit Total
Run a short interval in Visual mode. Compare the expected entry bar with the order log, then inspect stop placement, lot size, duplicate orders and exits around gaps. Pause on an unexpected trade and find the corresponding Journal messages.
Save the report and the EA input set separately. A .set file preserves EA parameters; it is not a complete record of history, spread, terminal build and tester settings. Keep those details in a test log alongside the source version.
Read Results as a Joint Description
MetaQuotes' results reference describes the Results, Graph, Report and Journal views. Review net profit, gross profit and loss, trade count, drawdowns and the trade sequence together.
Profit factor is gross profit divided by the magnitude of gross loss. Expected payoff is average profit or loss per trade in the sample. Neither a profit factor above 1.3 nor 100 trades is a universal reliability threshold. A small number of large winners may dominate the result, while a high win rate can coexist with occasional large losses.
For a hypothetical sample with 70 wins averaging 1 unit and 30 losses averaging 3 units, the total is 70 minus 90, or a loss of 20 units before additional costs. This illustrates payoff arithmetic, not an MT4 strategy's measured performance.
Optimize Without Treating the Best Pass as Evidence
Choose a small set of parameters with a reason for varying each one. In the Inputs table, enable the parameters to optimize and set their Start, Step and Stop values. A period range from 10 to 50 in steps of 5 defines nine candidate values.
The optimization criterion and genetic-search setting are in the Testing tab of Expert properties; the Optimization tab sets constraints on passes. Check the current interface rather than confusing the criterion with those constraints. Genetic search does not examine every combination.
Reserve a later interval before selecting parameters. Examine neighboring settings and sensitivity to costs, not only the highest-profit row. Repeatedly inspecting and retuning against the reserved interval makes it part of development; it is no longer untouched evidence.
From Historical Test to Demo Observation
After resolving logic errors, run the fixed EA settings in a demo environment and compare actual signal times and order handling with expectations. A calendar duration alone does not establish enough evidence; market conditions, trade frequency and unresolved execution differences matter.
Pineify can assist with drafting MQL4 code, but the resulting EA still requires MetaEditor compilation, tester inspection and broker-specific checks. Its Pine Script workflow is a different runtime, and a TradingView trade export is not a substitute for an MT4 execution test.

