Home / Blog / Add License Verification to Your EA | MQL4/MQL5 Tutorial

Add License Verification to Your EA | MQL4/MQL5 Tutorial

License verification system for an MT4 and MT5 Expert Advisor using security checks

Want to protect your Expert Advisor from unauthorized use? This tutorial shows you exactly how to add license verification to your MT4 or MT5 EA. No servers. No databases. No backend experience required.

What You’ll Build

By the end of this tutorial, your EA will:

  1. Check license status on every startup, and again every hour while it runs
  2. Auto-register new users as trial accounts
  3. Display trial days remaining to prospects
  4. Block execution when license is invalid or expired

You’ll manage everything from a web dashboard —no recompiling needed.

Prerequisites

Step 1: Create Your LicenseShield Account

  1. Go to licenses.barmenteros.com/register
  2. Enter your email and create a password
  3. Verify your email (check spam folder if needed)
  4. Log in to your dashboard

On the dashboard, click Generate API Key and copy the key. Keep this tab open —you’ll need it in Step 3.

Step 2: Download the MQL Library

The integration kit is one file. On the dashboard, the Quick Start Guide has its download button under a MetaTrader 4 and a MetaTrader 5 tab:

  1. Pick your platform’s tab and download LicenseShield.mqh
  2. In MetaEditor, choose File → Open Data Folder and open the MQL4 folder (MT5: MQL5)
  3. Copy LicenseShield.mqh into Include\. Nothing goes in Libraries\.

The license check is compiled into your EA, so your customers install nothing. An EA needs no DLL: the kit verifies over MetaTrader’s WebRequest. Protecting an indicator instead? It uses LicenseShieldInd.mqh, copied into the same Include\ folder, and does need “Allow DLL imports”; the Docs page in your dashboard covers it.

Step 3: Add Verification to Your EA

Press F4 in MetaTrader to open MetaEditor and open your EA’s source file. Add the #include and #define lines near the top, then call the two guard functions from OnInit() and OnTick(), as below. The code is the same on both platforms; only the platform name and the folder in the comments differ.

MQL4 Version

//+------------------------------------------------------------------+
//| LicenseShield Integration (MT4) - one include + two calls        |
//+------------------------------------------------------------------+

// FILE (from the Download button above) - the only file you need:
//   LicenseShield.mqh -> MQL4\Include\
// The license check is compiled into your EA. Your customers install nothing.

// SETUP: In MetaTrader (Tools > Options > Expert Advisors):
//   "Allow WebRequest for listed URL" - add: https://api-licenses.barmenteros.com
//   No "Allow DLL imports" needed - EAs verify over WebRequest only.

#include <LicenseShield.mqh>

// Your API Key (keep this secret - do not expose as an input!)
#define API_KEY "YOUR_API_KEY"

int OnInit()
{
   // Verifies on startup; a new account gets a free trial automatically.
   // Retries brief connection problems; fails only on a genuine rejection.
   if(LicenseShield_Guard_OnInit(API_KEY) == INIT_FAILED)
   {
      return INIT_FAILED;
   }

   // ... your existing initialization code here ...

   return INIT_SUCCEEDED;
}

void OnTick()
{
   // Re-verifies every 60 minutes and keeps the last good result through a
   // connection drop. It stops the EA only if the server rejects the license
   // or the API key, or if no check has succeeded for 72 hours.
   if(!LicenseShield_Guard_Tick())
   {
      return;
   }

   // Your trading logic here
}

MQL5 Version

//+------------------------------------------------------------------+
//| LicenseShield Integration (MT5) - one include + two calls        |
//+------------------------------------------------------------------+

// FILE (from the Download button above) - the only file you need:
//   LicenseShield.mqh -> MQL5\Include\
// The license check is compiled into your EA. Your customers install nothing.

// SETUP: In MetaTrader (Tools > Options > Expert Advisors):
//   "Allow WebRequest for listed URL" - add: https://api-licenses.barmenteros.com
//   No "Allow DLL imports" needed - EAs verify over WebRequest only.

#include <LicenseShield.mqh>

// Your API Key (keep this secret - do not expose as an input!)
#define API_KEY "YOUR_API_KEY"

int OnInit()
{
   // Verifies on startup; a new account gets a free trial automatically.
   // Retries brief connection problems; fails only on a genuine rejection.
   if(LicenseShield_Guard_OnInit(API_KEY) == INIT_FAILED)
   {
      return INIT_FAILED;
   }

   // ... your existing initialization code here ...

   return INIT_SUCCEEDED;
}

