NuvoraSyncNuvoraSync
Educational guideMetaTrader6 min readUpdated June 2026

What Is a Magic Number in MetaTrader?

Every order an Expert Advisor sends in MetaTrader can carry a magic number — an integer identifier that the platform stores with the trade for its entire life. It is how an EA recognizes its own positions among everything else on the account, and how analytics can split one account history into separate strategies. The sections below cover what the magic number actually does, how manual trades fit in, how to design a numbering scheme, and the pitfalls that quietly corrupt per-strategy statistics.

Key takeaways

  • A magic number is an integer identifier an EA attaches to every order it sends; the server stores it on the resulting positions and keeps it in history.
  • EAs filter by magic number to recognize their own trades, so several EAs — or an EA and a manual trader — can share one account without interfering.
  • Manual trades carry magic number 0 by default, but trade panels and scripts are programs too and may set their own values.
  • A consistent scheme — one unique number per EA, instrument and version — keeps a trade history unambiguous for years.
  • Grouping your own account history by magic number turns one blended result into per-strategy profit, win rate and drawdown.
  • Reused magic numbers and EAs that leave the field at 0 are the two most common reasons per-strategy statistics come out wrong.

An integer tag on every order an EA sends

When an Expert Advisor opens a trade, it can include an integer in the order request — the magic number. The trade server stores that value with the order, copies it onto the resulting position, and keeps it when the trade closes into history. The platform attaches no meaning to it at all: it is a free-form label whose entire job is identification.

MT4: the magic argument of OrderSend()

An integer passed when the order is opened and read back later with OrderMagicNumber(). It cannot be changed once the order exists.

MT5: the magic field of MqlTradeRequest

Set on the trade request and carried by the resulting position (POSITION_MAGIC) and each deal (DEAL_MAGIC), so the tag survives into the full history.

Because the value is permanent, a single integer chosen once links every trade a strategy ever makes — which is what makes both automated trade management and per-strategy analytics possible.

Why an EA needs to recognize its own trades

A MetaTrader account is a shared space. Manual entries, two or three EAs and the occasional script can all hold positions at the same time, and the position list makes no distinction between them. Yet almost everything an EA does after opening a trade — trailing a stop, scaling out, closing at a session end — starts with scanning that list and asking: which of these are mine?

The magic number — usually combined with the symbol — is that filter. Without it, a trailing-stop routine would happily move stops on trades it never opened, and an “close all my positions” function would flatten the whole account, manual trades included.

One account, several strategies

The same mechanism works backwards on closed trades. Since each strategy’s trades share a magic number, the account history can be split cleanly into per-strategy groups — no guesswork about which EA produced which result.

Grouped this way, each magic number gets its own profit, win rate, average trade and drawdown instead of one blended account figure. The difference matters: an account that gained 6% over a quarter might hide one EA that made 9% and another that lost 3% — a split that only shows up when trades are grouped by magic number. Which numbers are worth tracking per group is covered in the trading journal metrics guide.

Manual trades and magic zero

Trades placed by hand — in the desktop terminal, the web platform or the mobile apps — carry magic number 0in both MT4 and MT5. In practice, zero is the de facto “manual” bucket. There are caveats worth knowing:

  • Trade panels and one-click scripts count as programs, so anything they open may arrive with its own non-zero magic number even though it felt like a manual entry.
  • Some EAs ship with a default magic input of 0 — their trades then land in the manual bucket unless the input is changed.
  • Positions closed by the server (a stop-out, for example) keep the magic number of the trade that opened them; closing never re-tags anything.
Running an EA with magic 0 on an account where you also trade by hand means neither you nor the EA can tell the trades apart — and the EA’s management logic may modify or close your manual positions.

Choosing a numbering scheme

Any positive integer works; the value comes from consistency. The common convention is one unique number per EA, instrument and version — chosen once, written down, and never reused. Encoding those three parts into the digits keeps the scheme readable at a glance:

