Category
Platform
Difficulty
Beginner
Used in
MT5 operationEA evaluationStrategy design

Expert Advisor

An automated trading program written in MQL5 that runs inside MetaTrader 5 and places, modifies and closes orders according to programmed rules without manual intervention.

also: EA, trading robot, trading bot, algorithmic trader

Updated

In plain English

A program that trades for you inside MetaTrader. It has no judgement and no memory beyond what you gave it: it wakes when the platform calls it, looks at the few things it was written to look at, and acts.

Why it matters

Backtests, drawdown figures, magic numbers, VPS uptime — all of it exists because a program, not a person, places the orders. Knowing what the platform hands an EA, and what it withholds, is the difference between reading a result correctly and being surprised by it.

  • It executes without hesitation, which is its whole value and its whole risk. The rule set that never skips a valid signal also never notices that today is different.
  • It sees a narrow slice: prices for its symbol, indicator values it requests, the account's own positions and balance. News, other brokers' quotes and your other accounts sit outside that window unless the code fetches them.
  • It is distributed compiled. A .ex5 file runs but cannot be read, so a buyer's confidence has to come from published test evidence rather than the source.
  • It runs only while the terminal runs. An EA on a sleeping laptop is an EA that is not trading — the entire argument for a VPS.

In MetaTrader 5

Where it appears in MT5

  • Navigator → Expert Advisors — the compiled EAs the terminal can see
  • File → Open Data Folder → MQL5/Experts — where the .ex5 file has to sit for it to appear
  • Toolbar → Algo Trading — the master switch; an EA with a sad face on the chart is one this button is blocking
  • Chart → EA properties (F7) → Inputs / Common — parameters and per-EA permissions
  • View → Strategy Tester (Ctrl+R) — the same EA run over historical data

How EAs use it

  • The terminal calls OnInit() once at attach, OnTick() on every incoming quote for the chart's symbol, and OnDeinit() at removal.
  • Work usually happens on closed bars, not every tick: the EA compares the current bar's open time with the one it stored and returns immediately when nothing new has formed.
  • Orders go out as a filled-in MqlTradeRequest, or through the CTrade wrapper that fills most of it in for you.
  • Each instance tags its orders with a magic number so it manages only its own positions — without it, two EAs fight over the same tickets.

Typical settings

Setting Typical value Note
Algo Trading (terminal) enabled Off after installation. Nothing trades until it is on.
Allow Algo Trading (per EA, F7 → Common) enabled A separate permission from the terminal-wide switch.
Allow WebRequest for listed URL off unless the EA needs it Only EAs fetching external data need it; grant per URL, never blanket.
Chart timeframe the EA's designed timeframe An M15 strategy on an H1 chart is a different strategy — OnTick fires per tick, but bar logic reads the chart's period.
MagicNumber unique per running instance Not per product: two charts running the same EA need two values.

Common operational problems

  • The terminal is closed, asleep or restarting for updates — the EA is simply not running, and no error is recorded.
  • A symbol-name mismatch between broker and settings (EURUSD against EURUSD.m) leaves the EA attached and silent.
  • Insufficient free margin: OrderSend fails per attempt and the EA keeps trying, so the log fills while the account does nothing.
  • A trade context is busy when several EAs send at once — intermittent, hard-to-reproduce failures.
  • The EA was tested on a broker with a different execution model or contract size, and behaves differently live with no code change.

Related MT5 functions

OnInit() / OnDeinit()
Called once at attach and once at removal — where inputs are validated and handles created.
OnTick()
Called on every incoming quote for the chart symbol; the main entry point.
OnTimer()
Called on a fixed interval set by EventSetTimer(), for work that should not depend on ticks arriving.
OrderSend(request, result)
The single call that sends every trade operation; the request struct decides what kind.
CTrade (Trade/Trade.mqh)
The standard-library wrapper most EAs use instead of filling MqlTradeRequest by hand.

