A magic number is how an Expert Advisor tells its own trades apart from everyone else's. Two EAs sharing one number is not a cosmetic bug — it means each bot can close, modify or trail the other's positions, and your reporting stops meaning anything. The failure is silent until the day it costs you a trade.
What the magic number actually does
When an EA opens an order it stamps it with a MagicNumber. From then on the EA only touches positions carrying its own stamp: it filters by magic number before trailing a stop, moving to breakeven, or counting how many trades it already has open. Manual trades have magic number 0. If two EAs use the same value, each sees the other's positions as its own — one bot's breakeven logic yanks the stop on a trade the other bot is still nursing, and a "max 3 open trades" cap counts double.
One EA instance, one symbol, one magic number. If any two order-managing components can both claim a trade, you have a collision — even if it has not misfired yet.
The subtle part: it's per instance, not per EA file
The mistake that catches experienced traders isn't two different EAs colliding — it's the same EA run twice. Load "Trend Rider" on EURUSD and again on GBPUSD with the default magic number baked into the set file, and both charts stamp trades 20501. Now the EURUSD instance counts the GBPUSD positions toward its own limits and can manage them on a tick. The rule is one magic number per running instance, and for multi-symbol setups you usually want it to vary by symbol too.
A numbering scheme that scales
Random numbers work until you have forty of them and no idea which is which. Build a readable scheme instead. A common pattern is a base per strategy plus an offset per symbol:
- Strategy blocks of 100. Trend Rider = 1000–1099, Grid Master = 1100–1199, Scalper Pro = 1200–1299.
- Symbol as the offset. Inside a block, EURUSD = +01, GBPUSD = +02, XAUUSD = +03. So Trend Rider on GBPUSD is
1002, Scalper Pro on gold is1203. - Reserve 0 for manual trades and never assign it to an EA.
Reading 1203 back, you instantly know the strategy and the symbol. Worked through: five strategies across six symbols is thirty running instances, thirty distinct numbers, and each is self-documenting — no lookup table needed.
Common mistakes when you run dozens
- Copying a set file to a new chart and forgetting to change the magic. The single most frequent collision. The set file carries the old number with it.
- Reusing a number from a decommissioned EA while its old positions or pending orders are still on the account. The new EA adopts the ghost trades.
- Different values on MT4 and MT5 that happen to overlap. Magic numbers are per-account, not per-platform — if two terminals trade the same broker account, their numbers share one space and must not clash.
- Broker or account limits. MT4 magic numbers are a 32-bit integer, while in MT5 the magic number is a 64-bit integer (ulong), so don't needlessly cap MT5 values to the 32-bit range; keep values comfortably inside the applicable range and avoid negative or absurdly large numbers that some bridges truncate.
- No written registry. If the only record of which number is where lives in your head, the next collision is a matter of time.
Fixing a collision safely
Never renumber an EA that has open positions carrying the old magic — the moment you change it, those trades become orphans the EA no longer recognizes, so it will neither trail nor close them. The safe sequence is:
- Flatten or manually take over the affected positions first, or wait until the instance is flat.
- Change the magic number in the set file and reload the EA.
- Confirm the new number is unique across every terminal hitting that account, not just the one you edited.
Use the manager
The Magic Number Manager does the bookkeeping for you. Paste your Expert Advisors one per line — name and current magic number, or just the name for anything unassigned — and it flags every duplicate, keeps each number that is already unique, and reassigns only the clashing ones to the next free slot from a base you choose. It shows totals for conflicts and reassignments so you can see at a glance whether your fleet is clean, and the result is deterministic, so the same input always produces the same scheme.
Takeaway
Treat magic numbers as a namespace you design once and defend forever: one per running instance, a readable scheme that encodes strategy and symbol, and a written registry across every account. Check for duplicates before you deploy, not after a trade gets managed by the wrong bot — because that failure never announces itself.