PipWardenStart free

What is a magic number in MT5?

Definition A magic number is a whole-number ID that an Expert Advisor puts on the orders it sends in MetaTrader 5, so that the EA can tell its own positions apart from manual trades and other EAs' trades on the same account.

A magic number is an ID an Expert Advisor stamps on each order it sends, so it can later find its own positions among everything else on the account. An EA that does not filter by magic number cannot tell its trades from your manual ones or from another EA’s, and it may modify or close positions that are not its own.

How the magic number works in MT5

When an EA sends an order, the request has a magic field, a whole number the EA chooses. The MQL5 documentation calls it the “Expert Advisor ID” and notes that each EA “can set its own unique ID when sending a trade request”. The number is copied to the resulting deal and position, where the EA reads it back as POSITION_MAGIC.

A well-written EA uses it every time it counts, trails or closes positions: it goes through the open positions and skips any whose magic number is not its own. Manual trades carry 0.

You can see the number in the terminal: MT5 shows it as a tooltip in the list of open positions and orders in the Trade tab of the Toolbox (Ctrl+T), and in the trading history (MT5 release notes).

Worked example: three owners on one account

The magic number separates positions, not money. Manual trades and every EA still share one balance and one pool of margin; the margin calculator shows how much each position ties up.

Common mistakes

Running two copies of an EA with the same number. Two charts, one number: unless the EA also filters by symbol and the charts are on different symbols, each copy sees the other’s trades as its own and can close or resize them.

Expecting magic numbers to separate positions on a netting account. On a netting account there is only one position per symbol, so a manual trade on the EA’s symbol changes the EA’s position instead of opening a separate one. The position keeps the magic number of the deal that opened it (MQL5 article), so volume you add by hand becomes part of what the EA treats as its own.

Closing an EA’s trades by hand without checking. It is possible, from the desktop or the phone, but some EAs react to it, so read the EA’s documentation first. Running an EA with the MT5 mobile app covers what the phone can and cannot do.

Magic numbers in PipWarden

Each trading account on the PipWarden dashboard gets its own magic number, and the EA sends it with every order. The EA manages and counts only positions that carry that number, and only those are recorded as the bot’s trades. Your manual trades and trades from other EAs are left alone.

The same filter defines what the kill switch closes: every position the bot opened, identified by its magic number, and nothing else. The limit on open positions counts only the bot’s positions too. The EA also saves the number in the terminal, in its cached settings and a terminal global variable, so after a restart it recognises its positions before the platform answers. The install guide covers the setup.

Frequently asked questions

What magic number do manual trades have?
Zero. Orders you place by hand carry magic number 0, and it cannot be changed after the trade is opened. An EA that uses 0 as its own number can therefore end up treating your manual trades as its own.
Can two EAs use the same magic number?
They can, but unless each also filters by symbol and the two never trade the same one, neither can tell its positions from the other’s. Position limits, closes and reports then count both EAs’ trades.

Educational content, not financial advice. Forex and CFDs are traded on margin and are high risk: you can lose money, and more than your deposit with some brokers. Examples use made-up numbers and show no real results. Read the risk disclosure.