Quant infrastructure
Expert Advisors, Explained: How Automated Trading on MT4/MT5 Actually Works
In October 2026, two MetaTrader 4 builds broke Expert Advisors outright — a reminder that an EA is software running inside someone else's platform. What an EA actually is, how its event loop works, and what to check before it touches real money.
Educational content, not investment advice. Trading involves risk of loss.
In brief
- An Expert Advisor is a compiled MQL4/MQL5 program that lives inside your MetaTrader terminal and trades your rules on every price tick — it only runs while the terminal is open.
- In October 2026, MT4 builds 1490 and 1491 carried a bug that stopped some EAs from loading at all; build 1492 fixed it. The terminal can look fine while the automation underneath is not working.
- The core discipline is the event loop: OnTick fires on every tick, so a careful EA trades only on a new bar, risks a fixed share of equity, and always attaches a stop.
- In the executed demo, the same SMA-crossover logic produced 17 crossover signals and 8 closed trades on 500 synthetic bars — final equity $108,810.92 from $100,000, max drawdown 1.50%. Synthetic data: a logic check, not a return to expect.
On this page
The short answer
An Expert Advisor (EA) is a compiled program that lives inside your MetaTrader terminal and trades your rules for you. It watches every price tick, checks your conditions, and sends orders to your broker — no clicking, no 3 a.m. chart checks. In October 2026, MetaTrader 4 builds 1490 and 1491 shipped a bug that stopped some EAs from loading at all, and MetaQuotes had to rush out build 1492 to fix it. That is the whole story of EAs in one incident: the automation is only as reliable as the platform it runs inside, and the terminal can look perfectly fine while the strategy underneath has quietly stopped working.
What an Expert Advisor actually is
An EA is not a cloud service and not a separate app. It is a compiled file — .ex4 on MT4, .ex5 on MT5 — written in MetaQuotes' own language (MQL4 or MQL5) and attached to a chart inside the terminal. While that terminal is open and connected, the EA is alive. Close the laptop, lose the connection, or let the terminal crash, and the EA stops with it. That is why anyone running an EA seriously puts the terminal on a VPS that never sleeps.
The EA does three things, in a loop: read market data, apply your rules, send trade requests. It cannot do anything you did not program into it, and it cannot improvise. If your rule says "buy when the fast average crosses above the slow one," it will buy on every cross — including the tenth whipsaw cross in a sideways market. The discipline is in the rules, not in the program.
The event loop: where the logic lives
MetaTrader runs EAs on events, and each event has its own handler function:
- OnInit runs once, when the EA loads. Validate your inputs here — bad parameters should fail loudly at load time, not silently at 2 a.m.
- OnTick fires on every price update. This is where your core trade logic lives, and it is also where most EAs go wrong.
- OnTimer fires on a fixed interval, useful for checks that should not depend on price movement.
- OnDeinit runs when the EA is removed or the terminal closes. Use it for cleanup.
The single most important discipline in OnTick is the new-bar guard. OnTick fires on every tick, but a signal computed mid-bar can appear and disappear before the bar closes — the EA equivalent of repainting. A careful EA checks whether a new bar has opened and does nothing on any other tick. Everything in the example below hangs on that one guard.
MT4 vs MT5: the differences that matter
MT4 and MT5 look similar on the surface. Underneath, an EA written for one does not run on the other.
MT4 runs MQL4 EAs, defaults to hedging (multiple positions per symbol), and is the platform most retail forex traders still use. MetaQuotes no longer sells new MT4 licenses and reserves new features for MT5 — but it still ships MT4 builds, and build 1490 (October 2, 2026) changed how stop loss and take profit behave under FIFO rules: when several positions are open on the same symbol, new stop and target levels now apply to all of them. If your EA manages stops per position, that change touches your logic directly.
MT5 runs MQL5 EAs, defaults to netting (one position per symbol), covers more asset classes, and has the stronger tester: it is multi-currency, multi-threaded, and can replay real ticks your broker recorded, spread changes included. Its build 6230 (September 24, 2026) extended the built-in AI Assistant so it can retrieve an EA's input parameters and prepare Strategy Tester runs. The tester is covered in depth in how to backtest a strategy in MetaTrader 5's Strategy Tester — read that before you trust any EA result.
A complete EA you can read
This is a full working skeleton: a long-only SMA crossover that trades once per new bar, risks 1% of equity per trade, and always attaches a stop and a target. It is the same logic as the demo run below.
// SMA-crossover EA — long-only, new bar only, 1% risk per trade
#include <Trade\Trade.mqh>
CTrade trade;
input int FastPeriod = 10;
input int SlowPeriod = 30;
input double RiskPct = 1.0; // % of equity risked per trade
input double StopATR = 2.0; // stop distance, in ATR multiples
input double TargetR = 2.0; // target, as a multiple of risk
datetime lastBarTime = 0;
int OnInit() { return(INIT_SUCCEEDED); }
void OnTick()
{
// Trade once per new bar — intrabar ticks would repaint signals.
datetime barTime = iTime(_Symbol, PERIOD_CURRENT, 0);
if(barTime == lastBarTime) return;
lastBarTime = barTime;
double fast[], slow[], atr[];
CopyBuffer(iMA(_Symbol, PERIOD_CURRENT, FastPeriod, 0, MODE_SMA, PRICE_CLOSE), 0, 0, 3, fast);
CopyBuffer(iMA(_Symbol, PERIOD_CURRENT, SlowPeriod, 0, MODE_SMA, PRICE_CLOSE), 0, 0, 3, slow);
CopyBuffer(iATR(_Symbol, PERIOD_CURRENT, 14), 0, 0, 2, atr);
bool crossUp = fast[1] <= slow[1] && fast[0] > slow[0];
if(!crossUp || PositionSelect(_Symbol)) return;
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double stopDist = StopATR * atr[0];
double riskMoney = AccountInfoDouble(ACCOUNT_EQUITY) * RiskPct / 100.0;
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double lossPerLot = (stopDist / tickSize) * tickValue;
double volume = riskMoney / lossPerLot;
trade.Buy(volume, _Symbol, ask, ask - stopDist, ask + TargetR * stopDist, "SMA cross");
}
Note what the code does not do: it never trades without a stop, it never sizes by gut feel, and it never acts twice on the same bar. Those three omissions are most of what separates an EA that survives from one that blows up.
What the demo run shows
The identical logic was executed in Python on 500 synthetic bars (seed 42) to check the mechanics end to end: 17 crossover signals, 8 closed trades, 5 winners, final equity $108,810.92 from $100,000, maximum drawdown 1.50%. That is a logic check on made-up data, not a return to expect — a 500-bar random walk proves the code runs and the risk math works, nothing more. Any EA vendor quoting backtest profits without showing the test conditions is selling the demo, not the strategy. The same sizing logic, the same stop discipline, and the same new-bar rule are what automating a trading strategy end to end builds into a full five-stage loop.
Where EAs actually break
Most EA failures are not strategy failures. They are infrastructure failures, and October 2026 gave a clean example. Builds 1490 and 1491 carried a defect in loading EX4 files: indicators appeared in the Navigator but never drew on the chart, timer callbacks never fired, and at least one EA entered a continuous error loop after upgrading. MetaQuotes acknowledged the bug on October 5, and broker FXTF confirmed on October 7 that build 1492 resolves it. No verified monetary losses were documented — but an EA that never receives its expected event simply does nothing, and "does nothing" leaves no error message to investigate.
The rest of the failure list is permanent: overfitting to the tester (its fastest modes generate ticks from minute bars, so spread spikes at news mostly do not exist in the test — use "every tick based on real ticks" for final checks), a VPS that reboots mid-trade, a broker whose spreads widen at rollover, and an EA with no kill switch. The fix for each is boring and specific: test on real ticks, run a demo account on the same broker first, log every decision, and set a drawdown limit that halts the strategy automatically.
What to do before it touches real money
- Run it in the Strategy Tester on real ticks, then walk it forward on data it has never seen.
- Run it on a demo account with the same broker, spread and leverage as your live account.
- Read the logs for a week. An EA that trades without logging is un-auditable.
- Start live small, with a kill switch: a drawdown limit that stops the EA before you have to.
- Keep the terminal on a VPS, and check the build number after every MetaTrader update — October 2026 proved an update can break the automation silently.
If the strategy is yours but the engineering is not, that is exactly what the desk is for: an embedded engineer who builds the EA, grades it against out-of-sample data, and wires in the monitoring and kill switch — the same desk behind the MetaTrader guide for systematic traders. And if you would rather have an engineering team build and run the system for your business, BlackShore Agency works on retainer, with a senior engineer who owns the build. Either way, the rule is the same: the EA is code, the platform is someone else's, and the risk controls are yours to set before the first live tick.
Frequently asked questions
What is an Expert Advisor?
An Expert Advisor is a compiled program (MQL4 on MT4, MQL5 on MT5) that runs inside the MetaTrader terminal. It watches price ticks, checks your rules, and sends orders to your broker automatically. It only runs while the terminal is open — which is why most serious users run it on a VPS.
Does the same Expert Advisor work on MT4 and MT5?
No. MT4 runs MQL4 EAs and MT5 runs MQL5 EAs — the languages and the platform internals differ (MT5 defaults to netting, MT4 to hedging; MT5's tester is multi-currency with real ticks). An EA written for one does not run on the other without a rewrite.
How do I know an Expert Advisor is safe to run live?
Test it in the Strategy Tester on real ticks, then walk it forward on out-of-sample data, then run it on a demo account with the same broker, spread and leverage as your live account. Only then consider live money — with a small size and a kill switch that halts it at a drawdown limit you set in advance.
What happened to Expert Advisors in the October 2026 MT4 update?
Builds 1490 and 1491 (October 2026) carried a bug that could stop EX4 files — the compiled format for EAs and indicators — from loading. Some EAs looked attached but never received timer events or indicator data. MetaQuotes acknowledged the defect on October 5 and shipped the fix in build 1492, confirmed by broker FXTF on October 7.
Sources
- Dave Finances — MetaQuotes Pushes MT4 Build 1492 After Builds 1490 and 1491 Break EAs and Indicators (Oct 7, 2026)
- MetaQuotes / MQL5 — Introduction to MetaTrader 5 Strategy Tester
- Edgoro — MT5 Strategy Tester modelling modes explained (Nov 10, 2026)
- FinCode Labs — MT4 API: MQL4, broker-side APIs and Python routes (build 1490, Oct 2, 2026)
Related reading
- GuideAutomating a Trading Strategy End to End: From Signal to Live OrdersAutomating a strategy is five stages, not one: signal, sizing, order, execution, monitoring. Most people automate two of them. Here is the full loop, with code you can run.5 min read
- GuideYour thinkScript Strategy Can't Leave ThinkorSwim — Here's the BridgeA thinkScript strategy is a backtest drawn on a chart. It cannot place a live order, send a webhook, or call an outside service — Schwab's own documentation says so. Here are the three ways out, with the same 10/30 crossover written in thinkScript and in Python.6 min read
- GuidePython Just Arrived in cTrader — Your First cBot in an AfternoonPython developers no longer need C# to automate on cTrader. A complete first cBot — a 10/30 crossover — its logic run on 500 synthetic bars, and the four gaps between a passing backtest and a live system.4 min read
- GuideYour First NinjaTrader Strategy: From AI Strategy Builder to a Live Futures SystemNinjaTrader 8.1.9 shipped the AI Strategy Builder out of beta on November 10, 2026: plain English in, compiled NinjaScript and an instant backtest out. A backtest is not a live system — here is what it proves and the four gaps to live orders.5 min read