Skip to content
MT5MT4soonTradingViewsooncTradersoonNinjaTradersoonPythonsoon

What Is an Expert Advisor? How an EA Trades Forex for You

beginner9 min readOct 6, 20262 viewsUpdated Nov 1
Learn Forex from zero · lesson 44 of 47 · chapter 6

An expert advisor (EA) is a program that runs inside your trading platform and trades for you by fixed, mechanical rules. It analyses the market, decides when a setup matches its rules, then opens and closes trades with no emotional input. Whoever wrote the EA chose its rules; you choose its settings and how much it risks. The EA carries them out every time.

That cuts both ways. An EA repeats a good rule without hesitating, and it repeats a bad rule just as faithfully, with your money, while you are asleep. If you understand what is happening inside it, you can tell the difference before it costs you.

An EA is a file attached to a chart, so it stops when your platform stops

The term comes from MetaTrader, where an EA is written in MetaQuotes Language (MQL4 or MQL5, which aren't interchangeable).

An EA isn't a standalone app you double-click: it is code compiled into a file the platform runs. You attach it to a price chart inside the platform, and it trades the symbol on that chart.

That has one practical consequence beginners miss. The EA only works while the platform it is attached to is open, logged in and connected. If the computer sleeps, the internet drops or the platform closes, the EA stops making decisions. Any open trades stay in the market, protected only by the stop-loss and take-profit already sent to the broker.

What stops and what stays at the broker when the platform running an EA goes offline
Once the platform is offline, the only protection left is the stop-loss and take-profit that already sit on the broker's server.

How an expert advisor works: rules, triggers and a five-step cycle

An EA does not run continuously like a person watching a screen. It wakes up when an event happens, runs its rules once, then waits for the next event.

The most common event is a new tick, which is a new price quote arriving from your broker. On a busy pair that can happen many times a second. Other events can also trigger an EA: a timer going off, a trade being opened or closed on your account, or something happening on the chart.

Each time it wakes up, the EA goes through the same cycle. It scans for its setup. If the setup is there, it creates a signal. Then it applies its risk rules: how big the position is, and where the stop-loss and take-profit go (the prices where the trade closes automatically at a loss or at a profit). Only then does it send the order. The flow below shows that cycle.

The operating cycle of an expert advisor on each new price tick
  1. 1New tick arrivesA fresh price wakes the EA up
  2. 2Scan for setupCheck the rules against current prices
  3. 3Generate signalRules met: buy or sell
  4. 4Size and set stopsWork out lot size, stop-loss, take-profit
  5. 5Send orderThe market order goes to the broker
The EA repeats this cycle on every event. Most ticks end at step 2 with no trade.

This is why an EA is only as good as its rules. It cannot "sense" that the news looks scary or that the market feels different today. If a condition isn't written into the code, the EA doesn't know about it.

Signal-only EAs vs fully automated robots: who presses the button

Not every EA trades on its own. You can set some up to only produce a signal, such as an alert or arrow, and leave the decision to you. Others place and close every trade themselves. Some people call the second kind a "forex robot".

The comparison below shows what changes between the two, next to plain manual trading.

Manual trading vs signal-only EA vs fully automated EA
Manual trading
  • –You find setups
  • –You place every order
  • –You close every trade
  • –Emotion can bend the rules
Signal-only EA
  • –EA finds setups
  • –You confirm each trade
  • –You can skip bad timing
  • –You still need to be at the screen
Fully automated EA
  • –EA finds setups
  • –EA places the order
  • –EA closes the trade
  • –Mistakes in the rules repeat unchecked

Even a fully automated EA leaves you with jobs. You choose the account, the symbol, the lot or risk setting, and the maximum loss you will accept. You check that it's running, and you decide when to switch it off.

Decision rule: if you can't yet explain why the EA would take a trade, keep it in signal-only mode. Wait until you can predict what it will do before you let it press the button with real money.

Types of EA: trend-following, grid, martingale, scalper and breakout

Most EAs belong to one of a few families. Each family enters a trade on a different trigger, places its stop in a different spot and tends to fail in its own way.

EA typeWhat triggers a tradeWhere the stop sitsHow it usually blows up
Trend-followingPrice closes beyond a moving average or breaks a recent high or low in the trend's directionBeyond the recent swing, or a fixed distance from entryLong sideways markets bring one small loss after another until the losses add up
GridOrders sit at fixed gaps above and below price and fill as price moves through themOften no stop on each order, only a loss limit on the whole basket, or none at allPrice trends a long way in one direction, the losing orders pile up and the combined loss swamps the account
MartingaleAny entry rule, but the next trade is bigger after each lossUsually a fixed distance on each tradeA losing streak pushes the lot size beyond what the account can carry
ScalperSmall, short-lived price moves, aiming for a few pips eachVery tight, a few pips from entryWider spreads or slippage live eat the small gains a test showed
News / breakoutPrice breaking out of a range, often around a scheduled news releaseOn the other side of the rangeFalse breakouts, plus fast prices that fill the stop well past its level

A worked example: one EA trade with the numbers shown

A worked example: one EA trade with the numbers shown

The figures here are an illustrative example. Suppose you have an EA with a simple rule on the 1-hour EUR/USD chart: buy when a candle closes above a moving average, risk 1% of the account, set a 20-pip stop-loss and a 40-pip take-profit. A pip is the fourth decimal on EUR/USD. The chart below shows the candle that triggers the EA: earlier candles poke above the average but close below it, so nothing happens. Only a close above the line counts, and the EA buys as the next candle opens.

1-hour EUR/USD candles: the close above the moving average that triggers the example EA's buyIllustration
Moving average1.0990Signal: close above averageEA buys
A wick above the average is not enough. The EA acts only after a candle closes above it. The average is drawn flat here for simplicity.

Your account equity is $1,000. Equity is your balance plus or minus the profit or loss on any open trades.

On EUR/USD, one micro lot (1,000 units) is worth about $0.10 per pip. The calculation below shows how the EA turns the 1% risk into a position size.

How the example EA sizes a EUR/USD trade from 1% risk and a 20-pip stop
Risk in money$1,000 × 1%= $10
Risk per micro lot20 × $0.10= $2
Micro lots$10 ÷ $2= 5
Potential profit40 × $0.10 × 5= $20
Order size5 micro lots (0.05 lots)

The order window shows 5 micro lots as 0.05 lots.

The signal fires and the EA sends a market order. A buy fills at the ask price, the higher of the two quoted prices. The chart plots the bid, so the candle marked "EA buys" opens at 1.0998. In this example the ask is 2 pips above the bid, which is why the buy fills at 1.1000, slightly above where the chart shows price. The EA places the stop at 1.0980 and the take-profit at 1.1040, as the ladder below shows.

Example EA buy trade on EUR/USD: entry, stop-loss and take-profitIllustration
Risk: 20 pipsTake profit (+40 pips, +$20)1.1040Entry at ask1.1000Stop loss (-20 pips, -$10)1.0980

Now suppose the stop is hit. Equity falls to $1,000 − $10 = $990. On the next signal the EA works out the size again:

  • 1% of $990 = $9.90.
  • $9.90 ÷ $2 per micro lot = 4.95 micro lots.
  • In this example the smallest step is one micro lot (0.01 lots), so a well-written EA rounds down to 4 micro lots (0.04 lots). That risks 4 × $2 = $8.

This gives you a way to check any EA's settings. Look for how it rounds. An EA that rounds up would take 5 micro lots and risk $10, which is more than the 1% you asked for. Compare the lot sizes in the EA's trade history with your own sums.

Rounding an EA lot size down vs up against the 1% risk limit on a $990 account
Rounding down to 0.04 lots keeps the risk at $8, under the 1% limit. Rounding up to 0.05 lots risks $10, which is more than the $9.90 you asked for.

Mistakes that cost beginners money with EAs

Running a martingale EA without doing the math. A martingale EA doubles the position size after every loss. As long as the take-profit is at least as far from entry as the stop-loss, one win wins back all the earlier losses. With a closer take-profit it doesn't. Here is the same example account with a 20-pip stop and take-profit, starting at 0.01 lots (one micro lot, $2 risk). Five losses in a row cost $2 + $4 + $8 + $16 + $32 = $62. The sixth trade is 0.32 lots and risks $64.

Money at risk on each trade of a martingale EA after consecutive lossesIllustration
Trade 1 (0.01)
$2
Trade 2 (0.02)
$4
Trade 3 (0.04)
$8
Trade 4 (0.08)
$16
Trade 5 (0.16)
$32
Trade 6 (0.32)
$64

If trade six wins, you make $64 − $62 = $2 in total. If it loses, you are down $62 + $64 = $126, which is 12.6% of a $1,000 account, and trade seven would risk $128. You risk more than a hundred dollars to make two. An expensive price tag on a martingale EA doesn't change this arithmetic.

Trusting a short, perfect backtest. A backtest is a run of the EA on past prices. Curve-fitting means tuning an EA's settings until they match past prices almost perfectly. The backtest looks smooth, but the rules learned the noise in that one stretch of history. A test covering only a year or two, often just one trending period, is the usual warning sign. Ask for results across several years and different market conditions.

Ignoring the spread. A buy opens at the ask and closes at the bid (a sell is the reverse), so every trade starts a little negative by the bid-ask spread. An EA that aims for a few pips per trade can look profitable in a test with tight spreads and lose live when spreads widen.

Forgetting that the platform must allow automated trading. Trading platforms have a master switch that permits or blocks automated trading. If it's off, the EA sits on the chart and does nothing. Beginners often blame the EA when the cause is this switch.

Checklist before you let an EA trade real money

Run through this list with any EA, free or paid:

  • Can you state its rules in one sentence? "Buys a close above the average, 1% risk, 20-pip stop." If the seller can't tell you, don't run it.
  • Is a stop-loss sent to the broker on every trade, not only held inside the EA? Check the trade history, not the sales page.
  • Does any trade follow a loss with a bigger lot? Open the trade history and look for any lot size larger than the one on the losing trade just before it. One such trade is enough to treat it as a martingale EA.
  • Does the backtest hold up on prices it wasn't tuned on? Ask which period the settings were optimised on. Then backtest the EA with the same settings on a different stretch of history. If the results fall apart, the settings were fitted to the past.
  • Has it run on a demo account for at least a few dozen trades? A demo uses live prices and virtual money, so it shows spreads that change through the day. It doesn't show real execution: the broker simulates demo fills, and slippage on a demo can differ from live. Pass the demo, then run it on a small live account before you size up.
  • What is your exit rule for the EA itself? Write down the drawdown, the fall from your account's peak, at which you switch it off, before you start.

FAQ

Can I run an expert advisor from my phone?

Not on the phone itself. Desktop-style EAs do not run inside the usual mobile trading apps. The EA has to be attached to a chart on a computer or a remote server that stays switched on, logged in and connected. Your phone only monitors the trades the EA opens on that account.

Do I need to know how to code to use an EA?

No. Using a ready-made EA means installing it, attaching it to a chart and setting its inputs, such as lot size or risk percent, stop distance and trading hours. Coding only matters if you want to build your own. That means learning the platform's programming language and compiling the code before it can run.

Do I need a VPS to run an EA 24 hours a day?

Not strictly, but it is the usual answer. A home computer works only if it never sleeps, restarts for updates or loses power or internet. A VPS (virtual private server) is a computer in a data centre that you rent and log into remotely. You install the trading platform on it, attach the EA to a chart there, and it keeps running when your own computer is switched off.

Part of Expert Advisors & automation: more guides, terms and free tools on this subject.