EA Magic Numbers: What They Are & Why They Matter (2026)

Quick Answer

An EA magic number is a unique integer identifier that an Expert Advisor assigns to every trade it opens. It lets the EA tell its own trades apart from manual trades and from trades placed by other EAs. Each EA on your account should have a unique magic number. If you're running only one EA with no manual trading, the default value (often 0 or a preset) works fine. Golden Viper EA sets this automatically, but you can customize it in the Inputs tab.

EA magic numbers look like a minor technical detail, but getting them wrong causes real problems, especially once you're running multiple Expert Advisors on the same account. I've seen traders lose money because two EAs shared the same magic number and ended up closing each other's trades. Here's what you need to know about EA magic numbers in MetaTrader 4 and MT5, from the basic concept through to advanced multi-EA configurations.

What Is an EA Magic Number?

A magic number is simply a number that an EA attaches to every trade it opens, much like a name tag on a package identifies who sent it and who should receive it. In MetaTrader, the EA magic number tells the platform which EA "owns" each specific trade.

Technical Specifications

  • Data type: Integer (whole number, no decimals)
  • Valid range: 0 to 2,147,483,647
  • Default value: Usually 0 or a preset defined by the EA developer
  • Storage: Recorded with each order in the MT4/MT5 trade server
  • Visibility: Not shown by default in the terminal; check the "Magic" column in trade history

What It Looks Like in Practice

When an EA opens trades, the magic number is attached invisibly to each order:

  • Trade #12345678, XAUUSD Buy 0.10 lot, Magic: 55555 (opened by EA)
  • Trade #12345679, XAUUSD Sell 0.05 lot, Magic: 55555 (opened by same EA)
  • Trade #12345680, XAUUSD Buy 0.10 lot, Magic: 0 (opened manually by trader)

Both EA trades share magic number 55555, so the EA recognizes them as its own. The manual trade carries magic 0, and the EA ignores it entirely.

Where the Term Comes From

The phrase "magic number" is not unique to trading. It's a general programming term for a constant value baked into code without much explanation of what it represents, and it carries the same meaning here: a plain integer with no inherent significance beyond the role the program assigns it. MetaQuotes built the field into the order structure from the earliest versions of MetaTrader 4, and it carried over into MT5's rebuilt trading architecture (documented on the official MetaTrader 5 platform pages) without changing its purpose. There's nothing mysterious about the number itself; the "magic" is really just shorthand for "arbitrary but meaningful to the program that set it."

Why EAs Need Magic Numbers

Every EA relies on magic numbers for five main reasons, and knowing them will save you from some costly configuration mistakes.

1. Identifying Own Trades

An EA needs to know which trades it opened so it can manage them. Without a magic number, the EA cannot distinguish its trades from manual trades, trades from other EAs, or trades copied from signal services.

2. Trade Management

To modify stop loss, take profit, or close a position, the EA first checks the magic number. Only trades with a matching magic number get managed; everything else is left alone. This same filtering logic is what lets an EA enforce a one-position-per-setup rule; see our guide on how to ensure an EA uses only one position per setup for how that check works in practice.

3. Position Sizing

EAs often calculate lot sizes based on current exposure. If the EA counts all trades on the account (including manual ones and other EAs), position sizing will be incorrect, potentially leading to over-leveraged positions. Proper lot sizing depends on accurate trade identification.

4. Performance Tracking

To track each EA's performance separately on tools like Myfxbook, trades must be identifiable by their magic number. This allows filtering and analysis per EA.

5. Conflict Prevention

Without unique magic numbers, one EA might try to close or modify another EA's trades. This creates chaos and unpredictable losses.

Golden Viper EA handles magic numbers automatically. Verified live results on Myfxbook with a public track record — focus on profits, not configuration.
Get Access →

How EA Magic Numbers Work in Practice

When the EA Opens a Trade

  1. EA calculates entry based on its strategy rules
  2. EA sends the order request with its magic number attached
  3. Broker's server records the order with that magic number
  4. Trade appears in the terminal with the magic number stored in the order data

