On this page
Back to tutorials

What Is an Expert Advisor (EA) in MT5? Beginner Guide + EA Structure

New to EAs? Learn what Expert Advisors are, how they work in MetaTrader 5, and why they're essential for automated trading. Covers EA architecture (OnInit, OnTick, OnDeinit) and how to deploy them.

📖 12 min read

📝 2,400 words

🏷️ MQL5 & Expert Advisors

Share this article:

Try the workflow from this guide

Open the live demo first — no signup. Sign up later to save your strategy and export from Code Generator.


Why Automated Trading Changes Everything

Forex and CFDs trade 24 hours a day, five days a week. Miss a setup at 3 AM? A breakout while you sleep? Human traders face an impossible challenge: staying alert around the clock while avoiding the emotional traps of fear and greed. This is exactly where Expert Advisors (EAs) step in — automated trading programs that never sleep, never hesitate, and never deviate from your rules.

In this guide, you'll learn what an Expert Advisor is, how it works in MetaTrader 5, and why it has become the backbone of algorithmic trading for millions of traders worldwide.

Related guides: Create and Edit an MT5 EA · MQL5 Environment Setup · MQL5 Programming Reference · Backtest EA in MT5 Strategy Tester · Build EA Without Coding


What is an Expert Advisor?

An Expert Advisor (EA) is a software program built for MetaTrader 4 (MT4) or MetaTrader 5 (MT5) that automates trading based on pre-programmed algorithmic rules. According to MetaTrader 5's official documentation, EAs belong to the category of trading robots — applications designed to perform trading operations autonomously.

Unlike discretionary trading, where you decide each trade manually, an EA:

  • Scans markets continuously for setups matching its rules
  • Generates buy/sell signals using technical indicators (RSI, MACD, moving averages, etc.)
  • Executes trades automatically or alerts you for manual confirmation
  • Manages risk through stop-loss, take-profit, and position sizing — without emotional interference

EAs are written in MQL5 (MetaQuotes Language 5) for MetaTrader 5, or MQL4 for MetaTrader 4. They run directly on your chart, attached to a specific symbol and timeframe, and react to every new price tick.


EA vs Indicator vs Script: What's the Difference?

MetaTrader 5 offers several types of automated applications. Understanding the difference helps you choose the right tool:

TypePurposeRuns onCan Trade?
Expert Advisor (EA)Performs trading operations autonomouslyAttached to a chart✅ Yes
Custom IndicatorAnalyzes prices, displays signals on chartApplied to a chart❌ No
ScriptOne-time or scheduled taskManual run✅ Yes (if allowed)

Key insight: Indicators can be used inside Expert Advisors. An EA might call RSI, MACD, or Bollinger Bands to generate signals — forming a complete automated trading system. As MetaTrader 5 Help states: "Indicators can be used directly in trading robots forming a complete automated trading system."


How Expert Advisors Work

Every EA follows a clear lifecycle. When you attach it to a chart, MetaTrader 5 calls three main functions:

1. OnInit() — Initialization

Runs once when the EA starts. Here the EA:

  • Creates indicator handles (e.g., RSI, MA)
  • Validates inputs (lot size, stop loss, etc.)
  • Sets up buffers and variables

If initialization fails, the EA stops and shows an error.

2. OnTick() — The Heart of the EA

Runs on every new price tick. This is where the magic happens:

  • Market scan — Check if current price/indicators match entry conditions
  • Signal generation — Buy, sell, or hold?
  • Trade execution — Send orders via OrderSend()
  • Risk management — Update trailing stops, check position limits

Most EAs use OnTick() to react to every tick, or they filter for "new bar" only to avoid repeated logic on the same candle.

3. OnDeinit() — Cleanup

Runs when the EA is removed from the chart or the terminal closes. The EA releases indicator handles, clears resources, and can write a summary to the log.


Key Benefits of Using Expert Advisors

🧠 No Emotional Trading

Fear and greed drive most retail trading losses. An EA follows its rules exactly — no hesitation, no revenge trading, no chasing. Research consistently shows that emotional discipline is a major factor in long-term success. EAs enforce that discipline by design.

⏰ 24/7 Operation

Forex trades around the clock. An EA can monitor London, New York, and Tokyo sessions without you staring at the screen. Deploy it on a VPS (Virtual Private Server) and it runs even when your PC is off.

