Thursday, March 1, 2012

Magic Numbers in MT4

The magic number is a Mt4 concept used to track the open positions of an EA. The allows the Expert advisor to distinguish the trades that it opened versus those that it did not.

Every car uses a license plate. When you see a car in a foreign state or even a foreign country, you notice that every plate that you see is unique. The police can utitlize the number to determine who owns the car.

Magic numbers act like the license plates for EA's. When an expert advisor sees an open trade, called a ticket, it frequently looks up its magic number. If the magic number of the ticket is identical to the number that the expert advisor expects, then the EA concludes that it needs to manage the position.

Magic numbers are valuable, especially when you want to trade multiple time frames of the identical currency pair. Traders repeatedly use settings that differ from those on M1 charts versus those that they would use on the day chart. If they used the Expert advisor with the identical magic number on all different time frames, the consequence would be chaos. The expert advisor would enter and exit positions with no rhyme or reason. Setting each Expert advisor to utilize an independent magic number prevents the robots from obstructing the others.

Magic number factoids

The magic number of a trade that you open yourself is 0.
The value of a magic number must fall between 0 and 2147483647. The MQL programming language calls that last number EMPTY_VALUE and reserves the name as an integer value.