automation

Expert Advisors Explained: How MT4 and MT5 Trading Robots Execute, and What Goes Wrong

What a MetaTrader Expert Advisor is, how it reacts to ticks and sends orders, why it needs a running terminal or VPS, and the failure modes behind most EA losses, with worked numbers.

An Expert Advisor (EA) is a program written in MetaQuotes’ MQL4 or MQL5 language that runs inside the MetaTrader 4 or MetaTrader 5 trading terminal and can analyse prices and place, modify and close trades on its own. It is not a service or a person: it is code attached to a chart, and it only acts while the terminal it lives in is running and connected to your broker.

In short: an EA wakes up each time a new price (a tick) arrives, runs its rules, and if the rules say so, sends an order to the broker’s server through the terminal. It can only be as good as its rules, its connection and its broker’s execution. Most EA problems come from four places: rules that were fitted to past data, a terminal that goes offline, stops that live inside the EA rather than on the broker’s server, and execution costs the EA’s backtest assumed away.

The pitch you have probably seen

EAs are sold on marketplaces, in forums and through social media ads, usually with a backtest chart that rises in a near-straight line, a list of “set and forget” features, and a price that looks small next to the claimed returns. Some are offered free by brokers or introducing brokers, who earn from the trading volume the EA generates.

None of that tells you how the EA behaves. To judge one, you need to know what it is mechanically doing.

How an EA runs inside MetaTrader

Where it lives

According to MetaQuotes’ MetaTrader 5 help, EAs are stored in the platform’s /MQL5/Experts folder (MetaTrader 4 uses /MQL4/Experts) and are started by attaching them to a chart. Only one EA can run on one chart; starting a second one on the same chart removes the first. The platform’s AutoTrading button enables or disables automated trading for all EAs at once, and each EA also has its own permission setting.

One detail from the MetaTrader 5 help is worth knowing: disabling EAs in the platform settings “does not disable them completely”. It only stops them from trading. The code can keep running.

The tick loop

An EA is event-driven. In MQL5, the NewTick event is generated when new quotes arrive for the chart’s symbol, and the EA’s OnTick() function handles it. MQL4 works the same way.

The important part is what happens when prices arrive faster than the EA can process them. The MQL5 documentation is explicit: if a new quote arrives while OnTick() is still running, that quote is ignored, because the event is not queued. All new quotes received while the handler is running are skipped until it finishes.

In practice:

  • An EA that takes 300 milliseconds to run its logic, during a burst where ticks arrive every 100 milliseconds, sees roughly one tick in three.
  • Its decisions during fast markets are based on a thinned-out price stream.
  • A backtest that “saw” every tick does not describe that EA’s live behaviour.

Sending orders

When the rules trigger, the EA calls a trading function. In MQL4 that is OrderSend(), which includes a slippage parameter, described by MetaQuotes as the “maximum price slippage for buy or sell orders”. If the requested price is stale but still within that range, the order opens at the current price. If the price has moved beyond it, the terminal returns a requote error (error 138), and the EA has to decide whether to try again.

In MQL5, the order is described by a MqlTradeRequest structure with a deviation field: the maximum price deviation, specified in points. How much that matters depends on the broker’s execution mode for the symbol:

Execution modeWhat the EA sendsPrice risk
Request or InstantA specific price plus an allowed deviationOrder may be rejected or requoted if price moves beyond the deviation
MarketDirection, symbol and volume; no price requiredFills at whatever price the broker gives

With market execution, the order fills, but you accept the price you get. Either way, the EA’s live entry is not the price on the chart at the moment its condition was met. The cost is examined in slippage and execution on copied trades, and the same arithmetic applies to EAs.

Why EAs need a running terminal, and what a VPS does

An EA runs on whatever computer is running the terminal. If that computer sleeps, loses power or loses its internet connection, the EA stops acting. MetaQuotes’ own description of its virtual hosting service says that running a robot or a subscribed signal requires “constant connection to a trade server and uninterrupted power supply”, and that using a home PC “is not always possible and convenient”.

A virtual private server (VPS) is a rented machine in a data centre that runs the terminal around the clock. MetaQuotes notes that choosing a server close to your broker minimises network latency when sending orders. A VPS solves the “my laptop closed” problem; it does not make a losing strategy profitable.

A worked example: where the stop lives

