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.
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
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.