Using Magic Numbers to Isolate Expert Advisor Orders
Summary
The document explains how an Expert Advisor can use an order’s MagicNumber field to distinguish its trades from positions opened manually or by other automated systems. It presents common multi-strategy situations and recommends assigning each trading expert a distinct, nonzero identifier, then filtering selected orders by that value before managing them. An assisting expert intended to modify manual positions can instead select orders with the default identifier of zero.
A MACD zero-line example demonstrates the implementation: the expert checks the symbol and order type, then closes or retains only positions matching its configured identifier, and assigns that identifier when sending new orders. The article notes that identifiers should differ when running multiple instances on the same symbol and period. This is an order-management technique, not a trading signal or performance method; the example is written for the older MQL4 interface, and the identifier scheme depends on each expert applying the filtering consistently.
Key ideas
- A MagicNumber is a user-defined order identifier that lets automated systems recognize their own positions.
- An Expert Advisor should filter orders by both symbol and its configured identifier before managing them.
- Separate experts need distinct identifiers when they may trade the same symbol and timeframe.
- An assistant that should act only on manually opened orders can target the default zero identifier.
- The MACD example illustrates order ownership management rather than evidence of strategy profitability.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.