A six-digit scheme: strategy / instrument / version

  • Digits 1–2: strategy family — 10 = trend following, 20 = breakout, 30 = mean reversion.
  • Digits 3–4: instrument — 01 = EURUSD, 02 = GBPUSD, 03 = USDJPY.
  • Digits 5–6: version — incremented whenever entry or exit logic changes.
  • Trend EA on EURUSD, version 3 → magic number 100103.
  • Same EA after a logic rewrite → 100104 — old and new results never blend.

Keep values inside the signed 32-bit range (up to 2,147,483,647): MT4 stores the magic as an int, and although MT5 accepts much larger values, staying within MT4’s limit keeps one scheme portable across both platforms. A short note listing which number maps to which EA is worth maintaining — five years of history is only as readable as that mapping.

Magic number vs order comment

MetaTrader orders also carry a free-text comment, and it is tempting to use it for identification instead. The two fields behave very differently:

How the magic number and the order comment differ
PropertyMagic numberOrder comment
TypeInteger, set by the sending programFree text, set at order time
StabilityFixed for the life of the trade — nothing can alter itBroker servers may append to or replace it, e.g. after a partial close or stop-out
FilteringMachine-readable and reliable — designed for groupingUnreliable — may be truncated, rewritten or empty by the time the trade closes
Best useStrategy identity and per-strategy analyticsHuman-readable context on an individual trade

Comments are genuinely useful as notes, but they are not identity. A history export where half the comments read “from #4711022” after partial closes is unusable for grouping — while every one of those trades still carries its original magic number.

Pitfalls that corrupt per-strategy statistics

Most magic-number problems are invisible while trading and only surface later, when the history no longer splits the way it should:

  • Reused numbers. Two EAs sharing a magic number manage each other’s trades and merge into one statistic — the most damaging mistake, and the hardest to untangle afterwards.
  • Magic left at 0. The EA’s trades become indistinguishable from manual ones, in management and in analysis alike.
  • One number across versions. If version 1 and version 2 share a magic number, a logic change that altered performance is invisible in the grouped results.
  • Same EA, several charts, same number. Management usually still works because EAs also filter by symbol, but the statistics for both symbols merge — fine if intended, misleading if not.

A clean magic-number scheme pays off most when comparing a strategy’s live trades against its test results — the subject of why live EA results differ from backtests. You can run that comparison on a Strategy Tester report with the free MetaTrader Backtest Analyzer, and on your own account history with any journal that groups trades by magic number.

Frequently asked

Can two EAs on the same account use the same magic number?

They can, but they should not. Each EA will treat the other's positions as its own — a trailing-stop routine in one can move or close trades the other opened — and any per-strategy statistics merge into a single indistinguishable line. Give every EA instance its own unique number.

What magic number do manual trades have?

Trades placed by hand in the desktop terminal, web or mobile apps carry magic number 0 in both MT4 and MT5. The caveat: trade panels and scripts are programs, so trades they place may carry their own magic number rather than 0.

Can I change the magic number of an existing trade?

No. The value is set when the order is sent and cannot be edited afterwards — not from code and not from the terminal. To re-tag a strategy, change the EA's magic number input so future trades carry the new value.

Where is the magic number set?

Most EAs expose it as an input parameter in the EA's settings dialog. In code, MQL4 passes it as the magic argument of OrderSend(), and MQL5 sets the magic field of the MqlTradeRequest structure (or CTrade::SetExpertMagicNumber when using the standard library).

Related guides

Related free tools

Free, no login required.

Related NuvoraSync features

Sources & further reading

Want to analyze your own MetaTrader account data automatically?

NuvoraSync is a read-only MetaTrader journal and analytics workspace. Connect MT4 or MT5 once and your trades, drawdown and performance update on their own — no manual entry, no signals, just your own data.

This article is for educational purposes only. It does not provide trading signals, investment advice, financial recommendations, broker recommendations or trade execution.