Example

Almost every EA, reduced to the order the platform calls it in. None of this is strategy — it is the frame a strategy sits inside.

1. OnInit()
once, at attach
Validate inputs, create indicator handles, set the magic number.
2. OnTick()
every quote
Return immediately unless a new bar formed, then evaluate the rules.
3. OrderSend()
when a rule fires
One filled MqlTradeRequest per operation — open, modify or close.
4. OnDeinit()
once, at removal
Release handles. Open positions are not closed by this — they stay.

Removing an EA from a chart does not close what it opened. The positions remain, with nothing managing them.

Calculation if (iTime(_Symbol, PERIOD_CURRENT, 0) == lastBarTime) return;

Result A bar-close EA that ignores the thousands of ticks between decisions

How it is used

Judging an EA you did not write is a matter of evidence: the compiled file tells you nothing. Below is what to ask for.

  • Ask what data the backtest used and how it was modelled. Real ticks and a modelling quality figure mean something; an unlabelled equity curve does not.
  • Ask for the trade count and the window. The median EA published here closed 362 trades over several years; forty trades over four months is an anecdote.
  • Check whether the strategy holds losers open. Averaging down and grid recovery produce beautiful curves until the basket that does not recover, and no ratio from closed trades warns you.
  • Demo it on your own broker before funding it. Execution model, spread, contract size and symbol naming all differ, and all change results.
  • Give every instance its own magic number, and record which is which before more than two run.

Every EA listed here publishes its tested window, data source, modelling quality and full trade ledger, so this evidence can be checked rather than requested.

Common mistakes

Treating an EA as a trader with judgement

It is a rule set the platform calls on every tick. It cannot notice that the market has changed, that a central bank speaks in ten minutes, or that its own results have deteriorated — unless someone wrote a rule for exactly that.

Assuming a backtest result carries over to your account

Spread, commission, execution model, contract size and symbol set are all part of the result. A test on one broker is evidence about that broker; a demo run on your own is the cheapest way to see how much transfers.

Removing the EA to stop it, and thinking the trades stopped too

Detaching an EA leaves its open positions where they are. Nothing trails or closes them afterwards; they sit until they hit a stop, a target or a stop out.

Running several EAs on one account without separating them

Without distinct magic numbers each EA treats every position as its own to manage, and they close each other's trades. The failure is silent — no error, just results matching no single strategy.

In depth

What a real EA record looks like

A definition describes the mechanism; a record describes the experience. The fourteen EAs published here ship their full closed-trade lists — 9,702 trades since 2019.

Across the 14 published EAsValue
Closed trades9,702
Trades per EA (median)362, from 108 to 4,725
Profit factor (median)1.39, from 1.27 to 1.52
Worst losing streak (median)6 trades, worst 14
Longest stretch without a new equity high (median)423 days, worst 775
Verified live runs0

Are expert advisors profitable works through that record EA by EA, and EA vs manual trading replays the same trades under the stop rules a person actually applies.

Frequently asked questions

What is an Expert Advisor in MetaTrader 5?
A program written in MQL5 and compiled to a .ex5 file that runs inside the terminal and trades by its rules. The platform calls it on every incoming quote for the chart it is attached to, and it opens, modifies and closes orders with nobody at the keyboard.
Do I need to leave my computer on for an EA to work?
Yes — an EA runs inside the terminal, so it trades only while the terminal runs and is connected. That is why unattended EAs usually live on a VPS rather than a computer that sleeps or restarts.
Can I read the strategy inside an EA I bought?
Not from the .ex5 file. Compiled EAs run without exposing their logic, which is why sellers ship them that way. The strategy has to be described honestly in the listing and backed by published test evidence.
Can I run more than one EA on the same account?
Yes, and it is common. Each instance needs its own magic number so it manages only the positions it opened, and the account needs free margin for all of them at once — the strategies do not know about each other.