Documentation

Complete guide to integrating and using ProtectEAs

Quick Start Guide

1. Download License Manager File

Download the ProtectEAs_LicenseManager.mqh file and place it in your MT4/MT5 include folder:

2. Add Protection Code

Follow these simple 3 steps to integrate the protection system:

  1. Add an input for the license key
  2. Initialize the License Manager with your Product API key
  3. Check the license in the OnInit() function

// 1. Add input for license key
input string InpLicenseKey = "";    // License Key

// 2. Initialize License Manager with your Product API key
#include <ProtectEAs_LicenseManager.mqh>
CLicenseManager g_license(
    "YOUR-API-KEY-HERE",  // Your Product API key from ProtectEAs.com/manager
    true,                 // Check account number
    false,                // Check symbol
    false,                // Check timeframe
    true,                // Show alerts for license status
    true,                // Play sound when license verification succeeds or fails
    false,               // Remove EA if license check fails
    true                 // Use DLL for HTTP requests
);

// 3. Check license in OnInit()
int OnInit()
{    
    // Verify license on startup
    if(!g_license.VerifyLicense(InpLicenseKey))
    {
        Print("License verification failed. EA will not start.");
        return INIT_FAILED;
    }
    
    // Your EA initialization code here
    return INIT_SUCCEEDED;
}
                            

Integration Guide

Step 1: Add License Manager File

Download the ProtectEAs_LicenseManager.mqh file and place it in your MetaTrader include directory:

  • MT4: ...\MQL4\Include\
  • MT5: ...\MQL5\Include\
Step 2: Add License Key Input

Add an input parameter to your EA or indicator for the license key:


//+-------------------------------------------------------------------+
//| Input for the license key that you will share with your client    |
//| after creating it in ProtectEAs.com/manager/index.php?tab=licenses|
//+-------------------------------------------------------------------+
input string InpLicenseKey = "";    // License Key   
                            
Step 3: Initialize License Manager

Include the License Manager file and initialize it with your product API key:


//+------------------------------------------------------------------+
//| ADD LicenseManager and set the product API key                   |
//+------------------------------------------------------------------+
#include <ProtectEAs_LicenseManager.mqh>
CLicenseManager g_license(
    "YOUR-API-KEY-HERE",  // Your Product API key from ProtectEAs.com/manager
    true,                 // Check account number
    false,                // Check symbol
    false,                // Check timeframe
    true,                 // Show alerts for license status
    true,                 // Play sound when license verification succeeds or fails
    false,                // Remove EA if license check fails
    true                  // Use DLL for HTTP requests
);
                            
Step 4: Verify License in OnInit()

Add license verification to your OnInit() function:


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{    
    // Verify license on startup
    if(!g_license.VerifyLicense(InpLicenseKey))
    {
        Print("License verification failed. EA will not start.");
        return INIT_FAILED;
    }
    
    Print("License verified successfully. EA is running.");
    return INIT_SUCCEEDED;
}
                            
Step 5: Optional - Periodic Verification

Optionally, add periodic verification in your OnTick() function:


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    // Verify license periodically (handled internally - checks once per hour max)
    if(!g_license.VerifyLicense(InpLicenseKey))
    {
        return; // Skip trading if license verification fails
    }
    
    // Your trading logic here
    // ...
}
                            

Code Examples

Complete Example

Here's a complete working example of an EA with license protection:


//+------------------------------------------------------------------+
//|                                           ProtectEAs_Example.mq4 |
//|                                                 © ProtectEAs.com |
//|                                           https://ProtectEAs.com |
//+------------------------------------------------------------------+
//| This is a simple example showing how to use ProtectEAs License   |
//| Manager in your Expert Advisor.                                  |
//+------------------------------------------------------------------+

//+-------------------------------------------------------------------+
//| (1) Input for the license key that you will share with your client|
//| after creating it in ProtectEAs.com/manager/index.php?tab=licenses|
//+-------------------------------------------------------------------+
input string InpLicenseKey = "";    // License Key    

//+------------------------------------------------------------------+
//| (2) ADD LicenseManager and set the product API key               |
//+------------------------------------------------------------------+
#include <ProtectEAs_LicenseManager.mqh>
CLicenseManager g_license(
    "YOUR-API-KEY-HERE",  // Your Product API key from ProtectEAs.com/manager
    true,                 // Check account number
    false,                // Check symbol
    false,                // Check timeframe
    true,                 // Show alerts for license status
    true,                 // Play sound when license verification succeeds or fails
    false,                // Remove EA if license check fails
    true                  // Use DLL for HTTP requests
);

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{    
    // (3)Verify license on startup
    if(!g_license.VerifyLicense(InpLicenseKey))
    {
        Print("License verification failed. EA will not start.");
        return INIT_FAILED;
    }
    
    Print("License verified successfully. EA is running.");
    return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    // (4) (optional) Verify license periodically 
    if(!g_license.VerifyLicense(InpLicenseKey))
    {
        //Print("License verification failed. EA will stop trading.");
        return;
    }
    
    // Your trading logic here
    // ...
}
                            
