← MT5 & Expert Advisors

Magic Numbers: How EAs Keep Track of Their Own Trades

27 Oct 2026 · 2 min read

BullsEdges algo trading guide: A magic number tags every order an Expert Advisor places. Learn why it matters, how conflicts happen and how to manage magic numbers across strategies.

When an Expert Advisor opens a trade in MetaTrader, it can attach a number to it: the magic number. It is the EA's way of saying "this one is mine". It sounds like a small detail, but many strange EA behaviours come down to magic numbers.

BullsEdges algo trading application: Assign a unique magic number to each strategy and keep it stable while that strategy still has open positions.

Why EAs need it

An account can hold trades from several sources: different EAs, different charts of the same EA, and manual trades. Before an EA modifies a stop, closes a basket or counts its open positions, it filters by:

  • the symbol, and
  • its magic number.

Without that filter, an EA could close your manual trade, or count another strategy's positions as part of its own grid.

Manual trades have magic 0

Trades opened by hand in the terminal or mobile app usually have magic number 0. Well-written EAs ignore them. But be careful: if an EA uses magic 0 itself, it may treat your manual trades as its own.

Common problems

Two EAs, same magic

If two different strategies use the same magic number on the same symbol, each one sees the other's trades. A grid EA might count a trend EA's position as a level and add to it.

Same EA on two charts

Attaching the same EA twice to the same symbol with the same magic number makes both instances manage the same trades. Orders may be duplicated or closed unexpectedly.

Manual intervention

Closing one position of an EA's basket by hand changes what the EA sees. It might reopen the level, recalculate the average, or move the take-profit. Know how your EA reacts before intervening.

Changing magic on a live EA

If you change the magic number while trades are open, the EA may "forget" those trades and leave them unmanaged - with no trailing, no basket take-profit and no safety stop.

Good practice

  1. Give every strategy its own magic number and keep a list: strategy, symbol, magic.
  2. Use different magic numbers if you run the same EA with different settings on the same account.
  3. Never change the magic while the EA has open trades.
  4. Check the history. In MT5 you can add a column showing the magic or comment, which helps you see which strategy did what.
  5. Use the order comment as a human-readable tag too, but do not rely on it - some brokers overwrite comments (for example with "[tp]" when a take-profit closes the trade).

Copy trading and analysis

When you study another trader's account or a signal, magic numbers and comments help separate different strategies on the same account - useful when one account mixes a robot with manual trading.

BullsEdges takeaway for algo trading

Magic numbers are how EAs know what belongs to them. Plan them like account numbers: unique, documented and never changed while trades are open.

Trading forex and gold carries a high level of risk and may not be suitable for every investor. Past performance and backtests do not guarantee future results. This article is education, not financial advice.

Start your 1 month free trial

Full access to the Finoways Forex & XAUUSD algo, setup support included.