Expert Advisor Basics: What an EA Is and How to Backtest One in MT5

Trader reviewing an MT5 EA backtest

An Expert Advisor (EA) is a program that runs inside MetaTrader and trades by rules you set. It reads market and account data, applies your logic and, when algorithmic trading is switched on, can open, manage, modify and close trades without you clicking. For a scalper or a crypto trader, the rules are only half the result. Execution speed and spread decide whether the backtest you admired survives on a live account. At Mitra Markets we run MetaTrader 5 with MitraNet™ execution under 30 milliseconds, so the fills your EA receives are built for that kind of strategy.

This guide covers what an EA does, how it makes decisions, how to create one, how to backtest it in the MT5 Strategy Tester and how to read the results.

Mitramarkets
mitramarkets.com
Put EA Execution Speed in Context
Mitra Markets runs MetaTrader 5 with MitraNet™ execution under 30 milliseconds, a relevant consideration for short-term automated strategies.
Visit

TL;DR

  • An Expert Advisor is a trading robot inside MetaTrader that analyzes quotes and executes trades according to programmed rules.
  • In MT5 you can write one in MQL5 or generate one with the MQL5 Wizard, then check it in the Strategy Tester.
  • A backtest is one run with fixed parameters on historical prices. Optimization repeats the run with different parameter sets.
  • Backtests cannot reproduce every live condition, so set realistic spread, commission and delay values, then confirm on a later period.
  • Fast execution and tight pricing matter most for short-term EAs, because small costs repeat on every trade.

Table of Contents

What an Expert Advisor is

MetaTrader’s own description is plain: an Expert Advisor is a trading robot that analyzes instrument quotes and carries out trading operations according to the rules it was programmed with. You will also see EAs called forex robots, trading bots or just “experts”. The idea is identical: you write the rules once, and the program applies them every tick without hesitation, fatigue or second-guessing.

An EA is not an indicator. An indicator draws information on a chart, such as a moving average or an oscillator. An EA can act on information: it sends orders, moves stop losses, closes positions. Many EAs use indicators as inputs, and if you want to build your own signals first, our guide to MT5 custom indicators shows how to install and build them.

An EA is also not a profit machine. It is a way of executing a defined plan consistently. If the plan has no edge, automating it only loses money faster and more regularly. Everything below is about checking the plan before real money is involved.

What an Expert Advisor is

How an Expert Advisor works

An EA works on an event model. According to the MQL5 documentation, an EA can use quotes, ticks, market depth, account history or indicator readings as trading signals, and it reacts to events that are specific to Expert Advisors: OnTick (a new price arrives), OnTrade (something changed in your trades) and OnTradeTransaction (a detailed trade event occurred).

In practice, a typical simple EA does this on each new tick or bar:

  1. Reads the latest price data and any indicator values.
  2. Checks whether its entry condition is met, for example a fast moving average crossing above a slow one.
  3. Calculates position size from your risk rules.
  4. Sends the order, usually with a stop loss and take profit.
  5. Manages the open trade by trailing the stop, closing at a target or closing on an opposite signal.

The same document lists the design questions every EA author faces: how fast the program decides and sends orders, which instruments it trades, how lot sizes and order distances are calculated, and whether it needs news or external data. If you are new to sizing, our explainer on lot sizes from standard to nano will make the position-size step much clearer.

Running an EA on a chart

To run an EA in MT5, select it in the Navigator, attach it to the chart you want, configure its inputs and enable algorithmic trading on the platform. The EA only acts while the terminal is open and connected, so a locally running EA stops when your computer sleeps or loses internet. MetaTrader’s Store notes that virtual hosting can provide round-the-clock operation.

What EAs are good at

