Summary: This tutorial covers everything about the MT5 Strategy Tester - setting up backtests, understanding report metrics like profit factor and Sharpe ratio, exporting trade data to CSV, and using optimization features.




I spent the better part of last month trying to validate a new EA I'd been working on. The MT5 Strategy Tester is incredibly powerful, but honestly? It took me a while to stop feeling overwhelmed by all the options and metrics it throws at you.

Let me walk you through what I actually learned by doing, not just reading the manual.

Setting Up Your First Backtest

Hit Ctrl+R to open the Strategy Tester. The first thing you'll notice is the mode selection. The official MetaTrader 5 Strategy Tester documentation explains the three modes clearly :

  • Every tick - Most accurate, simulates real market conditions

  • 1-minute OHLC - Faster, uses open/high/low/close of each minute

  • Open prices only - Quickest but least accurate


  • I default to "Every tick" for final validation and use "1-minute OHLC" during early development when I'm iterating fast. The quality of your backtest depends entirely on the historical data quality. The report shows a "History quality" percentage - anything below 90% and I'd question the results.

    The Reports: What Actually Matters

    After running a test, the "Results" tab shows a mountain of numbers. Here's what I focus on:

    | Metric | What It Tells You | My Threshold |
    | ------ | ----------------- | ------------ |
    | Profit Factor | Gross profit / gross loss | >1.5 is decent |
    | Expected Payoff | Average return per trade | Positive always |
    | Sharpe Ratio | Risk-adjusted return | >1.0 acceptable, >3.0 excellent |
    | Max Drawdown | Worst peak-to-trough decline | Lower is better |
    | Recovery Factor | Profit / max drawdown | >2.0 means good risk management |

    The official MetaTrader 5 help center documents that the Sharpe ratio calculation assumes a risk-free rate of zero . A Sharpe ratio below zero means the strategy isn't profitable - straight forward enough.

    One Thing The Docs Don't Tell You

    Here's a pain point I discovered. The Strategy Tester's built-in equity curve is based on the report data, but when you right-click and export the report to HTML, you lose the granular trade data if you want to analyze it outside MT5. The visual chart in the tester is great for a quick look, but if you want to build custom visualizations in Python or Excel, you're stuck.

    The solution I settled on: use an MQL5 script that writes trade data to CSV directly during or after the backtest. The forum threads I dug through on MQL5.com pointed to this approach - you can add custom export logic to your EA's OnTester() or OnDeinit() functions.

    Exporting Trade Data to CSV

    Instead of wrestling with the HTML report, I added this to my EA:

    ``mql5
    void OnDeinit(const int reason) {
    int handle = FileOpen("BacktestTrades.csv", FILE_WRITE | FILE_CSV, ",");
    if(handle != INVALID_HANDLE) {
    FileWrite(handle, "Ticket", "Time", "Type", "Volume", "Price", "Profit");

    for(int i = 0; i < HistoryDealsTotal(); i++) {
    ulong ticket = HistoryDealGetTicket(i);
    FileWrite(handle,
    (long)ticket,
    TimeToString(HistoryDealGetInteger(ticket, DEAL_TIME)),
    HistoryDealGetInteger(ticket, DEAL_TYPE) == DEAL_TYPE_BUY ? "BUY" : "SELL",
    HistoryDealGetDouble(ticket, DEAL_VOLUME),
    HistoryDealGetDouble(ticket, DEAL_PRICE),
    HistoryDealGetDouble(ticket, DEAL_PROFIT)
    );
    }
    FileClose(handle);
    }
    }
    `

    The CSV lands in
    MQL5\Files folder. From there, I drag it into Excel or Python for proper analysis.

    Optimization: The Genetic Algorithm Trick

    The optimization feature can run hundreds or thousands of tests. The official docs mention using Genetic Algorithm to cut down time . What I didn't realize at first: you need to set a custom optimization criterion in your EA's
    OnTester()` function. Return the value you want to maximize - balance, Sharpe ratio, or profit factor. The GA then optimizes toward that specific target.

    Visual Testing Mode

    Switch to visual mode in the tester and you can watch your EA trade in real-time on historical data. It's slow, but invaluable for catching logic errors that the numbers alone won't reveal. I caught a bug where my EA was opening trades at the wrong price because I had misconfigured the symbol point value - something I'd never have spotted without watching it tick by tick.

    Reference: MetaTrader 5 Official Documentation - Strategy Tester (metatrader5.com), MQL5 Help Center - Testing Reports (metatrader5.com).

    This article was originally published on FXEAR.com. All rights reserved. Unauthorized reproduction is prohibited.