Indicator Example

For indicators, the implementation is very similar:


//+------------------------------------------------------------------+
//|                                 ProtectEAs_Indicator_Example.mq4 |
//|                                                 © ProtectEAs.com |
//|                                           https://ProtectEAs.com |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window

input string InpLicenseKey = "";    // License Key

#include <ProtectEAs_LicenseManager.mqh>
CLicenseManager g_license(
    "YOUR-API-KEY-HERE",  // Your Product API key
    true,                 // Check account number
    false,                // Check symbol
    false,                // Check timeframe
    true,                 // Show alerts
    true,                 // Use sounds
    false,                // Remove if fails
    true                  // Use DLL 
);

int OnInit()
{
    if(!g_license.VerifyLicense(InpLicenseKey))
    {
        Print("License verification failed. Indicator will not start.");
        return INIT_FAILED;
    }
    
    return INIT_SUCCEEDED;
}

int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], 
                const double &open[], const double &high[], const double &low[], 
                const double &close[], const long &tick_volume[], const long &volume[], 
                const int &spread[])
{
    // Optional periodic verification
    if(!g_license.VerifyLicense(InpLicenseKey))
        return 0;
        
    // Your indicator calculation logic here
    return rates_total;
}
                            

Downloads

License Manager File

Download the License Manager file to integrate with your EAs and indicators:

Example Templates

Download complete example templates for MT4 and MT5:

Additional Information

How License Verification Works
  1. Initial Check:
    • License is verified when EA/Indicator is first loaded
    • If verification fails, EA/Indicator will not start
  2. Periodic Checks:
    • Can be used in OnTick(), OnTimer(), OnCalculate()
    • Checks are limited to once per hour to avoid server load
    • Between checks, last verification result is used
    • Immediate re-check if trading account is changed
  3. Quick Testing:
    • To force immediate verification, remove and re-add EA/Indicator or Switch the account
    • Each new load triggers a fresh server verification
  4. Offline/Error Handling:
    • If connection fails, cached result is used for 24 hours
    • After 24 hours, valid connection is required
DLL Usage in License Verification

The license verification system can use two methods to communicate with the license server:

  1. DLL Method: Uses direct Windows DLL calls for HTTP requests (faster, more reliable)
  2. WebRequest Method: Uses MQL's built-in WebRequest function (limited to Expert Advisors only)

Important Notes about DLL Usage:

  • For Indicators: DLLs are automatically used regardless of your settings because WebRequest is not available in indicators
  • For Expert Advisors: You can choose to use either DLLs or WebRequest
  • No Additional Files Required: The DLL method uses Windows system DLLs (kernel32.dll and wininet.dll) that are already included in Windows by default
  • Non-Windows Users: If you or your clients use macOS or Linux, DLL imports may not work. In this case, WebRequest must be used (Expert Advisors only)
To Enable DLL Usage (Recommended):
  1. In MetaTrader, go to Tools → Options → Expert Advisors
  2. Check the option "Allow DLL imports"
  3. Set useDLL = true in CLicenseManager constructor
If You Prefer Not to Use DLLs (Expert Advisors only):
  1. Set useDLL = false in CLicenseManager constructor
  2. In MetaTrader, go to Tools → Options → Expert Advisors
  3. Check the option "Allow WebRequest for listed URL"
  4. Add "https://ProtectEAs.com" to the allowed URLs list
Important for Developers: If you choose not to use DLLs, every end-user of your protected product will need to add "https://ProtectEAs.com" to their allowed URLs list in MetaTrader settings. You should include this requirement in your product documentation and installation instructions.
Note: If DLLs are not allowed and you try to use a protected indicator, it will not work. Indicators must use DLLs for license verification since WebRequest is not available.
CLicenseManager Parameters
Parameter Description Default
api_key Your product API key from ProtectEAs manager ""
checkAccountNumber Check account number when validating true
checkSymbol Restrict license to specific symbol false
checkTimeframe Restrict license to specific timeframe false
alerts Show alerts for license status true
useSounds Play sounds for notifications true
remove_EA_on_fail Remove EA if license check fails false
useDLL Use DLL for HTTP requests true

Troubleshooting

Common Issues

Check these common causes:
  • Enable alerts and check the Experts tab in ToolBox
  • You will find all the information you need there

Common compilation issues:
  • ProtectEAs_LicenseManager.mqh is not in the Include directory
  • Incorrect file path in #include statement

If you're seeing DLL errors:
  • Make sure DLL imports are allowed in MT4/MT5 settings (Tools → Options → Expert Advisors)
  • For indicators, DLLs must be enabled as WebRequest is not available
  • Check that you have properly set the useDLL parameter to true in CLicenseManager constructor
  • If using a non-Windows operating system (macOS/Linux), DLL imports may not work. Use WebRequest instead for Expert Advisors