How to Run Multiple Strategies on One MT5 Account with Magic Numbers

Last updated · By the TradingView Link team
Short answer

A magic number is an ID an EA attaches to each order. Give each TradingView strategy its own, such as m=1001, in every alert line. The TradingView Link EA then closes, reverses and changes only trades with that number. On one symbol, this needs a hedging account, because netting allows one position.

What is a magic number in MT5?

It's a whole number attached to a trade to show which EA placed it. MetaQuotes' trade request docs describe the magic field as "Expert Advisor ID", and say "each Expert Advisor can set its own unique ID when sending a trade request". The number then stays with the order, deal and position.

The number does nothing by itself. Strategies stay apart because the EA checks it before closing or changing a trade, which ours does. It sets the number with MT5's standard SetExpertMagicNumber call. You can see it in MT5, in the Magic column of your open positions. Our EA also writes it in the trade's comment, as m=1001.

How do you set a magic number in a TradingView alert?

Add m= and the number to the command. One strategy might send this:

YourWebhookPassword
long EURUSD q=0.1 sl=300 tp=600 m=1001

And a second strategy on the same symbol might send this:

YourWebhookPassword
short EURUSD q=0.2 sl=150 tp=300 m=1002

Use a positive whole number of up to nine digits. If the value isn't a whole number, the line fails and no order is placed. The EA reads the value as a 32-bit integer, so very long numbers won't stay intact.

In a Pine Script strategy, write the number into each order's alert_message, including the exits, and put {{strategy.order.alert_message}} in the alert's message box:

if longSignal
    strategy.entry("Long", strategy.long, alert_message = "long EURUSD q=0.1 sl=300 tp=600 m=1001")
if exitSignal
    strategy.close("Long", alert_message = "flat EURUSD m=1001")

If the strategy only opens and closes whole positions, the {{strategy.market_position}} placeholder also works. It sends long, short or flat, with the same number each time:

YourWebhookPassword
{{strategy.market_position}} EURUSD q=0.1 sl=300 tp=600 m=1001

How to automate a TradingView strategy covers these two methods in full, and the webhook guide lists every other command.

What does each command do with the number?

This is what each command does when it includes m=1001. It leaves trades with other numbers alone.

TradingView Link commands with m=1001
CommandWhat it does
long, short Opens a trade tagged 1001, and first closes opposite trades tagged 1001
flat Closes the trades tagged 1001 on that symbol
flat cq=50% Closes 50% of the trades tagged 1001
modify Changes stops and targets on positions and pending orders tagged 1001
cancel Cancels pending orders tagged 1001

What happens if you leave out m=?

The EA treats the command as magic number 0. This catches people out in one way: a plain flat EURUSD closes only trades without a number. It doesn't close trades tagged m=1001, so those stay open.

So use the same number on every line a strategy sends, entries and exits alike. There's no command that closes every number at once. To close everything on a symbol, send one line per number, plus a plain flat for any trades without a number:

YourWebhookPassword
flat EURUSD m=1001
flat EURUSD m=1002
flat EURUSD

Do magic numbers work on a netting account?

Not on one symbol. MT5 has two position accounting systems, and "the system used depends on the account and is set by the broker". Only hedging keeps separate positions on a symbol:

Hedging and netting accounts in MT5, based on MetaQuotes' help (checked November 2026)
SituationHedgingNetting
Positions per symbol Several, including opposite ones One
New deal in the same direction Opens a new position Adds to the position
New deal in the opposite direction Opens a new position Reduces, closes or reverses the position
Two strategies on one symbol Stay separate Merge into one position
Two strategies on different symbols Stay separate Stay separate

On a netting account, a short from one strategy would reduce or reverse the other strategy's long. We didn't find anything in MetaQuotes' docs on which magic number a merged position keeps, so don't rely on it. Use a hedging account, or keep each strategy on its own symbol.

To test your account: on a demo account of the same type, send two long alerts on one symbol with different numbers. Two rows in the Trade tab means hedging. One row with a larger volume means netting.

Can two strategies hold opposite trades on one symbol?

Yes, on a hedging account, where MetaQuotes says you can have "multiple open positions of one and the same symbol, including opposite positions". A short tagged 1002 doesn't close a long tagged 1001. Both stay open until their own strategy closes them, and they partly cancel each other's profit and loss while they do.

Prop firms may look at this more closely. FTMO, for example, forbids holding opposing positions to get around its profit-distribution rules. See how to automate a TradingView strategy on FTMO.

Which EA limits do strategies share?

Magic numbers don't give each strategy its own trade limits unless you turn that on:

EA settings that limit trades
SettingDefault and what it counts
MaxTradePerSymbol Default 10. Counts positions and pending orders on the symbol, across all magic numbers
Pyramiding Default 10. Counts same-direction positions on the symbol, across all magic numbers
PyramidingPerMagic Default 0 (off). Counts same-direction positions on the symbol, for each magic number

Busy strategies on one symbol can use up a shared limit, and the EA then refuses the next entry, even for a strategy with no trades open. Raise MaxTradePerSymbol and Pyramiding if you need to, and set PyramidingPerMagic to cap each strategy. With Pyramiding at 3 and PyramidingPerMagic at 2, each strategy can open 2 positions in one direction, up to 3 on the symbol. Stops, targets and sizes stay separate, because each alert sets its own.

How should you number your strategies?

How many alerts do you need?

One TradingView alert per strategy. The EA still only needs one MT5 chart. Webhooks start at Essential, and TradingView's pricing table showed 20 active technical alerts on that plan in November 2026. It showed us prices in euros, so check the page for your region. Our plan comparison has the higher plans.

More strategies also means more alerts on our side. Our Free plan's 5 alerts a month is only enough for a test, and paid plans start at 500 alerts a day. Pricing has the full list.

Try two strategies on a demo account
Connect TradingView to MT4 or MT5 and check how your account handles magic numbers. 5 free alerts a month, no credit card.

Frequently asked questions

What is a magic number in MT5?

It's a number that identifies which Expert Advisor placed an order. MetaQuotes calls it the Expert Advisor ID. Orders, deals and positions all carry it, and it appears in the Magic column of your open positions.

Do I need a separate webhook or EA for each strategy?

No. One EA on one chart can handle them all. Create one TradingView alert per strategy, send them to the same webhook, and give each strategy its own m= number in every command.

What happens if I leave out m=?

The EA treats the trade as magic number 0. Those trades are only managed by commands that also leave out m=, so a plain flat doesn't close trades tagged m=1001.

Can two strategies share a magic number?

Yes, but then they aren't separate. If both trade one symbol, a flat from either strategy closes both strategies' trades, and a long from one closes the other's shorts.

Can I use one magic number on several symbols?

Yes. The EA checks the symbol and the number together, so a strategy that trades EURUSD and GBPUSD can use m=1001 on both, and a flat EURUSD m=1001 leaves GBPUSD alone.

Do magic numbers work on a netting account?

Only across different symbols. A netting account holds one position per symbol, so two strategies on one symbol merge into one position. Use a hedging account, or give each strategy its own symbol.

Does the m= command work on MT4?

Yes. The MT4 and MT5 EAs both read m= from the alert and filter their closes, changes and cancels by it.

Do magic numbers separate strategies for prop-firm limits?

No. A magic number is a label inside MetaTrader. At FTMO, for example, the loss limits are measured on the whole account's equity, whichever strategy made the loss.

Sources

All checked November 2026. What the EA does with m= comes from our own EA code.

Related guides