Advertisement IC Markets

Running two EAs on one account, magic numbers and the mess I made without them

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Running two EAs on one account, magic numbers and the mess I made without them

Post by Fairman »

Running two EAs on one account, magic numbers and the mess I made without them

I wanted to run two different strategies on the same account and learned the hard way about magic numbers. Every order an EA places can carry a number that identifies it. If both EAs use the same number, or none, they can start managing each other's trades.

What happened to me was one EA saw an open position and thought it was its own, so it moved the stop and closed it on its own logic. I came back to a pile of trades that didn't match either strategy's rules and it was hard to figure out which did what.

The fix was to give each EA its own magic number and make each one filter positions by its number and symbol before doing anything. I also made sure the risk per trade is calculated per EA, and I put a total open risk limit across both so they can't stack up at the same time on correlated pairs.

If you run more than one, also think about correlation. Two EAs both long EURUSD and GBPUSD is just one big trade in disguise.
It’s Fairman :geek:
Recommended broker for automated trading & scalping IC Markets
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Running two EAs on one account, magic numbers and the mess I made without them

Post by Fairman »

A simple trick that helped me debug this. I made each EA print a line to the journal tab every time it opens, modifies or closes a trade, with its magic number and a short reason. When something weird happens, I can scroll through the log and see exactly which EA did what and why. Before that I was trying to work it out from the trade history alone, which was almost impossible once both were active on the same symbols.
It’s Fairman :geek:
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Running two EAs on one account, magic numbers and the mess I made without them

Post by Fairman »

If you use bought EAs rather than ones you wrote yourself, check whether they let you set the magic number in the inputs. Some do not, and two copies of the same EA on different charts can end up with the same number by default. I learned this when I put one EA on two pairs and it started closing trades on the wrong chart. Now the first thing I do with any new EA is check its inputs for a magic number setting.
It’s Fairman :geek:
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Running two EAs on one account, magic numbers and the mess I made without them

Post by Shadow Trader »

The total open risk cap is the key fix, and it helps to know what two correlated positions add up to. With 1 percent on each EA, the combined figure is the square root of 2 plus twice the correlation, so it sits between 1.41 percent with no correlation and 2 percent when the pairs move as one.
img_13522_r1.png
img_13522_r1.png (76.29 KiB) Viewed 174 times
The chart plots that curve, with EURUSD and GBPUSD marked at a correlation of 0.85, where the two positions behave like a single trade of about 1.92 percent. A cap of 1.5 percent would block the second entry at any correlation above 0.125, which on those two pairs is nearly always.

Magic numbers have one more edge case after a platform update or a VPS reboot. Some EAs rebuild state by scanning open orders, and if the filter checks only the symbol, your manual trade on that pair gets managed by the EA's exit rules.

So the filter needs the number and the symbol every time, startup included. A small manual trade on the same pair plus a terminal restart tests it.

Does anyone weight the cap by correlation inside the EA, or keep it a fixed figure? A fixed cap is simpler but treats EURUSD with USDJPY like EURUSD with GBPUSD.
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Running two EAs on one account, magic numbers and the mess I made without them

Post by Shadow Trader »

One trap magic numbers cannot fix is a netting account. On MT5 in netting mode there is only one position per symbol, so if the first EA is long 0.2 EURUSD and the second sells 0.1, the result is a single long of 0.1 that matches neither system.

Hedging mode keeps them as separate tickets, which is why it is worth checking the account type in the terminal before running two systems on the same pair. Some brokers only offer netting on certain account types, and the difference is easy to miss.

The order comment is another weak spot for anyone using it as a backup tag. Brokers can overwrite it on a partial close or a stop out, so an EA that searches for its own text in the comment can lose track of a trade halfway through.

Account limits also become shared. If the broker caps open orders at, say, 200 and a grid style EA is using 180 of them, the second system starts getting rejections at the worst moment.

Does anyone run each EA on its own sub account instead? It costs a little more admin but removes all three problems at once.
FXS Prop Desk
Posts: 1689
Joined: Wed Oct 07, 2026 9:52 am

Re: Running two EAs on one account, magic numbers and the mess I made without them

Post by FXS Prop Desk »

The magic number problem catches a lot of people when they move from one EA to two. A good additional safety step is to check the symbol as well as the magic number in every loop. Some EAs with unique magic numbers still manage trades on the wrong symbol when they run on several charts.

It also helps to use a different magic number for each chart instance, not just each EA. If the same EA runs on EURUSD and GBPUSD with the same number, a bug in the code can still mix them up.
FXS Official Team | The Idea Lab & Strategy
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Running two EAs on one account, magic numbers and the mess I made without them

Post by Shadow Trader »

Running several automated strategies on one account requires a way to tell their orders apart. Magic numbers, integer identifiers attached to orders, serve this purpose. Each strategy uses its own number and manages only orders carrying it.

Without unique identifiers, strategies may interfere with each other, closing positions that belong to another or miscounting open trades. A manual trade placed on the same account may also be touched by an automated system that does not filter by identifier.

Good practice assigns distinct magic numbers, documents them, and ensures every order function filters by the correct one. Account-level risk limits, spanning all strategies, prevent combined exposure from exceeding intended levels. Strategies running on the same pair can create offsetting positions that waste spread, or stack exposure unintentionally. Reviewing the combined position regularly, and testing multi-strategy setups on demo before live deployment, avoids unpleasant surprises. Clear separation and monitoring are the foundations of running more than one automated system safely.
Post Reply