MagicNumber Design for Running Multiple EAs on One Account
Contents
Bottom Line: MagicNumber Is the EA's Name Tag. Never Duplicate It Within One Account
If you run multiple EAs on a single account, the first thing to decide is how you assign MagicNumbers. A MagicNumber is a number attached to orders and positions that shows which EA placed them. Most EAs look at this number to decide "which positions are mine."
When numbers overlap, one EA can mistake another EA's position for its own and close it or change its stop on its own. No error appears, and both EAs look like they are running normally, so this kind of accident is easy to miss.
Recommended Broker Comparison →
🎁 Download Free EA📧 Free 8-email course + subscriber-only pack of 13 MT5 indicators
* Privacy strictly protected. You can unsubscribe at any time.
How It Works: How an EA Recognizes "Its Own Positions"
In MT5, an EA can attach a numeric MagicNumber when it places an order. This value stays on the position (POSITION_MAGIC) and in the trade history (DEAL_MAGIC). Orders placed manually usually carry 0.
When counting or managing positions, a typical EA filters them like this:
- Whether the symbol matches its own chart
- Whether the MagicNumber matches its own setting
Only positions that match both are treated as "its own holdings." The key point is that MT5 itself does not stop MagicNumbers from being duplicated. The number is just a convention, and whether it is respected is left to the person running the EAs and to how each EA is built.
What Happens When Numbers Collide
If two EAs run on the same symbol with the same MagicNumber, you can see problems like these:
- Suppressed entries: An EA set to "maximum 1 position" counts the other EA's position as its own and skips new entries
- Closing someone else's position: When a close signal fires, it also closes the other EA's position
- Overwritten stops: A trailing stop moves the SL on the other EA's position as well
- Distorted lot calculation: For an EA that sizes lots based on the number of open positions, the resulting exposure can be larger than intended
None of these show up in backtests, because the tester runs one EA at a time. This is one of the reasons live results drift away from test results.
Tracking Partial Closes
For EAs that use partial closes, you also need to be careful about how you trace the records. On a hedging account, the position identifier (POSITION_IDENTIFIER) does not change after a partial close, and it is also recorded on the closing deals in the history as DEAL_POSITION_ID. If you want to total up results per EA afterward, the reliable method is to filter by MagicNumber and then group by this position ID.
However, the MagicNumber recorded on a closing deal can be the value of whoever sent the closing order. If you manually close part of a position an EA opened, that deal alone will carry 0, and totals based only on MagicNumber may not add up. The comment field can also be rewritten by the broker or server, so it is not a dependable way to identify trades.
Pre-Setup Checklist
| Item to check | How to check | Risk if skipped |
|---|---|---|
| Are the MagicNumbers of all EAs unique? | List them from each EA's parameter screen and keep a record | Interference in closes and SL changes |
| If you use the same EA on multiple charts, did you give each a different number? | Use separate numbers even for different symbols or timeframes | Mix-ups with EAs that don't check the symbol |
| Is the account a hedging type? | Check the account information | On a netting account, positions on the same symbol are merged into one and can't be separated by number |
| Did you change a number while the EA was running? | Confirm there are no open positions before changing it | Existing positions are left unmanaged |
| Are you mixing in manual trading? | Keep manual trading on a separate account | Skewed totals, and records lost through manual closes |
If you use a simple rule, such as separating EAs by digit ranges, it is easy to read the history later. For where to find the setting screen, see How to Set Up an EA.
Limits and Caveats
Separating MagicNumbers does not prevent everything. Here is what it cannot do.
- It does nothing for EAs that ignore MagicNumber: EAs that filter by symbol only, or that manage every position on the account, will interfere even if the numbers differ. If you mix in EAs from other vendors, we have no way of knowing how they are built.
- Default-value collisions: Many EAs are distributed with their default value unchanged. It is entirely possible for EAs from different developers to share the same default by chance. Always check the value yourself.
- EAs that trade multiple symbols: When one EA handles several symbols, as ATLAS and TRINITY do, it ends up competing with other EAs for the same symbols. Even with separate numbers, margin is shared, so drawdowns can still overlap at the same time.
- Capital management is not separated: Numbers only separate position management. Margin level and stop-out are determined at the account level. If one EA loses heavily, the other EAs get dragged down with it.
If you want to avoid interference for certain, giving each EA its own account is the simplest approach. Think of MagicNumber design as the minimum safeguard once you have decided to run them on one account.
Summary
- MagicNumber is the EA's identifier recorded on orders, positions, and history, and MT5 does not stop duplicates
- Duplicates can cause suppressed entries, closing of other EAs' positions, overwritten SLs, and distorted lot calculation. None of this reproduces in backtests
- Track partial closes by combining MagicNumber with the position ID. Manual closes can throw the records off
- On a netting account you can't separate positions by number. For multiple EAs, use a hedging account
- Even with separate numbers, margin stays shared. To avoid interference for certain, separate the accounts
For more operating know-how, see EA & MT5 Know-How.
Related
2026-11-02
MT5 Orders and Positions: Avoid Netting Account Mishaps
2026-10-29
MQL5 OnTick vs OnTimer: How to Use Each in EA Design
2026-10-20
How Server Timezones Break EA Session Filters
2026-10-19
Backtest Not Reproducing? 5 Things to Check First
📧 Free 8-email course + subscriber-only pack of 13 MT5 indicators
* Privacy strictly protected. You can unsubscribe at any time.
Have a question about EAs or FX?
You can post it on the Nattzy trading forum (free sign-up). Questions beyond this article are welcome too — EA settings, choosing a broker and more.
Ask on Nattzy ↗