When the EA Scans Open Trades

  1. EA loops through all open orders on the account
  2. For each order, the EA checks if the magic number matches its own
  3. If the magic number matches: the EA manages this trade (modify, close, trail stop)
  4. If the magic number does not match: the EA ignores this trade completely

Manual Trades and Magic Number Zero

When you open a trade manually through the MT4/MT5 interface, the magic number is automatically set to 0. Most well-coded EAs filter out magic number 0 so they never interfere with your manual trading activity.

Magic Numbers vs. Order Comments

The magic number isn't the only piece of metadata attached to a trade. Every order also carries an optional order comment, a short text string that can be set when the trade is opened. The two fields look similar on the surface but serve different jobs, and understanding the distinction clears up a lot of confusion for traders new to reading trade history.

A magic number is a required numeric field. In the underlying MQL4/MQL5 order-sending code, it's passed as part of the trade request the EA sends to the server (see the MQL5 documentation on OrderSend for the exact request structure), and it can always be read back afterward through functions like PositionGetInteger(POSITION_MAGIC), part of the position properties reference. Because it's a number and always present, comparing it in code is fast and unambiguous: either it matches, or it doesn't.

An order comment, by contrast, is optional free text, often used to label a trade with something human-readable like "TP1 hit" or a strategy name. Comments are useful for a trader scanning their own history, but they're a weaker tool for an EA to filter on programmatically. Text comparison is slower than integer comparison, some brokers truncate or overwrite comments (particularly on trades that pass through a bridge or are modified by the server), and there's no guarantee a comment stays intact through partial closes or platform quirks. That's why virtually every serious EA, Golden Viper EA included, relies on the magic number as the primary filter and treats the comment as a secondary, cosmetic label at best.

A practical way to think about it: the magic number is how the EA recognizes its own trades, and the comment is how you, the human reading the terminal, get a quick hint about what happened without digging into the EA's logic.

When EA Magic Numbers Matter Most

Scenario Magic Numbers Critical? Recommended Action
Multiple EAs on same account Essential Unique number for each EA
EA + manual trading Important EA uses non-zero magic number
Same EA on multiple pairs Important Different magic per instance
EA + trade copier Essential Different magic numbers
Single EA, no manual trading Less critical Default value is fine

How to Set Magic Numbers

Most EAs expose the magic number as a configurable parameter in their Inputs tab. To change it:

  1. Right-click on the chart where the EA is attached
  2. Select Expert Advisors → Properties
  3. Go to the Inputs tab
  4. Find the magic number setting (may be called "Magic Number," "Magic," "OrderMagic," or "MagicNumber")
  5. Enter your desired unique number
  6. Click OK to apply

Tips for Choosing Magic Numbers

  • Any unique positive integer works: 12345, 77777, 100001
  • Avoid 0, since it's reserved for manual trades in most EA designs
  • Make it memorable: pick numbers you'll recognize in trade logs
  • Document your assignments: a simple spreadsheet tracking which EA uses which number does the job
  • Use a system, for example 111XXX for gold EAs and 222XXX for forex EAs

Choosing a Numbering Scheme

There's more than one reasonable way to assign magic numbers once you're managing several EAs. None of these is objectively "correct," but each has trade-offs worth knowing before you settle on one.

