Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Libraries | UniMagicNumber

MetaTrader Experts, Indicators, Scripts and Libraries

The library allows receiving a magic number bound to three elements:

  • Symbol (financial instrument) name;
  • Timeframe;
  • Prefix index;

All these three elements are to be encoded in 64 bits, of which:

  • Symbol name = 48 bits (the first 8 characters are taken from the name);
  • Timeframe = 5 bits;
  • Prefix index = 11 bits (may be a number from 0 to 2047, inclusive).

The prefix number is necessary for obtaining several unique magic numbers on a single chart. To do this, we need to call the appropriate function with different prefix indices. The number of prefix indices is limited and may vary from 0 to 2047, inclusive.

To obtain the magic number, just call the function:

ulong GetMagicNumber(ushort prefix,//prefix number                       string symbol,//Symbol name                       ENUM_TIMEFRAMES tf);//Timeframe  

Example of use:

//+------------------------------------------------------------------+  //| Input params  //+------------------------------------------------------------------+  input ushort MagicPrefixNumber_ = 0;    //+------------------------------------------------------------------+  //| Import functions  //+------------------------------------------------------------------+  #import "cUniMagicNumber.ex5"     ulong GetMagicNumber(ushort prefix,//prefix number                          string symbol,//Symbol name                          ENUM_TIMEFRAMES tf);//Timeframe  #import    //+------------------------------------------------------------------+  //| Global Vars  //+------------------------------------------------------------------+  ulong _MagicNumber;    //+------------------------------------------------------------------+  //| Custom indicator initialization function                         |  //+------------------------------------------------------------------+  int OnInit()  {     _MagicNumber = GetMagicNumber(MagicPrefixNumber_, Symbol(), Period());       return (INIT_SUCCEEDED);  }  
22069