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 recognize which trades belong to it -- versus manual trades or trades from other EAs. Each EA on your account should have a unique magic number. If 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 allows customization in the Inputs tab.

EA magic numbers seem like a minor technical detail, but misunderstanding them causes real problems -- especially when running multiple Expert Advisors on the same account. I have seen traders lose money because two EAs shared the same magic number and started closing each other's trades. This guide explains everything you need to know about EA magic numbers in MetaTrader 4 and MT5, from the basic concept 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. Think of it like a name tag on a package -- it identifies who sent it and who should receive it. In the context of 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 -- use 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 knows they belong to it. The manual trade has magic 0 and is ignored by the EA.

Why EAs Need Magic Numbers

There are five critical reasons why every EA uses magic numbers. Understanding these will help you avoid 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 are managed -- everything else is left alone.

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. +135% monthly returns, 81% win rate. Focus on profits, not configuration.
Try Free →

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.

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 -- reserved for manual trades in most EA designs
  • Make it memorable -- use numbers you will recognize in trade logs
  • Document your assignments -- keep a simple spreadsheet tracking which EA uses which number
  • Use a system -- e.g., 111XXX for gold EAs, 222XXX for forex EAs

Running Multiple EAs: Magic Number Strategy

If you run multiple EAs on the same account (which many traders do alongside XAUUSD trading), proper magic number assignment is essential. Here is how I recommend organizing it:

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 -- the EA will lose track of them
  4. Test on demo first when adding a new EA to verify no conflicts

Critical warning: Never change an EA's magic number while it has open trades. The EA will instantly "forget" those positions and may open conflicting new trades. Always close all positions managed by the EA before changing its magic number. Read our broker guide for account setup best practices.

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.

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.

Myfxbook Verified

Professional EA, Automatic Configuration

+135%Monthly Returns
81%Win Rate
24/5Automated
Starting at $99/month
Start 7-Day Free Trial →
✓ No credit card required ✓ Full feature access ✓ MT4 & MT5 compatible
GV

Golden Viper EA Team

We specialize in automated XAUUSD trading with verified live results. Golden Viper EA handles magic numbers and all technical configuration automatically.

Myfxbook Verified Live Trading Since 2024 81% Win Rate