Managing Expert Advisor Magic Number Ranges in MetaTrader
Summary
This document explains a utility for assigning and recognizing magic numbers used by trading Expert Advisors. Magic numbers help an EA distinguish its trades from trades opened by other EAs, including when the same EA runs on the same symbol and timeframe across multiple charts. The library offers shift modes that expand the range of possible magic numbers, from a single value to a much larger set, and includes a function for checking whether a magic number belongs to an EA's range.
The described tradeoff is that larger ranges increase the chance of overlapping with another magic number in the terminal. The comparison function must use the same shift parameter that was used to obtain the number. The document also warns that a magic number cannot be restored after its chart is closed, without explaining a recovery mechanism. It references a sample Expert Advisor but provides no test results or evidence about collision rates, persistence, or behavior in complex multi-chart setups.
Key ideas
- Magic numbers allow an Expert Advisor to identify trades associated with its own logic.
- Shift modes expand an EA's magic number range, with larger ranges increasing the chance of overlap.
- The magic comparison function must receive the shift mode used to generate the number.
- The document warns that a magic number cannot be recovered after its chart closes.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.