Scheme Example Pros Cons
Sequential 1, 2, 3, 4… Simple, quick to assign Easy to lose track of which number maps to which EA over time
Category-range 111XXX gold, 222XXX forex Self-documenting at a glance in trade history Requires planning ranges before you have many EAs
Instrument-coded XAUUSD = 1900, EURUSD = 1200 Ties the number to something memorable (e.g., gold's price level) Breaks down if an EA trades multiple instruments
Random / arbitrary 77341, 502918 No planning needed, virtually zero collision risk Meaningless at a glance; relies entirely on your documentation

Whichever scheme you pick, the only rule that actually matters is uniqueness. The scheme just makes your own record-keeping easier when you're staring at a trade history with several magic numbers mixed together.

Running Multiple EAs: Magic Number Strategy

If you run multiple EAs on the same account (plenty of traders do this alongside XAUUSD trading), getting the magic number assignment right matters. Our dedicated guide on running multiple EAs on one account covers the broader setup considerations; here's how we'd recommend organizing the magic numbers specifically:

EAInstrumentMagic Number
Golden Viper EAXAUUSD111111
Second Gold EAXAUUSD222222
EURUSD ScalperEURUSD333333
Manual TradingAny0 (automatic)

Rules for Multi-EA Setups

  1. Every EA gets a unique magic number, no exceptions
  2. Document your assignments in a spreadsheet or note file
  3. Never change magic numbers while trades are open, or the EA will lose track of them
  4. Test on demo first when adding a new EA, just to confirm there are no conflicts

Running several EAs also means your terminal needs to stay connected around the clock; a dropped connection doesn't erase magic number assignments, but it can leave positions unmanaged while the platform is offline. Most multi-EA traders run their terminal on a VPS rather than a home PC for exactly this reason.

Critical warning: Never change an EA's magic number while it has open trades. The EA instantly "forgets" those positions and may open conflicting new ones. Close all positions managed by the EA first, before touching its magic number. Our broker guide covers more account setup best practices.

Magic Numbers, Copy Trading, and Signal Services

Magic number conflicts get more subtle once copy trading or a signal subscription enters the picture. A signal-copied trade generally arrives on your account without you choosing its magic number; the copying mechanism (whether it's the built-in MQL5 Signals service or a third-party copier) assigns its own value, which is often different from whatever your locally running EA uses. That's usually fine on its own, but problems appear when you run a local EA and a copied signal on the same instrument at the same time: if the local EA isn't strict about filtering by its own magic number, it can miscount total exposure or, in worse cases, attempt to manage trades it didn't open.

The safe pattern is the same one that applies to any multi-EA setup: know what magic number each source is using, keep them distinct, and check your terminal's trade history periodically to confirm trades are landing under the magic number you expect. If a copied signal and a locally running EA are both trading gold, treat them as two separate "EAs" for magic-number planning purposes, exactly as you would two different Expert Advisors.

Common Issues and Solutions

Issue 1: EA Opens Trades But Never Closes Them

Cause: Magic number was changed after trades were opened. The EA no longer recognizes them.

Fix: Change the magic number back to what it was when the trades were opened, or close the orphaned trades manually.

Issue 2: EA Closes Your Manual Trades

Cause: EA's magic number is set to 0, same as manual trades.

Fix: Change the EA's magic number to any non-zero value (e.g., 12345).

Issue 3: Two EAs Interfering With Each Other

Cause: Both EAs share the same magic number.

Fix: Give each EA a unique magic number and restart both.

Issue 4: EA Opens Too Many Trades

Cause: EA cannot see its existing trades because the magic number was changed or corrupted.

Fix: Verify the magic number setting matches what was used when existing trades were opened.

Issue 5: Magic Number Resets After an EA Update

Cause: Updating to a new build of an EA sometimes resets input parameters to their default values if you didn't save your settings as a preset (.set file) beforehand.

Fix: Before updating any EA, export your current inputs as a preset from the Inputs tab, then re-apply that preset (or manually re-enter your custom magic number) after the update completes. Our MT4 common errors guide covers other issues that tend to surface after updates.

Issue 6: Terminal Shows Trades With an Unfamiliar Magic Number

Cause: This usually means a different EA, a copied signal, or a bridge/API connection you forgot about is placing trades on the account, or a broker-side process (such as a swap-free conversion or partial close) generated an order with a system-assigned value.

Fix: Cross-check the unfamiliar magic number against every EA, copier, and signal subscription attached to the account. If none of them match, contact your broker's support to confirm what generated the order before assuming it's a bug in your own setup.

A Word on Vendor Claims

Because magic numbers sound technical, some EA marketing leans on the term to imply sophistication it doesn't have. A magic number is a standard MetaTrader order field, described in MetaQuotes' own MQL5 documentation, available to any developer writing an Expert Advisor. It's configuration, not a trading edge. If a vendor's pitch centers on a "proprietary magic number system" or similar language rather than a verifiable track record, treat that as a minor red flag rather than a differentiator.

The same caution applies more broadly to automated trading claims in general. Algorithmic trading, as a category, carries no guarantee of profit regardless of how the code is structured internally, and regulators including the CFTC and the FTC publish ongoing warnings about automated-trading and trading-bot scams that promise guaranteed returns. Golden Viper EA does not claim to be risk-free or guaranteed, and any EA that does should be treated with real skepticism no matter how its configuration screen is labeled.

Frequently Asked Questions About EA Magic Numbers

What is a magic number in MT4/MT5?

A magic number is a unique integer identifier (0 to 2,147,483,647) that an Expert Advisor assigns to every trade it opens. It acts like a name tag, letting the EA recognize which trades belong to it versus manual trades or trades from other EAs running on the same account.

Why do EAs need magic numbers?

EAs need magic numbers to identify their own trades for management (modify, close), avoid interfering with manual trades or other EAs, calculate position sizes based only on their own exposure, and track performance separately. Without magic numbers, EAs cannot distinguish their trades from others.

Can two EAs have the same magic number?

No. Two different EAs running simultaneously should never share the same magic number. If they do, both EAs will treat each other's trades as their own, causing conflicts such as one EA closing another's trades or miscalculating position sizes.

What happens if I change the magic number with open trades?

The EA will lose track of those trades entirely. It will not recognize them as its own and will not manage, modify, or close them. The trades remain open but become orphaned. Either close all trades before changing the magic number, or change back to the original value.

What magic number does Golden Viper EA use?

Golden Viper EA sets a default magic number automatically. If you are only running Golden Viper EA with no other EAs or manual trading, the default works perfectly. If running multiple EAs, you can customize the magic number in the EA's Inputs tab to ensure uniqueness.

Do I need a different magic number for the MT4 and MT5 versions of the same EA?

No, not for the sake of avoiding conflicts. MT4 and MT5 are separate platforms with separate trade servers, so a magic number set on one has no relationship to trades on the other. You can reuse the same number on both. Some traders still assign different ranges per platform purely to keep their own notes unambiguous when reviewing statements from both accounts side by side.

Does the magic number affect execution speed or slippage?

No. The magic number is a label the trade server stores alongside order size, price, and other order details; it has no effect on how fast an order fills or how much slippage occurs. Execution quality depends on your broker's execution model, market volatility, and connection quality, not on which integer is attached to the trade.

How do I find an EA's default magic number if it isn't documented?

Attach the EA to a demo chart, let it place one trade, then check the "Magic" column in the terminal's trade history or Trade tab (right-click the column headers and enable it if it's hidden). Whatever number appears there is the value the EA is using by default.

Can a broker or prop firm restrict which magic numbers I use?

Some prop trading firms and a handful of brokers place restrictions on automated trading generally, sometimes requiring EAs to be disclosed or configured a certain way, though this is about EA usage rather than the specific magic number value. If you're running an EA on a funded or evaluation account, check that firm's rules first; our guide on using the same EA across multiple brokers covers related account-setup considerations.

What's the difference between a magic number and an order comment?

A magic number is a required integer field every order carries, and it's what EAs use for reliable, fast trade filtering. An order comment is an optional short text string, more useful as a human-readable note than as something a program should depend on, since comments can be truncated or altered by some brokers and aren't guaranteed to survive partial closes.

Myfxbook Verified

Professional EA, Automatic Configuration

+€1,485Net · 6-mo (verified)
56%Win Rate (51/91)
24/5Automated
Starting at $199 one-time
Get Lifetime Access →
✓ Instant download ✓ Full feature access ✓ MT4 & MT5 compatible
DC

Daniel Cole

Daniel Cole writes about MetaTrader 4/5, Expert Advisors and trading automation for Golden Viper EA.

Myfxbook Verified Verified live since Jan 2026 Public track record

Let Golden Viper EA trade gold for you

Automated XAUUSD trading for MT4 & MT5, verified live on Myfxbook. One-time $199, lifetime access.

Get Lifetime Access — $199