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
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.
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.
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.
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.
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.
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
| Scenario | Suggested assignment | Risk if confused |
|---|---|---|
| One EA on one chart | One stable number for that strategy instance | Changing it while trades are open can orphan positions |
| Same EA on two pairs | Different number per symbol unless the vendor states otherwise | The EA may combine baskets or close the wrong symbol group |
| Two different EAs | A unique number for each EA | Both programs may attempt to manage the same orders |
| Manual trades | Usually Magic Number 0 | An EA coded to manage 0 may touch manual orders |
Common mistakes
Safe setup
Check the EA’s documented ownership scope before choosing identifiers. Some programs filter by both Magic Number and symbol; portfolio EAs may intentionally manage several symbols together. An identifier only works when the code checks the intended scope before modifying or closing an order.
Do not use order comments as an ownership lock. Comments can be changed by the server, and Magic Number 0 is commonly used for manual orders. Verify the actual magic field with a trusted diagnostic script or report, not the displayed comment alone.
How to verify
A Magic Number does not lock another terminal out
Two terminals logged into the same account can read and act on the same order pool. A shared Magic Number does not create a server-side mutex or appoint one terminal as the owner. Even different identifiers do not stop two copies from opening duplicate strategy exposure if both independently detect the same signal.
Keep one intended trading instance for a given deployment unless the developer explicitly supports coordination. During a VPS move, preserve identifiers needed to recognize open positions, stop the old instance and confirm the new one manages those positions. Do not change a live basket’s identifier to solve a duplicate-terminal problem.
The OrderSend reference describes the magic field as a user-defined identifier and notes that the server can alter the end of an order comment.
Verify ownership before combining independent instances
Assume the vendor explicitly supports two independent demo instances with identifiers 11401 and 11402. Record the account, broker server, EA version, exact symbols and timeframes for each. When a normal test signal creates an order, inspect its actual magic field and symbol. Confirm that each instance recognizes only the orders within its documented scope, including after a restart. Different numbers alone do not prove that the code filters correctly.
If an unrelated position is modified or an existing basket is not recognized, stop adding new exposure and retain the evidence. Do not change the identifiers of open positions as an experiment. A coordinated portfolio EA may intentionally use a different ownership model, so the vendor’s instructions take precedence over this independent-instance example.
Use the VPS recovery and handover checks when moving the deployment, and review combined portfolio exposure separately. Correct order ownership prevents operational confusion; it does not make correlated strategies independent or limit their market losses.