📐 Consistency

The same rules, every time. No "I'll skip this one" or "just this once." Backtested logic executes identically in live markets — giving you a fair assessment of whether your strategy actually works.

🔬 Backtesting Before Risk

MetaTrader 5's Strategy Tester lets you run your EA on years of historical data. You can optimize parameters, measure drawdown, and validate logic before risking a single dollar. This is one of the most powerful features of algorithmic trading.

Many traders prototype their strategy logic visually first — using no-code tools to test ideas, tweak indicators, and refine risk rules before writing MQL5. If your rules are already if/then (not discretion), sketch them in the live Strategy Builder demo before you type MQL5 — you will know what to code.


Types of Expert Advisors

EAs come in many flavors, each suited to different market conditions and trading styles:

  • Trend-following EAs — Trade in the direction of the trend using moving averages, ADX, or breakout logic
  • Scalping EAs — Target small profits on short timeframes (M1, M5) with tight spreads
  • Grid EAs — Place orders at regular price intervals to profit from ranging markets
  • News traders — React to economic releases and volatility spikes
  • Breakout EAs — Enter when price breaks support/resistance or consolidations
  • Hedge EAs — Manage hedged positions across accounts or symbols

Choosing the right type depends on your market view, risk tolerance, and the instruments you trade.


EA Architecture: One Chart, One EA

Important: Only one Expert Advisor can run on one chart at a time. If you attach a second EA, the first is removed. To run multiple EAs (e.g., different strategies on EUR/USD and GBP/USD), open separate charts and attach one EA per chart.

EAs can be enabled or disabled for trading via the AutoTrading button in the toolbar. Even when disabled, the EA continues to run and analyze — it just won't place orders. This is useful when you want to observe signals without executing.


Limitations to Keep in Mind

  • Your computer must be on — Unless you use a VPS, the EA stops when MetaTrader closes
  • No profit guarantee — Past backtest results don't guarantee future performance. Overfitting and changing market conditions can erode edge
  • Spread and slippage — Live execution differs from backtests; account for real-world costs
  • Broker dependency — EAs behave differently across brokers due to spreads, execution speed, and server time

Getting Started: Next Steps

Now that you understand what an Expert Advisor is, you're ready to build your first one. Start with How to Create and Edit an MT5 Expert Advisor (Wizard, code, or no-code), then follow MQL5 Environment Setup to install MetaTrader 5, MetaEditor, and run your first EA in the Strategy Tester.

No-code path: If Wizard templates feel tight, follow Build EA Without Coding — complete Steps 1–3 in the live demo before you decide whether you still need to learn MQL5 syntax.

Build this EA in Strategy Builder

Start in the live demo — no signup required. Walk through signals, filters, and risk. Create a free account only when you want to save and export MQL5.

Frequently Asked Questions

An Expert Advisor is a trading robot for MetaTrader 4 or 5 that runs on your chart and executes trades automatically based on rules you (or a developer) programmed. It can scan the market, generate signals with indicators like RSI or moving averages, and place orders 24/5 without you being at the screen.

When you attach an EA to a chart, MetaTrader calls three main functions: OnInit() (runs once at start — setup and validation), OnTick() (runs on every price tick — where signals and orders are handled), and OnDeinit() (runs when the EA is removed — cleanup). The EA keeps running as long as the chart is open and AutoTrading is enabled.

Yes. Once attached to a chart and with AutoTrading turned on, an EA can open and close trades by itself according to its code. You can also configure some EAs to only show alerts and let you confirm trades manually.

An Expert Advisor can place trades; an indicator only analyzes price and draws on the chart — it cannot trade. Indicators are often used inside EAs to generate signals (e.g. RSI, MACD), so the EA is the "brain" that decides when to buy or sell.

Yes, if MetaTrader is running on your PC, the PC must stay on (and MetaTrader open) for the EA to run. Many traders use a VPS (Virtual Private Server) so the EA runs 24/7 even when their own computer is off.

There is no guarantee. EAs run your strategy consistently, but profitability depends on the strategy, market conditions, broker execution, and risk settings. Always backtest and use a demo account before going live.

Try Strategy Builder — no signup

Try Strategy Builder — No Signup