StructureX

Home › Guides › Trading bots & code

MetaTrader Expert Advisor basics: what an EA really does

An Expert Advisor is a small program that runs inside MetaTrader and can place trades for you. The name sounds clever. Under the hood it's a set of rules — and you can read, test and switch off every one of them.

Beginner guide · 8-minute read · Updated 2026-10-21

What an Expert Advisor is

MetaTrader is a trading platform many forex and CFD brokers give their clients. An Expert Advisor (EA) is a program attached to one of its charts.

Every time price moves, the EA runs its rules. Depending on how it's written, it can:

"Expert" is just the name. An EA isn't an expert at anything. It's a rulebook that can click buttons.

MT4 vs MT5

There are two versions you'll hear about.

MetaTrader 4MetaTrader 5
LanguageMQL4MQL5
File types.mq4 (code), .ex4 (ready to run).mq5 (code), .ex5 (ready to run)
MarketsMostly forex and CFDsForex, CFDs, and on some brokers stocks and futures
Strategy TesterSingle-thread, simplerMulti-thread, more test modes
Code moves between them?No — needs rewritingNo — needs rewriting

Which one you use depends on your broker. New EAs are usually written for MT5. This page uses MT5 names; MT4 is similar.

The 3 functions every EA has

Inside, an EA is built around events — moments when MetaTrader calls your code:

So an EA is really: "set up, then check the rules on every price, then tidy away." See MQL5 for beginners for a full example, line by line.

Where EAs live

Compiling turns your .mq5 code into an .ex5 file MetaTrader can run. MetaEditor has a Compile button. Errors show at the bottom with line numbers.

How to switch an EA on

There are two switches, and both must be on for an EA to trade:

  1. The Algo Trading button on the main toolbar. This is the master switch for the whole platform. Off means no EA can trade.
  2. "Allow Algo Trading" in the EA's own settings, on its Common tab, when you drag it onto a chart.

When it's running, the EA's name shows in the chart's top-right corner with an icon that tells you if trading is allowed. Menu names change between versions — look for "Algo Trading" or "Auto Trading".

That master button is also your kill switch. Know where it is before you ever run an EA on real money.

Test it in the Strategy Tester first

MT5's Strategy Tester replays past prices and lets the EA trade them. Open it from the View menu (or Ctrl+R on Windows).

Pick:

Then read the report: the number of trades, the largest Drawdown (the deepest drop from a high point), the longest losing streak, and the trades themselves on the chart.

Two warnings for every test:

A backtest is hypothetical. It shows what the rules would have done, not what they'll do. See how to backtest a trading strategy.

Then run it on a demo account

Most MetaTrader brokers offer a demo account with fake money. Run the EA there for weeks before real money.

The demo shows what the tester can't: the platform closing, the internet dropping, a weekend gap. Many people run EAs on a VPS (a rented computer that stays on all day) for this reason. A VPS keeps the EA online; it doesn't make it any better.

See paper trading a bot.

The risk checks every EA needs

Before any EA touches real money — yours or one you bought — check that it has:

More: trading bot risk controls.

Be careful with EAs for sale. Many promise smooth results and hide how they lose — often by adding to losing trades or running with no stop. If you can't read the code or the rules, you can't know the risk. A seller's backtest is marketing, not proof.

Red flags in a bought EA

Questions

What is an Expert Advisor in MetaTrader?

A program attached to a MetaTrader chart that runs a set of rules on every price update. It can alert you, open and close trades, or manage stops, depending on how it's written.

Are Expert Advisors safe?

An EA is only as safe as its rules. Check for a real stop on every trade, sizing from the stop, a daily loss limit and error handling — and test it in the Strategy Tester and on a demo account first.

Can I use an MT4 EA in MT5?

Not directly. MT4 uses MQL4 and MT5 uses MQL5. The ideas carry over, but the code has to be rewritten for MT5.

How do I turn on an Expert Advisor?

Turn on the Algo Trading button on the toolbar, then tick "Allow Algo Trading" in the EA's settings when you attach it to a chart. Both switches must be on.

Do I need to keep my computer on for an EA to run?

Yes. The EA only runs while MetaTrader is open and connected. Many people use a VPS so the platform stays online, but your stops should still sit at the broker in case anything disconnects.

Want the next step? We'll walk you through it.

Four free lessons by email, one every few days — each with a 10-minute exercise on a real chart.

Send Me the Free Lessons 4 short emails · No spam · Unsubscribe anytime

Or see the whole method, step by step:

See What’s Inside the Course Try everything free first. Decide when you're ready. · Open the free chart tool (works in the TradingView phone app)

One chart idea a day, in plain English. Follow along:

Follow on XFollow on TradingView