void OnTick()
{
   // Re-verifies every 60 minutes and keeps the last good result through a
   // connection drop. It stops the EA only if the server rejects the license
   // or the API key, or if no check has succeeded for 72 hours.
   if(!LicenseShield_Guard_Tick())
   {
      return;
   }

   // Your trading logic here
}

Replace YOUR_API_KEY with the API key from your dashboard, and keep it in the #define: an input would show it to anyone who runs the EA.

Step 4: Enable WebRequest

Before testing, you need to allow your EA to make web requests:

  1. In MetaTrader, go to Tools → Options → Expert Advisors
  2. Check “Allow WebRequest for listed URL“
  3. Add: https://api-licenses.barmenteros.com (the API address, not the dashboard)
  4. Click OK

“Allow DLL imports” is not needed: the EA kit verifies over WebRequest only.

Step 5: Compile and Test

  1. Compile your EA in MetaEditor (F7)
  2. Attach to any chart in your demo terminal
  3. Check the Experts tab for the verification result

You should see something like:

LicenseShield: guard v2.0.0 (mql5/webrequest) starting - re-verify every 60 min, staleness bound 72 h
LicenseShield: license verified

That is the MT5 output; on MT4 the first line reads mql4/webrequest. A first line that starts guard v1. means the EA was compiled with an earlier kit.

Step 6: Check Your Dashboard

Go back to your LicenseShield dashboard and open the Licenses tab.

You’ll see a new entry:

AccountBrokerStatusLast Seen
12345678Name-Demo01Trial (7 days)Just now

This account was auto-registered as a trial. No manual setup needed!

Managing Licenses

Approving a Paid Customer

When a customer pays (or you want to extend a trial):

  1. Find their account in your license list
  2. Look for the Actions column on the right
  3. Click the Reactivate or Enable button
  4. Done —the Status updates to “Active” immediately

Revoking Access

If a customer requests a refund or their subscription expires:

  1. Find their account
  2. Click the Disable button in the Actions column
  3. The Status changes to “Disabled“
  4. A running EA stops at its next check (every 60 minutes by default), and it will not start again

Regenerating your API key or deleting your account works differently by kit. Programs built with LicenseShield kit 2.0 or later stop at their next license check (within 60 minutes by default). Programs built with an earlier kit stop at their next restart. To see which kit a program uses, check its startup line in the Experts log.

Viewing Activity

The Last Seen column shows when each license was last verified. Use this to:

  • Identify active vs. inactive customers
  • Track trial users who might convert
  • See which accounts are actually using the EA

Handling Edge Cases

What if the user has no internet?

An EA built with LicenseShield kit 2.0 or later still starts when it cannot reach our server, but paused, not licensed: it makes three quick attempts, keeps retrying (after 1, 2, 4… minutes) and starts working at the first successful check. Until then LicenseShield_Guard_Tick() returns false, so your trading logic does not run, and LicenseShield never fabricates a valid license. An EA built with an earlier kit tries three times and then returns INIT_FAILED. If the connection drops while the EA is already running, it keeps working (see below).

What about Strategy Tester?

The library detects the Strategy Tester and skips the license check there, so your EA works in backtests without license issues. Live and demo charts always verify.

What if LicenseShield is down?

LicenseShield runs serverless on a cloud server infrastructure (99.9%+ uptime). A program built with LicenseShield kit 2.0 or later keeps running on its last good check and retries at each interval, for up to 72 hours without reaching the server; after that it stops at the next failed check. A program that starts while the server cannot be reached loads paused and starts working at the first successful check. Programs built with an earlier kit keep running until their next restart. LicenseShield never fabricates a valid license.

Upgrading Beyond Free Tier

The Free tier includes:

  • 10 verifications/day
  • 1 license
  • 7-day fixed trial period

If you’re selling more EAs or need higher limits, view pricing →

Summary

You’ve just added professional license verification to your EA:

  1. Created a LicenseShield account
  2. Downloaded the kit file
  3. Added one include and two guard calls
  4. Enabled WebRequest
  5. Tested the integration

Now you can focus on building great trading software —LicenseShield handles the licensing.

Questions? Reply to any LicenseShield email or contact [email protected].

Ready to protect your EA?

Leave a Reply

Your email address will not be published. Required fields are marked *

Get a free quote

Fixed price within 24–48 hours. No subscriptions, no demos.