EA LicenseManager

EA Integration

Drop-in MQL5 CheckLicense() that matches this tool's 4-digit key algorithm

How it works
  1. The web tool generates a 4-digit license key that is deterministically derived from the MT5 account number — the same account number can only ever produce one specific key.
  2. The MQL5 function below runs the identical hash algorithm inside the EA, so no network call is needed — the EA validates offline.
  3. Because the key is tied to the account number, a customer cannot share or transfer their key — it will fail on any other account.

Replace the existing CheckLicense() function in your EA with the code below. Do not add a second copy — only one definition is allowed in MQL5.

MQL5 — CheckLicense()
//+------------------------------------------------------------------+
//| License Check — paste this into your EA, replacing the existing |
//| CheckLicense() function. The algorithm is identical to the web  |
//| tool so the same 4-digit key is produced for every account.     |
//+------------------------------------------------------------------+
bool CheckLicense()
{
   long   accountNumber = AccountInfoInteger(ACCOUNT_LOGIN);
   uint   seed          = (uint)accountNumber;

   // ---- same hash chain used by the web tool ----
   uint magic1 = 0x9e3779b9;
   uint h      = (seed ^ magic1);
   h = (h ^ (h >> 16)) * 0x45d9f3b;
   h = (h ^ (h >> 13));
   h = h * 0x6c62272e;
   h = (h ^ (h >> 16));
   // -----------------------------------------------

   string expectedKey = IntegerToString((int)(h % 9000) + 1000);

   if(InpLicenseKey == expectedKey)
   {
      Print("License OK — account: ", accountNumber, "  key: ", expectedKey);
      return true;
   }

   Print("License FAILED — account: ", accountNumber,
         "  expected: ", expectedKey,
         "  provided: ", InpLicenseKey);
   return false;
}

Integration steps

1

Open your EA source file in MetaEditor.

2

Locate the existing CheckLicense() function and delete it entirely.

3

Paste the copied code in its place.

4

Ensure InpLicenseKey input parameter is declared (string type) — it already exists in the EA shown above.

5

Compile (F7). The EA will now validate keys generated by this web tool.