What Is an Expert Advisor (EA) in MetaTrader 5?
An Expert Advisor is a program that trades inside the MT5 terminal. How EAs work, what they can and cannot do, where they fail, and how to evaluate one before it touches real money.
By the AURAX teamPublished 5 min read
On this page (6)
An Expert Advisor (EA) is a program written in MQL5 that runs inside the MetaTrader 5 terminal and places, manages and closes trades on its own. It is attached to a chart, reacts to every price tick, and sends orders to your broker exactly as a manual trade would. It trades only while that terminal is open, connected and allowed to trade — which is why EAs usually run on a computer that never sleeps.
| What it is | |
|---|---|
| Language | MQL5, MetaQuotes' C++-like language for MT5 |
| Files | .mq5 source code; .ex5 compiled program (what you usually receive) |
| Where it lives | MQL5\Experts in the terminal's data folder |
| Where it runs | In your MT5 terminal — your PC, a VPS, or a hosted terminal |
| Who executes the trades | Your broker, through your account, at the broker's prices |
How an EA works
An EA is event-driven. MT5 calls into it when something happens, and the EA decides what, if anything, to do:
- On start (
OnInit): read its inputs, check the symbol and account, set up indicators. - On every tick (
OnTick): a new price arrived. This is where most EAs evaluate their rules — whether to open, add to, or close positions. - On timers and trade events: periodic checks, and reactions to fills, closures and order changes.
- On stop (
OnDeinit): removed from the chart, terminal closing, settings changed.
Inside those events an EA can read prices and indicators, inspect open positions, and send orders. What it cannot do is anything the terminal cannot: it cannot trade when MT5 is closed, cannot bypass the broker's rules, and cannot move money in or out of the account.
What EAs are good at
- Consistency. The rules run the same way at 03:00 as at 15:00, without fatigue, hesitation or revenge trading.
- Speed and coverage. Reacting within milliseconds, on every tick, around the clock of a 23-hour market like XAUUSD.
- Mechanical management. Trailing stops, basket take-profits, time filters and position limits that are tedious to run by hand.
- Testability. A fixed set of rules can be run over years of history in the Strategy Tester — something you cannot do with discretionary judgment.
Where EAs fail
An EA does exactly what it was written to do, including in conditions its author never imagined. The common failure modes:
| Failure | What it looks like |
|---|---|
| Regime change | Rules tuned for ranging markets keep firing through a strong trend (or the reverse). |
| Overfitting | Parameters that were optimised until the backtest looked perfect, and fit noise rather than behaviour. |
| Unrealistic testing | Zero spread, no slippage, no swap — results that the live account can never reproduce. |
| Infrastructure | A sleeping laptop, a lost connection or a terminal update stops the EA mid-position. |
| Unbounded risk | Strategies that add to losing positions without a hard account-level limit. |
| Silent errors | Trading disabled, wrong symbol name, a rejected order — and nobody notices for days. |
What it takes to run one
Install it
Copy the
.ex5into the terminal'sMQL5\Expertsfolder and refresh the Navigator. How to install an EA on MT5 has the exact steps.Allow it to trade
Algo trading has to be allowed in three places: the terminal options, the EA's own settings, and the Algo Trading button. How to enable algorithmic trading.
Test it
Run it in the Strategy Tester with realistic costs, then on a demo account in real time. How to backtest an EA in MT5.
Host it
Keep the terminal running and connected — usually on a VPS. Do you need a VPS?
Supervise it
Check its logs (the Experts and Journal tabs), its drawdown and its connection. An unattended EA still needs attention.
How to evaluate an EA
Before an EA trades real money, you should be able to answer these questions from evidence, not from marketing:
- What is the strategy? Trend-following, mean reversion, breakout, grid, martingale — each has a characteristic way of losing. If the seller will not say, assume the worst.
- What is the worst case? The largest drawdown in testing, and whether anything caps losses at account level. For strategies that add positions, the full exposure at maximum depth.
- How was it tested? Which modelling mode, which spread, which period — and does the period include violent markets?
- Is there live evidence? A verified live or forward record that includes the bad stretches, not just a screenshot of the good ones.
- What does it need to run? Minimum balance, leverage, broker conditions, hosting, and what happens if the connection drops mid-trade.
- Can you stop it? Pausing, closing positions and changing risk without editing code.
Common EA strategy families
| Family | Wins when | Loses when |
|---|---|---|
| Trend-following | Markets make sustained moves | Markets chop sideways (many small losses) |
| Mean reversion | Price oscillates around a level | A trend starts and does not come back |
| Breakout | Ranges resolve into strong moves | Breakouts fail and reverse |
| Grid / averaging | Price ranges and retraces | Price runs one way further than the grid can absorb |
| Scalping | Costs are low and execution fast | Spreads widen or slippage rises |
Grid strategies are popular for gold because gold often retraces, and dangerous for the same reason: the time it does not retrace is when the losses concentrate. What is grid trading? covers the mechanics.
Go deeper
Each of these takes one part of this guide further.
Sources
- Algorithmic trading, trading robots — MetaQuotes — MetaTrader 5 Help
- MQL5 Reference — MetaQuotes
Educational content, not financial advice. Trading gold and other leveraged products carries a high level of risk, including the possible loss of some or all of your capital. Automated strategies do not guarantee profit, and past or simulated performance is not indicative of future results. Risk disclosure.