MAG - Magic Number
Parameters for the magic number
A magic number is a unique identifier that groups all trades initiated by a specific application. In the context of MetaTrader, this is utilized to prevent interference between different applications. For instance, if applications A and B use 123456 and 654321 as their magic numbers, each trade these applications open will be marked with these numbers. Ideally, each application should only modify trades configured with its magic number. The Custom Expert Advisor strictly adheres to this rule. While every application compatible with MetaTrader should follow this rule, some do not. For this discussion, we'll assume that any third-party application you use does adhere to this rule.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (MAG) Avoided range start (IN_nMagAvoidedRangeStart) | 100000 | The input value cannot be smaller than 0. |
> (MAG) Avoided range end (IN_nMagAvoidedRangeEnd) | 200000 | The input value cannot be smaller than 0. |
Many third-party applications allow you to specify which magic number should be used. However, the Custom Expert Advisor operates on a different principle. Its input parameters > (MAG) Avoided range start and > (MAG) Avoided range end define a range within which a magic number should not be searched and used. Your Custom Expert Advisor will automatically search for an available magic number in the remaining number range. All FEA Trading applications follow this principle. To ensure the applications do not use the same magic numbers, a mechanism is in place to prevent a magic number from being used twice.
The above illustration explains this principle using a number line. Assuming > (MAG) Avoided range start is set to 100.00, and > (MAG) Avoided range end is set to 200.000, the actual randomly selected magic number can be any value between 0 - 99.999 and above 200.000. All applications use 100.000 and 200.000 as default values, so it is recommended to configure any other third-party application with a dedicated magic number between 100.000 and 200.000.