Adding License Code to MT4 Indicator

A step-by-step guide on adding a license code to your MT4 Indicator.

Step 1: Copy the MetatraderValidation.ex4 file

Open your download folder and copy the MetatraderValidation.ex4 file.

Alt Text

Step 2: Open MT4 Application

Open the MetaTrader 4 (MT4) application.

Alt Text

Step 3: Open Data Folder

Go to "File" in the top menu and click "Open Data Folder."

Alt Text

Step 4: Navigate to MQL4 Folder

In the Data Folder, click on the "MQL4" folder.

Alt Text

Step 5: Open Libraries Folder

Within the MQL4 folder, locate and open the "Libraries" folder.

Alt Text

Step 6: Paste MetatraderValidation.ex4

Paste the MetatraderValidation.ex4 file you copied earlier into the "Libraries" folder.

Alt Text

Step 7: Navigate to Indicators Folder

Go back to the "MQL4" folder and click on the "Indicators" folder.

Alt Text

Step 8: Open the Indicators

Locate and open the Indicator you want to license using the MetaEditor.

Alt Text

Step 9: Add License Code (Above OnInit)

Place the following code above the OnInit() function of your Indicator:

//-------------------License Code Start----------------------//

#import "MetatraderValidation.ex4"
bool Validate(string Serialkey,string productCode);
void updateConnectionStatus(string);
void updateHardwareId(string);
void updateConnectionStatusConnected(string);
void updateConnectionStatusDisconnected(string);

#import
bool auth = false;

input string strMA1="---------------------------------------- License Input ----------------------------------------";//<<<<<<<< License Input >>>>>>>>

input string serialkey = ""; //Serial Keys
string ProductCode="MACD Demo EA";//Product Code
string shortname;

//----------------License Code End--------------------------//

Alt Text

Step 10: Add License Code (OnInit)

Place the following code inside the OnInit() function of your Indicator:

//-------------------License Code Start----------------------//

if(IsDllsAllowed()==false) 
    { 
     Alert("DLL call is not allowed. Indicator cannot run.");
    } 
   if(MQLInfoInteger(MQL_OPTIMIZATION) == 0)
     {
      updateHardwareId(serialkey);
      auth = Validate(serialkey,ProductCode);
      if(auth == true)
        {
         Comment("Active");
         updateConnectionStatusConnected(serialkey);
        }
      if(auth == false)
        {
         Comment("Inactive. Contact Provider to Activate");
         shortname=ProductCode;
         IndicatorSetString(INDICATOR_SHORTNAME,shortname);
         int window=ChartWindowFind();
         bool res=ChartIndicatorDelete(0,window,shortname);
         return(INIT_FAILED);
        }
     }

//----------------License Code End--------------------------//

Alt Text

Step 11: Add License Code (OnDeinit)

Add the following code at the end of your Indicator:

//-------------------License Code Start----------------------//

void OnDeinit(const int reason)
  {
if(MQLInfoInteger(MQL_OPTIMIZATION) == 0)
     {
      updateConnectionStatusDisconnected(serialkey);
     }
  }

//----------------License Code End--------------------------//

Alt Text

Step 12: Add License Code (OnCalculate)

Place the following code inside the OnCalculate() function of your Indicator:

//-------------------License Code Start----------------------//

  if(MQLInfoInteger(MQL_OPTIMIZATION) == 0 && MQLInfoInteger(MQL_TESTER) == 0)
     {
      auth = Validate(serialkey,ProductCode);
      if(auth == true)
        {
         Comment("Active");
        }
      if(auth == false)
        {
         Comment("Inactive. Contact Provider to Activate");
         return(rates_total);
        }
     }
//----------------License Code End--------------------------//

Alt Text

Step 13: Replace the Product Code

Replace the string "MACD Demo EA" with your generated Product Code, the Indicator will use this Product Code to validate the license key provided by the client using the MetaTraderValidation library.

Alt Text

Alt Text

Step 14: Compile and Provide to Client

Compile the Indicator and provide your client the resulting .ex4 files (yourIndicator.ex4 and MetatraderValidation.ex4).

Step 15: Instruct the Client

Instruct your client to enter the Serial Key in the "serial key" input field of the Indicator when placing the Indicator on the chart.

Alt Text

Step 16: Validation

The Indicator will validate the Serial Key with the MetaTraderValidation library and allow the client to use the Indicator if the validation is successful.

Alt Text