Mastering the Magic Number: Your Guide to Order Identification in MetaTrader

If you’re venturing into automated trading with MetaTrader 4 or 5, you’ve likely encountered a crucial but often misunderstood setting: the “Magic Number” (sometimes just called “Magic”). Far from being a mystical figure, this parameter is a fundamental tool for maintaining order and control in your trading account. Whether you’re a novice user running a single Expert Advisor (EA) or an advanced trader managing a portfolio of robots, understanding the Magic Number is essential for efficient and error-free operation.

What is a Magic Number?

At its core, a Magic Number is a unique integer identifier assigned to every order placed by an Expert Advisor or script. Think of it as a digital “nametag” or “ID badge” for each trade. Its primary purpose is to allow an EA to distinguish its own orders from those placed by:

  • Other EAs running on different charts.
  • Manual trades you’ve executed yourself.
  • Scripts or other automated tools.
  • Without this identifier, an EA would see a chaotic list of all open orders and positions on your account, making it impossible to manage its own strategy logically. It could mistakenly close trades from another system or incorrectly calculate its own position size.

    The Default: Manual Orders and the Zero Magic

    A key point of confusion is the Magic Number for manual trades. By default, any order opened directly from the MetaTrader terminal—by clicking Buy or Sell—receives a Magic Number of 0. This zero value acts as a universal flag, indicating “this trade was not initiated by automated code.” For an EA to recognize and manage manual trades, it must be specifically programmed to look for orders with Magic 0.

    Locating and Configuring the Magic Number Setting

    Most well-designed commercial and free Expert Advisors expose the Magic Number as a configurable input parameter for the user.

    How to Find It:

  • Attach your EA to a chart.
  • Open the EA’s settings dialog.


  • You can do this by:

  • Pressing the F7 key on your keyboard.
  • Right-clicking on the chart, selecting “Expert Advisors”, and then clicking “Properties…”.
  • Clicking the “Expert Advisors” button on the toolbar.
  • Double click on the parameter and set your identifier.

    expert advisor magic and license number

    How to Set It:

    Within the settings list (usually under the “Inputs” or “Common” tab), look for a parameter named “Magic Number,” “Magic,” or “Identifier.” It is typically found near the top of the list. Simply double-click on the value field and enter your chosen unique number (e.g., 123456, 1001, 888).

    Important Note: If you cannot find this option in the settings, it means the EA developer has hard-coded the Magic Number into the program’s logic. This is common in simpler or older EAs. In this case, you cannot change it, and the EA will only manage orders with its predefined identifier.

    Practical Configuration Scenarios & Best Practices

    How you configure your Magic Number depends entirely on your trading setup:

    Running a Single EA: You can often leave the number at its default setting (frequently 0 or a pre-set like 123456). However, setting a unique, non-zero number (e.g., 100001) is a good practice for future-proofing.

    Running Multiple EAs on One Account (Portfolio Trading): This is where the Magic Number becomes critical. You must assign a unique, non-overlapping Magic Number to each EA. For example:

  • EA on EUR/USD: Magic = 111111
  • EA on GBP/USD: Magic = 222222
  • EA on Gold: Magic = 333333
  • This ensures each robot manages only its own trades, preventing catastrophic interference where one EA closes another’s positions.

    Using a Recovery Manager, Trade Copier, or Trade Panel: These utility tools are designed to manage orders from a specific EA. For them to function correctly, you must configure their Magic Number filter to match exactly the Magic Number of the EA they are supposed to support. This directs the tool to monitor and act on the correct set of trades.

    Enabling an EA to Manage Manual Trades: If you want your EA to apply its management rules (like adding trailing stops or closing conditions) to trades you opened manually, you typically need to set the EA’s Magic Number to 0. This instructs it to look for orders with the manual trade identifier. (Warning: Ensure the EA’s logic is designed for this, as it can be risky.)

    Advanced Considerations & Troubleshooting

  • Uniqueness is Key: Treat your Magic Numbers like passwords for your EAs. Avoid simple sequences and aim for a range with a wide gap between numbers used by different systems.
  • Persistence: An order retains its Magic Number until it is closed. If you change an EA’s Magic Number, it will ignore its previously opened trades and only look for new ones with the new identifier.
  • Troubleshooting “Ghost Orders”: If an EA seems to be ignoring trades, the first step is to verify that the Magic Number on the open order (viewable in the “Trade” tab of the Terminal window) matches the Magic Number set in the EA’s properties.
  • Scripts vs. EAs: Scripts, which execute once, can also use a Magic Number when they place orders. This helps identify which script was responsible for a trade later on.


  • In summary, the Magic Number is a simple yet powerful concept that brings order to automated trading. By taking a moment to configure it thoughtfully, you create a clean, manageable, and conflict-free trading environment, allowing your EAs to perform their tasks with precision and reliability.

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    This blog is kept spam free by WP-SpamFree.