EAs suit rules-based approaches. A few examples of what traders automate:

  • Trend following: enter when price breaks a range or a moving average crosses, and trail the stop.
  • Scalping: take many small trades on short timeframes, where reaction time and spread dominate the result.
  • Grid or averaging logic: place orders at set distances. These need strict risk limits in the code.
  • Risk management helpers: close all trades at a daily loss limit or move stops to breakeven.
  • Crypto CFD strategies: react to fast moves that can pass before a manual order is typed.

The common benefit is consistency: the rule you tested is the rule that trades. The common risk is the gap between test and live conditions, which the backtesting sections below address directly.

How to create an EA in MT5

MT5 gives you two routes. The first is writing code. MetaTrader’s automated trading page explains that MT5 uses the MQL5 language and an integrated development environment for developing, debugging, testing, optimizing and running trading robots. That environment is MetaEditor, opened from the platform with F4.

The second route needs no programming. The same page says the MQL5 Wizard can generate an EA without programming experience by letting you pick parameters and components. Here is the flow, as described in MetaQuotes’ Wizard article:

  1. In MetaEditor, choose New and then Expert Advisor (generate).
  2. Enter the general properties: name, author and input parameters.
  3. Select a signal module, such as a moving-average or oscillator-based entry rule.
  4. Select a trailing module, which defines how stops follow price.
  5. Select a money and risk-management module, which defines position size.
  6. Finish, and the wizard generates the source file. Compile it, and it appears in the Navigator.

The Wizard is a good way for a beginner to assemble standard components. Treat the generated code as a draft: it still needs validation and testing before it is trusted with capital. Our longer walkthrough, MT5 algorithmic trading: set up, backtest and validate EAs, goes through the full cycle from setup to validation.

Decisions to make before you build

  • Instrument and timeframe. A strategy tuned on EUR/USD hourly bars is a different thing from a crypto CFD scalper on one-minute bars.
  • Risk per trade. Fix it as a percentage of the account, not a guess.
  • Costs. Decide the spread and commission you expect, because you will need them in the tester.
  • Failure behavior. Decide what the EA does if the connection drops or an order is rejected.

Backtesting in the MT5 Strategy Tester

Backtesting means running your EA against historical prices to see what it would have done. The official MT5 documentation defines testing as a single run with fixed parameters on historical data, while optimization repeats the run with different parameter sets. Keep the two apart in your mind: testing checks an idea, optimization searches for settings, and the second is where overfitting creeps in.

Step by step

Open the Strategy Tester from the View menu (Ctrl+R) and follow the documented sequence:

  1. Select the EA you want to test.
  2. Choose the symbol and timeframe. Test the instrument you actually plan to trade.
  3. Set the historical dates. Use a long enough window to include trending, ranging and volatile periods.
  4. Set the account and test inputs, such as deposit, leverage and your EA’s parameters.
  5. Choose a modelling mode. More detailed tick-based modes suit short-term strategies, where price movement inside a bar matters.
  6. Start the test and watch the run.
  7. Review the trades, equity graph and report.

Where backtests go wrong

Most bad backtests fail at step 4, with unrealistic inputs. The official documentation warns that a historical test cannot reproduce every live situation, since actual spreads, commissions, swaps, execution modes and available prices change over time. MetaTrader’s Store guidance also advises checking realistic spread, commission and execution-delay settings as part of testing.

For a scalper this is critical. A strategy that makes 0.6 pips per trade before costs can look excellent with a zero spread and collapse with a real one. Enter the commission you will really pay. On our accounts page the listed commission is $7 per lot, so a test that ignores that figure overstates your result.

How to read your backtest results

The tester produces a report with profit, number of trades, statistical values and a balance and equity graph. Read them in this order:

What to look at What it tells you What to watch for
Number of trades Whether the result has enough data behind it A handful of trades proves nothing
Net profit The headline outcome A figure produced by one lucky trade
Equity graph The path, not only the end point Deep dips that you could not sit through
Drawdown The worst fall from a peak Is it within what your account can bear?
Profit per trade vs. costs How much room you have after spread and commission Thin margins that live costs could erase

