Advertisement IC Markets

Telling EAs apart on a shared account: an ID scheme

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 806
Joined: Sun Oct 18, 2026 12:25 pm

Telling EAs apart on a shared account: an ID scheme

Post by FXS London Scalper »

When several EAs run on the same account, each needs a way to identify its own trades. The magic number field serves this purpose, but conflicts are common when two EAs use the same value or when one EA ignores it.

A practical scheme is to assign magic numbers that encode the strategy and the pair, for example a prefix for the strategy and a suffix for the symbol. This makes logs and reports easier to read.

Every function that counts, modifies or closes positions should filter by both magic number and symbol. An EA that closes all positions on a symbol without checking magic numbers can close trades opened by another EA or by hand.

A worked example: a trailing stop EA attached to EURUSD modifies stops on all EURUSD positions, including one opened manually with a different plan. Filtering by magic number would prevent this.

Netting accounts complicate things further, since positions on the same symbol merge.

How do you organise magic numbers?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Amanhasnoname
Posts: 1506
Joined: Fri Oct 30, 2026 9:45 am

Re: Telling EAs apart on a shared account: an ID scheme

Post by Amanhasnoname »

I ran into this on a VPS where three EAs shared an account, and the symptom was one EA quietly closing another one's positions after a restart. What fixed it was a magic number scheme with digits that carry meaning: the first two for the strategy, the next one for the timeframe, and the last two for the symbol. So 21501 might be strategy 21, the 15 minute chart, and EURUSD, and when I read the history later I could tell which EA made each trade without opening the code.

The second part was a small block of code at the top of every function that touches positions, which skips anything with a different magic number or symbol. I also made manual trades use magic zero and told the EAs never to touch those, which protected a position I had opened myself during a news spike.

On netting accounts, I stopped running two strategies on the same symbol at all and used separate accounts instead, since the merged position made it impossible to attribute results.
Post Reply