ForexBestRobots.com

MT4 & Expert Advisors · Order identification

MT4 Magic Number Explained: How Expert Advisors Track Trades

Understand how an MT4 Magic Number identifies EA orders, prevents strategy conflicts and supports safer multi-EA account management.

13 min readReviewed by ForexBestRobots Editorial Team
MT4 Magic Number diagram showing separate Expert Advisors and manual trades routed to different order groupsMT4 & Expert AdvisorsPractical MT4 guidance

Original illustration created for ForexBestRobots.com.

A Magic Number is an integer that an Expert Advisor writes into an MT4 order when the trade is created. The EA can later scan open and historical orders, find its own identifier and decide which positions it is allowed to manage.

What a Magic Number does

A Magic Number is an integer that an Expert Advisor writes into an MT4 order when the trade is created. The EA can later scan open and historical orders, find its own identifier and decide which positions it is allowed to manage.

The number does not make trades profitable, limit drawdown or license an account. Its purpose is operational: it separates one automated strategy from another and, when the code is written correctly, prevents an EA from modifying unrelated orders.

MT4 Magic Number diagram showing separate Expert Advisors and manual trades routed to different order groups
A Magic Number is an order identifier, not a risk control or account license.
A unique number prevents confusion, not market loss

Position size, Stop Loss, correlation and maximum drawdown still require separate risk controls.

Order workflow

Use a unique, documented integer for each independent strategy. Keep the same value when restarting MT4 or moving the same installation to a VPS. A symbol suffix does not require a new Magic Number by itself, but a separate strategy instance usually does. If the vendor supplies a fixed value or hides the input, follow that design instead of forcing a replacement.

1

Choose the ownership model

Read the vendor instructions first. Some EAs expect one fixed Magic Number, while portfolio systems intentionally share a number across several charts.

2

Record every assignment

Keep a simple table with terminal, account, EA, symbol, timeframe and Magic Number. This is more reliable than trying to remember several installations.

3

Set the value before attachment

Enter the number in EA Inputs before live use. Do not copy a set file blindly if another EA already uses the same number.

4

Preserve it during open trades

If positions are active, do not change the identifier unless the developer gives a migration procedure. The new instance may no longer recognize the existing basket.

Common conflicts

ScenarioSuggested assignmentRisk if confused
One EA on one chartOne stable number for that strategy instanceChanging it while trades are open can orphan positions
Same EA on two pairsDifferent number per symbol unless the vendor states otherwiseThe EA may combine baskets or close the wrong symbol group
Two different EAsA unique number for each EABoth programs may attempt to manage the same orders
Manual tradesUsually Magic Number 0An EA coded to manage 0 may touch manual orders

Common mistakes

Duplicate numbers used by unrelated EAs on the same account
A copied set file that silently overwrites the planned identifier
Running the same account in two terminals with different settings
Using Magic Number 0 when the EA is allowed to manage manual orders
Changing the value after an EA has opened a basket

Safe setup

Use a unique, documented integer for each independent strategy. Keep the same value when restarting MT4 or moving the same installation to a VPS. A symbol suffix does not require a new Magic Number by itself, but a separate strategy instance usually does. If the vendor supplies a fixed value or hides the input, follow that design instead of forcing a replacement.

How to verify

Open Terminal → Trade and display the order comment if the EA writes one.
In Account History, inspect the order with a script or report that exposes the magic field.
Confirm that closing or changing one test order does not affect another EA’s position.
Check Experts and Journal after restart for messages about missing or unmanaged orders.
Repeat the test on Demo before running several EAs on one live account.

Official reference

Read the official documentation.