The equity graph deserves most of your attention. Two EAs can end with the same profit, but one climbs steadily and the other swings wildly. The steady one is the one you can actually hold through a bad month.

Optimization and forward testing

When you optimize, you vary chosen inputs, such as a moving-average period, and let the tester run many combinations. The risk is choosing settings that merely fit the past. The documentation’s remedy is to use a later forward segment to check the chosen settings: optimize on one period, then test the winner on dates the optimizer never saw. If the result falls apart there, the parameters were fitted to noise.

A sound sequence is: build the rule, test it with realistic costs, optimize only a few inputs, forward-test, and only then run it on a live account with small size. Small size is where micro lot trading and a small account approach help, since you can see live behavior while risking very little.

Five steps from EA rule to small live test

Why execution matters for EAs

A backtest assumes your orders fill at the price the model shows. Live, the fill depends on how quickly the order reaches the market and who is on the other side. For an EA that trades a few times a week, this barely registers. For a scalper sending dozens of orders, a few tenths of a pip of slippage per trade is the difference between a strategy that works and one that does not.

That is why execution conditions belong in your EA planning, not after it. Three questions are worth answering about any account you plan to run an EA on:

  • How fast do orders reach the liquidity provider?
  • Are spreads tight enough that your average win clears the cost?
  • Are fills routed to deep liquidity? Our piece on DMA versus market maker execution explains how order routing differs.

Perspective

Most traders approach EAs as a coding problem. We see them as a conditions problem. A strategy is a set of assumptions about price, cost and speed, and the Strategy Tester only confirms those assumptions on paper.

That is why we built Mitra Markets around MetaTrader 5 with MitraNet™ technology, which is designed for order execution under 30 milliseconds and direct access to Tier-1 liquidity. Retail traders have long been denied the speed and tools that professionals take for granted, and automated strategies are where that gap shows up first. Our goal is for the conditions your EA meets live to resemble the institutional-grade conditions it was designed around.

There is no minimum deposit, so you can start an EA with a size that matches your plan and scale as the results justify it.

Partners

Run your EA on MetaTrader 5 with Mitra Markets

Mitra Markets supports MetaTrader 5 with advanced charting and algorithmic trading across forex, commodities, indices and crypto CFDs. Deposits and withdrawals are instant, there is no minimum deposit, and a rewards program pays out on trading volume. You can compare the Edge and Standard account types, and see the listed commission of $7 per lot, on our accounts page. The platforms page describes MetaTrader 5 and MitraNet™ in more detail.

Mitramarkets

To see which instruments you can automate, browse the markets we offer.

Common mistakes with Expert Advisors

  • Testing with zero costs. Always enter a realistic spread and commission.
  • Over-optimizing. Tuning ten inputs to fit five years of data produces a curve, not a strategy.
  • Skipping forward testing. A result you have not checked on unseen dates is a hypothesis.
  • Ignoring uptime. A locally running EA needs the terminal open and connected.
  • Starting big. Begin with small position sizes while you watch live behavior.
  • Trusting generated code blindly. Even a wizard-built EA needs validation.

FAQ

What is an Expert Advisor in simple terms?

It is a trading robot that runs inside MetaTrader. You define the rules, and it analyzes quotes and places or manages trades according to them. You decide the strategy and the risk, and the EA carries it out.

Can I create an EA in MT5 without coding?

Yes. The MQL5 Wizard in MetaEditor lets you choose signal, trailing and money-management modules and generates the source file for you. The generated EA should still be compiled, backtested and validated before live use.

How do I backtest an EA in MT5?

Open the Strategy Tester, select the EA, symbol and timeframe, set dates and inputs, choose a modelling mode and start. Then review the trades, equity graph and report. The official steps also describe optimization and forward checks.

Does a good backtest guarantee live profits?

No. Historical tests cannot reproduce every live situation, because spreads, commissions, swaps and prices change. Use realistic cost settings, confirm on a later period and begin live trading with small size.

Sources