How To Install License
1. Include the License Check in Initialization
- Locate the init() function in your EA’s code. This function runs when the EA is first attached to a chart.
- Add the following lines at the beginning of the init() function to perform an initial license check:
int init()
{
// Initial license check on attachment
if(!CheckLicense())
{
ExpertRemove();
return(INIT_FAILED); // Fail to initialize if the license is not valid
}
// Set timer to check the license every 'x' seconds you want, ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return(INIT_SUCCEEDED);
}
2. Set Up License Recheck on Timer
- Ensure that the EA checks the license every x seconds by including the OnTimer() function:
void OnTimer()
{
// Recheck the license
if(!CheckLicense())
{
Print("License invalid. Removing EA.");
ExpertRemove(); // Remove the EA if the license is not valid
}
}
3. Handle Deinitialization
- Properly handle the removal of the EA by killing the timer:
int deinit()
{
// Remove the timer when the EA is removed
EventKillTimer();
return(0);
}
4. Implement the License Check Function
- Add the following function that performs the actual license check with the server:
bool CheckLicense()
{
string cookie = NULL, headers;
char postData[], result[];
string postText, resultText;
string licenseServerUrl = "https://expertadvisorlicense.com/EALicense.php"; // License Server URL
// Account Information
int accountNumber = AccountNumber();
string platform = "MT4"; // Set platform to "MT4"
string type = "Expert Advisor"; // Set type to "Expert Advisor"
string name = "Your EA Name"; // Expert Advisor Name, must be exact with the one in "Licensing" ExpertAdvisorLicense's dashboard
// Prepare POST data
postText = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
// Convert postText to a character array
StringToCharArray(postText, postData, 0, StringLen(postText));
// Execute the WebRequest
int timeout = 10000;
ResetLastError();
int res = WebRequest("POST", licenseServerUrl, "Content-Type: application/x-www-form-urlencoded", timeout, postData, result, headers);
if(res == -1)
{
Print("WebRequest failed, error: ", GetLastError());
return false;
}
// Convert the result back to a string
resultText = CharArrayToString(result);
Print("Received Data: ", resultText);
// Check if "Account Valid" is present in the resultText
if(StringFind(resultText, "Account Valid") == -1)
{
Alert("License Invalid, Contact EA Owner");
return false; // License is not valid
}
return true; // License is valid
}
5. Customize for Your Expert Advisor
- Replace the following placeholders in the CheckLicense() function with your EA-specific details:
- name = “Your EA Name”; : Replace “Your EA Name” with the exact name of your EA as it appears in the licensing dashboard.
6. You are done!
- Attach the EA to a chart in MetaTrader 4 to ensure that it works correctly and verifies the license.
Full-view of the MT4 Expert Advisor License Code
//+------------------------------------------------------------------+
//| MT4 ExpertAdvisorLicense.mq4 |
//| Copyright 2024, ExpertAdvisorLicense |
//| https://expertadvisorlicense.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, ExpertAdvisorLicense"
#property link "https://expertadvisorlicense.com/"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
// Initial license check on attachment
if(!CheckLicense())
{
ExpertRemove();
return(INIT_FAILED); // Fail to initialize if the license is not valid
}
// Set timer to check the license every x seconds, Ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
// Remove the timer when the EA is removed
EventKillTimer();
return(0);
}
//+------------------------------------------------------------------+
//| Timer function to check license every x seconds |
//+------------------------------------------------------------------+
void OnTimer()
{
// Recheck the license
if(!CheckLicense())
{
Print("License invalid. Removing EA.");
ExpertRemove(); // Remove the EA if the license is not valid
}
}
//+------------------------------------------------------------------+
//| Function to check the license |
//+------------------------------------------------------------------+
bool CheckLicense()
{
string cookie = NULL, headers;
char postData[], result[];
string postText, resultText;
string licenseServerUrl = "https://expertadvisorlicense.com/EALicense.php"; // License Server URL
// Account Information
int accountNumber = AccountNumber();
string platform = "MT4"; // Set platform to "MT4"
string type = "Expert Advisor"; // Set type to "Expert Advisor"
string name = "King D"; // Expert Advisor Name, must be exact with the one in "Licensing" ExpertAdvisorLicense's dashboard
// Prepare POST data
postText = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
// Convert postText to a character array
StringToCharArray(postText, postData, 0, StringLen(postText));
// Execute the WebRequest
int timeout = 10000;
ResetLastError();
int res = WebRequest("POST", licenseServerUrl, "Content-Type: application/x-www-form-urlencoded", timeout, postData, result, headers);
if(res == -1)
{
Print("WebRequest failed, error: ", GetLastError());
return false; // Assume license is invalid if the request fails
}
// Convert the result back to a string
resultText = CharArrayToString(result);
//Print("Received Data: ", resultText);
// Check if "Account Valid" is present in the resultText
if(StringFind(resultText, "Account Valid") == -1)
{
Alert("License Invalid, Contact EA Owner");
return false; // License is not valid
}
return true; // License is valid
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void start()
{
}
//+------------------------------------------------------------------+
1. Download and Install the wininet.mqh Library
- Click here to download the wininet.mqh file.
- Place the downloaded wininet.mqh file in the Include folder. ‘Path: MQL4/Include/’
- Including the wininet.mqh in your indicator mq4 file.
#include <wininet.mqh>
2. License Variables
- These variables store the necessary information for the license check.
- Update the name variable to match the name of your indicator exactly as it is registered in the licensing system. Ensure that the platform is set to “MT4” and type is set to “Indicator”.
// License variables
int accountNumber = AccountNumber();
string platform = "MT4"; // Set platform to "MT4"
string type = "Indicator"; // Set type to "Indicator"
string name = "MT4 Indicator License"; // Update According to Your Indicator Name
3. Custom Indicator Initialization
- No changes needed here unless you want to modify the interval at which the license is rechecked. The timer is currently set to 300 seconds (5 minutes). Then place the code into your indicator’s mq4 code.
int init()
{
Print(__FUNCTION__, " > Checking license...");
IndicatorShortName(name);
// Initial license check on attachment
if (!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
return (INIT_FAILED); // Fail to initialize if the license is not valid
}
// Set timer to check the license every 'x' seconds you want, ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return (INIT_SUCCEEDED);
}
4. Indicator Deinitialization
- No changes are necessary here. Place the code into your indicator’s mq4 code.
int deinit()
{
// Remove the timer when the indicator is removed
EventKillTimer();
return (0);
}
5. Timer Function
- No changes are needed here. This ensures that the license remains valid while the indicator is running. You may directly place it into your Indicator’s mq4 code.
void OnTimer()
{
// Recheck the license
if (!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
}
}
6. License Check Function
- No changes are needed here. You may directly place it into your Indicator’s mq4 code.
bool CheckLicense()
{
// URL and Path Separation
string domain = "expertadvisorlicense.com";
string path = "/EALicense.php";
// Prepare POST data
string postData = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
string response;
// Use the PostHTTPRequest function to send data
bool success = PostHTTPRequest(domain, path, postData, response, SSL_ON);
if (!success)
{
Print("Failed to check license. Please contact the owner.");
return false;
}
// Check if "Account Valid" is present in the response
if (StringFind(response, "Account Valid") == -1)
{
Alert("License Invalid, Contact Indicator Owner");
return false; // License is not valid
}
return true; // License is valid
}
7. You are done!
- Attach the Indicator to a chart in MetaTrader 4 to ensure that it works correctly and verifies the license.
Full-view of the MT4 Indicator License Code
//+------------------------------------------------------------------+
//| MT4 IndicatorLicense.mq4 |
//| Copyright 2024, ExpertAdvisorLicense |
//| https://expertadvisorlicense.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, ExpertAdvisorLicense"
#property link "https://expertadvisorlicense.com/"
#property indicator_chart_window
#include <wininet.mqh>
// License variables
int accountNumber = AccountNumber();
string platform = "MT4"; // Set platform to "MT4"
string type = "Indicator"; // Set type to "Indicator"
string name = "MT4 Indicator License Original"; // Indicator Name
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Print(__FUNCTION__, " > Checking license...");
// Set the short name of the indicator
IndicatorShortName(name);
// Initial license check on attachment
if (!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
return (INIT_FAILED); // Fail to initialize if the license is not valid
}
// Set timer to check the license every 5 minutes (300 seconds)
EventSetTimer(60);
Print("License Active");
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
// Remove the timer when the indicator is removed
EventKillTimer();
return (0);
}
//+------------------------------------------------------------------+
//| Timer function to check license every x seconds |
//+------------------------------------------------------------------+
void OnTimer()
{
// Recheck the license
if (!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
}
}
//+------------------------------------------------------------------+
//| Function to check the license using Wininet |
//+------------------------------------------------------------------+
bool CheckLicense()
{
// URL and Path Separation
string domain = "expertadvisorlicense.com";
string path = "/EALicense.php";
// Prepare POST data
string postData = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
string response;
// Use the PostHTTPRequest function to send data
bool success = PostHTTPRequest(domain, path, postData, response, SSL_ON);
if (!success)
{
Print("Failed to check license. Please contact the owner.");
return false;
}
// Check if "Account Valid" is present in the response
if (StringFind(response, "Account Valid") == -1)
{
Alert("License Invalid, Contact Indicator Owner");
return false; // License is not valid
}
return true; // License is valid
}
//+------------------------------------------------------------------+
//| Indicator calculation function |
//+------------------------------------------------------------------+
int start()
{
return (0);
}
//+------------------------------------------------------------------+
1. Include the License Check in Initialization
- Locate the OnInit() function in your EA’s code. This function runs when the EA is first attached to a chart.
- Add the following lines at the beginning of the OnInit() function to perform an initial license check:
int OnInit()
{
// Initial license check on attachment
if(!CheckLicense())
{
ExpertRemove();
return(INIT_FAILED); // Fail to initialize if the license is not valid
}
// Set timer to check the license every 'x' seconds you want, ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return(INIT_SUCCEEDED);
}
2. Set Up License Recheck on Timer
- Ensure that the EA checks the license every x seconds by including the OnTimer() function:
void OnTimer()
{
// Recheck the license
if(!CheckLicense())
{
Print("License invalid. Removing EA.");
ExpertRemove(); // Remove the EA if the license is not valid
}
}
3. Handle Deinitialization
- Properly handle the removal of the EA by killing the timer:
void OnDeinit(const int reason)
{
// Remove the timer when the EA is removed
EventKillTimer();
}
4. Implement the License Check Function
- Add the following function that performs the actual license check with the server:
bool CheckLicense()
{
string url = "https://expertadvisorlicense.com/EALicense.php";
string headers;
char post[];
// Account Information
int accountNumber = (int)AccountInfoInteger(ACCOUNT_LOGIN);
string platform = "MT5"; // Set platform to "MT5"
string type = "Expert Advisor"; // Set type to "Expert Advisor"
string name = "Your Expert Advisor Name"; // Replace with your EA's exact name
// Prepare POST data
string postText = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
// Convert postText to a character array
int len = StringLen(postText);
StringToCharArray(postText, post, 0, len, CP_UTF8);
char result[];
string resultHeaders;
int response = WebRequest("POST", url, headers, 1000, post, result, resultHeaders);
string resultText = CharArrayToString(result);
// Check if "Account Valid" is present in the resultText
if(StringFind(resultText, "Account Valid") == -1)
{
Alert("License Invalid. Contact EA/Indicator Owner.");
return false; // License is not valid
}
return true; // License is valid
}
5. Customize for Your Expert Advisor
- Replace the following placeholders in the CheckLicense() function with your EA-specific details:
- name = “Your Expert Advisor Name”; : Replace “Your Expert Advisor Name” with the exact name of your EA as it appears in the licensing dashboard.
6. You are done!
- Attach the EA to a chart in MetaTrader 5 to ensure that it works correctly and verifies the license.
Full-view of the MT4 Expert Advisor License Code
//+------------------------------------------------------------------+
//| MT5 ExpertAdvisorLicense.mq5 |
//| Copyright 2024, ExpertAdvisorLicense |
//| https://expertadvisorlicense.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, ExpertAdvisorLicense"
#property link "https://expertadvisorlicense.com/"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Initial license check on attachment
if(!CheckLicense())
{
ExpertRemove();
return INIT_FAILED; // Fail to initialize if the license is not valid
}
// Set timer to check the license every x seconds. Ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Remove the timer when the EA is removed
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Timer function to check license every x seconds |
//+------------------------------------------------------------------+
void OnTimer()
{
// Recheck the license
if(!CheckLicense())
{
ExpertRemove(); // Remove the EA if the license is not valid
}
}
//+------------------------------------------------------------------+
//| Function to check the license |
//+------------------------------------------------------------------+
bool CheckLicense()
{
string url = "https://expertadvisorlicense.com/EALicense.php";
string headers;
char post[];
// Account Information
int accountNumber = (int)AccountInfoInteger(ACCOUNT_LOGIN);
string platform = "MT5"; // Set platform to "MT5"
string type = "Expert Advisor"; // Set type to "Expert Advisor"
string name = "Your Expert Advisor Name"; // Your Expert Advisor Name, must be exact with the one in "Licencing" ExpertAdvisorLicense's dashboard
// Prepare POST data
string postText = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
// Convert postText to a character array
int len = StringLen(postText);
StringToCharArray(postText, post, 0, len, CP_UTF8);
char result[];
string resultHeaders;
int response = WebRequest("POST", url, headers, 1000, post, result, resultHeaders);
string resultText = CharArrayToString(result);
// Check if "Account Valid" is present in the resultText
if(StringFind(resultText, "Account Valid") == -1)
{
Alert("Contact EA/Indicator Owner");
return false; // License is not valid
}
return true; // License is valid
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
}
//+------------------------------------------------------------------+
1. Download and Install the wininet.mqh Library
- Click here to download the wininet.mqh file.
- Place the downloaded wininet.mqh file in the Include folder. ‘Path: MQL5/Include/’
- Including the wininet.mqh in your indicator mq4 file.
#include <wininet.mqh>
2. License Variables
- These variables store the necessary information for the license check.
- Update the name variable to match the name of your indicator exactly as it is registered in the licensing system. Ensure that the platform is set to “MT5” and type is set to “Indicator”.
// License variables
int accountNumber = (int)AccountInfoInteger(ACCOUNT_LOGIN);
string platform = "MT5"; // Set platform to "MT5"
string type = "Indicator"; // Set type to "Indicator"
string name = "Your Indicator Name"; //Your Indicator Name, must be exact with the one in "Licencing" ExpertAdvisorLicense's dashboard
3. Custom Indicator Initialization
- No changes needed here unless you want to modify the interval at which the license is rechecked. The timer is currently set to 300 seconds (5 minutes). Then place the code into your indicator’s mq5 code.
int OnInit()
{
// Initial license check on attachment
if(!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
return INIT_FAILED; // Fail to initialize if the license is not valid
}
// Set timer to check the license every x seconds. Ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return(INIT_SUCCEEDED);
}
4. Indicator Deinitialization
- No changes are necessary here. Place the code into your indicator’s mq5 code.
void OnDeinit(const int reason)
{
// Remove the timer when the indicator is removed
EventKillTimer();
}
5. Timer Function
- No changes are needed here. This ensures that the license remains valid while the indicator is running. You may directly place it into your Indicator’s mq5 code.
void OnTimer()
{
// Recheck the license
if(!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
}
}
6. License Check Function
- No changes are needed here. You may directly place it into your Indicator’s mq4 code.
bool CheckLicense()
{
Print(__FUNCTION__, " > Checking license...");
// URL and Path Separation
string domain = "expertadvisorlicense.com";
string path = "/EALicense.php";
// Prepare POST data
string postData = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
string response;
// Use the PostHTTPRequest function to send data
bool success = PostHTTPRequest(domain, path, postData, response, SSL_ON);
if (!success)
{
Print(__FUNCTION__, " > Failed to send POST request.");
Print("Failed to check license. Please contact the owner.");
ChartIndicatorDelete(0, 0, name);
return false;
}
//Print(__FUNCTION__, " > Server response text: ", response);
// Check if "Account Valid" is present in the response
if (StringFind(response, "Account Valid") == -1)
{
Alert("Contact Indicator Owner");
return false; // License is not valid
}
return true; // License is valid
}
7. You are done!
- Attach the Indicator to a chart in MetaTrader 5 to ensure that it works correctly and verifies the license.
Full-view of the MT5 Indicator License Code
//+------------------------------------------------------------------+
//| MT5 Indicator License.mq5 |
//| Copyright 2024, ExpertAdvisorLicense |
//| https://expertadvisorlicense.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, ExpertAdvisorLicense"
#property link "https://expertadvisorlicense.com/"
#property indicator_chart_window
#include <wininet.mqh>
// License variables
int accountNumber = (int)AccountInfoInteger(ACCOUNT_LOGIN);
string platform = "MT5"; // Set platform to "MT5"
string type = "Indicator"; // Set type to "Indicator"
string name = "Your Indicator Name"; //Your Indicator Name, must be exact with the one in "Licencing" ExpertAdvisorLicense's dashboard
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Initial license check on attachment
if(!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
return INIT_FAILED; // Fail to initialize if the license is not valid
}
// Set timer to check the license every x seconds. Ex: 5 minutes (300 seconds)
EventSetTimer(300);
Print("License Active");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Remove the timer when the indicator is removed
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Timer function to check license every 5 minutes |
//+------------------------------------------------------------------+
void OnTimer()
{
// Recheck the license
if(!CheckLicense())
{
ChartIndicatorDelete(0, 0, name);
}
}
//+------------------------------------------------------------------+
//| Function to check the license using Wininet |
//+------------------------------------------------------------------+
bool CheckLicense()
{
Print(__FUNCTION__, " > Checking license...");
// URL and Path Separation
string domain = "expertadvisorlicense.com";
string path = "/EALicense.php";
// Prepare POST data
string postData = "account_no=" + IntegerToString(accountNumber) +
"&platform=" + platform +
"&type=" + type +
"&name=" + name;
string response;
// Use the PostHTTPRequest function to send data
bool success = PostHTTPRequest(domain, path, postData, response, SSL_ON);
if (!success)
{
Print(__FUNCTION__, " > Failed to send POST request.");
Print("Failed to check license. Please contact the owner.");
ChartIndicatorDelete(0, 0, name);
return false;
}
//Print(__FUNCTION__, " > Server response text: ", response);
// Check if "Account Valid" is present in the response
if (StringFind(response, "Account Valid") == -1)
{
Alert("Contact Indicator Owner");
return false; // License is not valid
}
return true; // License is valid
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
return(rates_total);
}
//+------------------------------------------------------------------+