EN
Help Centre
Contact Us
Company Logo
Markets
MARKETS TO TRADE
  • All Markets
  • Forex
  • Commodities
  • Metals
  • Indices
  • Stocks
  • Cryptocurrency
  • ETF CFDs
  • Futures CFDs
  • Crosses CFDs
Trading
ACCOUNTS
  • Our Accounts
  • Standard
  • Micro
  • ECN
  • Pro ECN
  • Demo
PAMM
  • PAMM Trading
TRADING TERMS
  • Fees
  • Deposits & Withdrawals
  • Leverage & Margin
  • Dividends Calendar
  • Contract Specifications
Platforms
PLATFORMS
  • Our Platforms
  • Desktop
  • Trading App
  • MetaTrader 4
  • MetaTrader 5
Tools & Resources
TOOLS
  • Economic Calendar
  • Trading Schedule
  • Advanced Charts
NEWS & ARTICLES
  • Market Analysis
LEARN
  • Alpari Academy
  • Learning Tools
Loyalty & Promotions
REWARDS
  • Alpari Rewards
PROMOTIONS
  • Our Promotions
  • Refer a Friend
About
Why Alpari?
  • About Us
Partners
  • Partnerships
  • Introducing Brokers
Terms and Conditions

    ADVANCED: COURSE 3 | LESSON 1

    Algorithmic trading and EAs on MT4/MT5

    Learning objectives

    1. Explain what an Expert Advisor is, how it runs on MT4/MT5, and what automation genuinely does and does not solve

    2. Identify the major backtest failure modes — curve-fitting, look-ahead bias, poor modelling quality, survivorship of ideas — and the tests that expose them

    3. Evaluate a backtest report (your own or a vendor's) with a professional's checklist before any real money is involved

    What an EA actually is

    An Expert Advisor (EA) is a program that runs inside MetaTrader and trades your account by rule: it receives market events (each tick, each new bar), evaluates its logic, and sends orders through the same API your mouse clicks use. MT4 EAs are written in MQL4, MT5 in MQL5 — C-like languages with built-in functions for indicators, order management and account state. MT5 is the more capable environment for our purposes here, chiefly because of its far better strategy tester (more on modelling quality below), multi-threaded optimisation, and support for more order types.

    Be precise about what automation buys you. It buys consistency (the EA never widens a stop out of hope — the whole A2 course is irrelevant to it), coverage (it watches sessions you sleep through), speed (reaction in milliseconds), and above all testability — a rule set that is fully mechanical can be evaluated on years of history in minutes. What it does not buy you is an edge. An EA is a delivery mechanism: automating a losing strategy produces losses with excellent discipline and superb execution. The uncomfortable corollary: most of the skill in algorithmic trading is not programming — it is the statistics of not fooling yourself, which is the rest of this lesson.

    Operationally, an EA is also an uptime problem: it needs a machine running MetaTrader continuously (in practice a VPS near your broker's servers), monitoring for disconnects, and a plan for open positions when the platform, the VPS, or the broker's bridge hiccups. Treat these as part of the system, not afterthoughts — a trend EA that missed its exit signal during a VPS reboot has no opinion about what to do when it reconnects unless you wrote one.

    The backtest: where self-deception is industrialised

    A backtest replays history through your rules and reports what would have happened. Done honestly, it is the most powerful tool a rule-based trader has. Done casually, it is a machine for manufacturing false confidence. The classic failure modes:

    Curve-fitting (overfitting). Every parameter you tune — MA periods, stop multiples, session filters, day-of-week rules — is a dial for fitting the strategy to the specific noise of your test data. With enough dials, any random data can be "profitably" fit; the resulting system has memorised history, not learned structure. Warning signs: performance that collapses when a parameter moves slightly (a 20-period MA earns 3,000 pips but 18 or 22 loses money — you found a coincidence, not an edge); many conditions that each exist to remove one historical losing streak; spectacular equity curves with implausibly small drawdowns. Discipline: few parameters, plateaus not peaks in optimisation results (a robust system is profitable across a neighbourhood of settings), and a strict split between in-sample data (used for development) and out-of-sample data the strategy has never seen, evaluated once. Walk-forward analysis — repeatedly optimising on a window and testing on the next unseen segment — is the systematic version and the closest a backtest gets to honest simulation of live use.

    Look-ahead bias. The rules accidentally use information unavailable at decision time: acting on a bar's close while pricing entry at its open, computing an indicator on the forming bar (in MQL terms, reading buffer index 0 instead of the completed bar at index 1), or signals repainting after the fact. Look-ahead is deadly because it often adds just a few "impossible" pips per trade — enough to turn breakeven into brilliant while looking innocent in the code.

    Modelling quality and cost realism. MT4's tester interpolates ticks from M1 bars ("90% modelling quality" is a ceiling, not a compliment), which flatters anything sensitive to intrabar sequence — tight stops, scalping, pending-order fills. MT5's "Every tick based on real ticks" mode replays actual recorded ticks and is dramatically more trustworthy for such systems. Beyond ticks: test with realistic variable spreads (a fixed 1-pip spread assumption quietly deletes the news-time spread widening from A3.2 that would have stopped you out), include commission and swap (A3.3), and add slippage assumptions for any strategy trading around volatility. A useful stress test: if halving the assumed edge per trade by costs kills the system, the system was mostly a cost-modelling error.

    Selection and survivorship of ideas. Test twenty strategy ideas and one will look great by chance — the multiple-comparisons problem applies to your own research history, not just to vendors. Keep a log of everything you tested; judge the survivor in the context of the graveyard.

    Reading a backtest report like a sceptic

    Whether the report is yours or a seller's, the same checklist applies. Sample size: hundreds of trades minimum across several years and, crucially, several regimes (trend, range, high/low volatility — a 2023-only test proves nothing about 2020 behaviour). Consistency: profit spread across years, not one golden quarter. Drawdown: judged against the return realistically — and against A2.4's envelope logic. Trade distribution: an equity curve built on a few huge winners is fragile; one with a fat left tail is undisciplined by construction. Costs: spread model, commission, swap, slippage all stated. Out-of-sample: shown, and shown once. For commercial EAs, add: verified live (not demo) track records over a year or more on an independent service — and the base-rate warning that marketplace bestsellers overwhelmingly show beautiful backtests and short, ugly live histories. Martingale and grid systems deserve special mention: their equity curves look serenely smooth right up until the strategy's defining catastrophic loss, which is not a tail risk but the design.

    The honest path from idea to live is boringly incremental: mechanical rules → tick-quality backtest with full costs → walk-forward → forward test on demo for weeks-to-months (this is where the P3.5 demo loop pays off) → small live size, scaling only as live statistics accumulate per A2.3's sample-size rules. Live-versus-backtest divergence is expected — spreads, slippage and the odd requote take their bite — and measuring that gap is your first live experiment (A3.2 gives you the tools).

    Key takeaways

    1. An EA is rule execution, not edge: it delivers consistency, coverage and testability, and will automate a losing idea just as faithfully as a winning one

    2. Curve-fitting is the default outcome of optimisation — defend with few parameters, parameter plateaus, out-of-sample data used once, and walk-forward analysis

    3. Look-ahead bias adds impossible information worth a few pips a trade; audit indicator indexing and entry timing explicitly

    4. Backtest realism is costs and ticks: MT5 real-tick mode, variable spreads, commission, swap and slippage — a strategy killed by realistic costs never existed

    5. The idea-to-live pipeline is staged: honest backtest → walk-forward → demo forward test → small live size, with the live-vs-backtest gap measured, not assumed away

    Company Logo

    Explore

    • Markets
    • Platforms

    About

    • About Us
    • Partnerships

    Support

    • Help Centre
    • Contact Us
    • Helpline: +44 2045 771 951
    • Bonovo Road, Fomboni, Island of Moheli, Comoros Union

    Alpari is a global forex and CFDs broker.

    Alpari, the trading name of Parlance Trading Ltd, Bonovo Road – Fomboni, Island of Mohéli – Comoros Union, is incorporated under registered number HY00423015 and licensed by the Mwali International Services Authority, Island of Mohéli as an International Brokerage and Clearing Company under number T2023236.

    Risk Disclosure: Before trading, you should ensure that you've undergone sufficient preparation and fully understand the risks involved in margin trading.

    Alpari does not provide services to residents of the USA, Japan, Canada, the Democratic Republic of Korea, European Union, United Kingdom, Myanmar, India, Azerbaijan, Syria, Sudan and Cuba.

    © 1998-2026 Alpari

    Privacy PolicyClient AgreementRisk DisclosureCookie PolicyTerms of BusinessRegulations for Non-Trading OperationsAlpari Re-deposit bonus
    logo
    We value your privacy
    We use cookies to give you the best-possible experience on our site and serve you personalised content. Click "Sounds good" to agree to our Cookie Policy
    Sounds good