Many EAs offer a hidden or virtual stop: rather than placing a stop-loss order on the broker’s server, the EA watches the price itself and sends a closing order when the level is hit. Sellers present this as hiding your stop from the broker. The trade-off is that the stop only exists while the EA is running.

Assume a 0.5-lot EUR/USD position, where one pip is worth about $5 (0.5 x $10 per standard lot), and a planned stop 30 pips away.

ScenarioWhat happensLoss
Stop held on the broker’s serverBroker closes the position near 30 pips (gaps can add slippage)30 x $5 = $150
Virtual stop, terminal offline while price falls 80 pipsNothing closes the trade until the EA comes back80 x $5 = $400
Virtual stop, terminal offline during a 150-pip moveSame150 x $5 = $750

The same plan, the same trade, and a loss five times larger, because the protection depended on a home computer staying awake.

Does a VPS pay for itself?

At a hypothetical $15 a month, a VPS costs $180 a year.

Account sizeVPS cost as share of account per year
$1,00018.0%
$5,0003.6%
$20,0000.9%

On a $1,000 account the EA must earn 18% a year just to cover hosting, before spreads, commissions and any purchase price. Small accounts are where EA marketing is most aggressive, and where the fixed costs bite hardest. Every recurring cost belongs in the calculation; see transaction costs in retail FX.

US accounts: the FIFO and no-hedging rule

US retail forex dealers that are NFA members must follow NFA Compliance Rule 2-43(b), effective for positions opened after May 15, 2009. It prohibits carrying offsetting positions (long and short the same pair) in one account and requires positions in the same currency pair to be closed first-in, first-out, with a limited exception for same-size trades.

Many EAs, particularly grid, hedging and “recovery” systems, open several positions in the same pair, sometimes in opposite directions, and close them in a chosen order. On a US account those systems either fail to run or behave differently from their backtest. Grid and recovery logic is unpacked in martingale and grid strategies explained.

The backtest problem

MetaTrader includes a Strategy Tester that replays historical prices through an EA. It is useful for finding bugs. As evidence of future profits, it is weak:

  • Curve fitting. With enough adjustable settings, almost any EA can be tuned to look excellent on a given stretch of history.
  • Cost assumptions. A test with a fixed narrow spread and no slippage flatters strategies that trade often for small gains.
  • Data quality. Tests on modelled ticks rather than real tick history can produce trades that could never have happened.
  • Live behaviour differs. Skipped ticks, requotes, rejected orders and outages do not appear in the tester.

These problems are covered in backtests vs live results.

Fake EA results and the demo-account trick

A screenshot of an EA’s statement can be taken from a demo account, which trades simulated money. The CFTC’s January 2024 customer advisory, AI Won’t Turn Trading Bots into Money Machines, describes the Mirror Trading International case, in which the operator promised at least 10% a month from a forex “bot” and, according to the CFTC, showed customers fake balances using MetaTrader demo accounts. In a September 2023 order, a federal court in Texas found the company liable for fraud; the CFTC had earlier obtained a default judgment against its founder, Cornelius Johannes Steynberg, involving at least 29,421 bitcoin taken from participants. The point is not that MetaTrader is unsafe. It is that a MetaTrader screen proves nothing about real money unless the account is verifiably live.

What can go wrong

  • Outages. Power, internet, terminal crashes, automatic updates and VPS maintenance all stop the EA.
  • Virtual stops. Protection that exists only inside a running program.
  • Skipped ticks and requotes. The EA’s live decisions and fills differ from its test.
  • Broker changes. Wider spreads, different execution modes, new minimum stop distances or leverage changes can break an EA that worked last month.
  • Multiple EAs, one account. Two EAs that each risk 2% can open correlated positions that together risk far more.
  • Updates and licences. A purchased EA may stop working when the seller changes the licence server or disappears.
  • The strategy itself. If the rules have no edge after costs, perfect execution only loses money more reliably.

The short version

An Expert Advisor is a MetaTrader program that reacts to price ticks and sends orders through your terminal. It ignores ticks that arrive while it is busy, it accepts the execution your broker gives it, and it stops entirely when the terminal does. Keep stops on the broker’s server, count VPS and trading costs against realistic returns, check that the logic works under US FIFO rules if you trade in the US, and treat any backtest or screenshot as a claim to test, not as evidence. For the broader picture of human versus automated systems, see manual vs automated signals.

Related: Forex Trading Bots, Honestly · Overfitting and Data Snooping · Slippage

#expert advisors#MT4#MT5#MetaTrader#VPS#automated trading