Supporting Image

Please use the attached image as a reference to incorporate the codes provided below into your Expert Advisor or indicator for implementing a license validation check.

 

License Validation Code {Expert initialization function}

Insert this code just above “Expert Initialization” or “OnInit” function.

				
					// Declare a global variable to track if the delay has passed
bool delayPassed = false;
				
			

Insert the below code in the “Expert Initialization” function. For ease of use, watch the video.

				
					// Determine if running in Strategy Tester
    IsStrategyTester = MQLInfoInteger(MQL_TESTER);

    if (IsStrategyTester)
    {
        Print("Running in Strategy Tester, skipping license validation.");
    }
    else
    {
        // Start a short timer for 3 minutes (180 seconds) to delay execution
        Print("Waiting for license validation...");
        EventSetTimer(180);
    }
				
			

Steps :

Follow the simple instructions on the screen.

  • Open “MT5 Terminal”.
  • In the “Navigator Section” scroll to your Expert Advisor you want to insert the license code in.
  • “Right Click” on the expert advisor.
  • Click on “Modify”.
  • MT5 “Meta Editor” will open with your expert advisor code.
  • Now, in the code, scroll down to “Expert Initialization Function” or “OnInit Function”.
  • Now, open our website and “Log Into It’.
  • Now, from the header menu “more” section, go to “License Code”.
  • Copy the “License Validation Code {Expert initialization function}” and open your “MT5 Meta Editor”.
  • In the “Expert Initialization Function” paste the code just below the first bracket under OnInit function.
  • Now, next step is not add the License Validation Code {Expert deinitialization function}.

License Validation Code {Expert deinitialization function}

Insert the below code in the “Expert deinitialization function”. For ease of use, watch the video.

				
					EventKillTimer(); // Kill the timer when the program is deinitialized
				
			

Steps :

Follow the simple instructions on the screen.

  • Open “MT5 Terminal”.
  • In the “Navigator Section” scroll to your Expert Advisor you want to insert the license code in.
  • “Right Click” on the expert advisor.
  • Click on “Modify”.
  • MT5 “Meta Editor” will open with your expert advisor code.
  • Now, in the code, scroll down to “Expert denitialization Function” or “OnDeinit Function”.
  • Now, open our website and “Log Into It’.
  • Now, from the header menu “more” section, go to “License Code”.
  • Copy the “License Validation Code {Expert deinitialization function}” and open your “MT5 Meta Editor”.
  • In the “Expert DeInitialization Function” paste the code just below the first bracket under (void OnDeinit)
  • Now, last step is to add the “Timer Function” in the program’s code.

License Validation Code {Adding Timer Function}

Insert the below the “Expert deinitialization function”. For ease of use, watch the video.

				
					//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
    if (!delayPassed)
    {
        delayPassed = true;
        EventKillTimer();  // Remove the short delay timer

        // Perform license validation after 3 minutes
        if (!GlobalVariableCheck("LicenseValidated") || GlobalVariableGet("LicenseValidated") == 0)
        {
            Alert("License validation failed. You are not allowed to use this program.");
            ExpertRemove();
            return;
        }
        
        Print("License validation successful. Starting main timer.");
        
        // Set the main timer for 14400 seconds (4 hours)
        EventSetTimer(14400);
    }
    else
    {
        // Regular 4-hour validation check
        if (!GlobalVariableCheck("LicenseValidated") || GlobalVariableGet("LicenseValidated") == 0)
        {
            Alert("License validation failed. You are not allowed to use this program.");
            ExpertRemove();
        }
        else
        {
            Print("License validation check successful.");
        }
    }
}
				
			

Steps :

Follow the simple instructions on the screen.

  • Copy the above “Timer Function Code”.
  • Go back to your program’s code in the “meta editor”.
  • Scroll down to “Expert Deinitialization function”.
  • Now, paste the above full code under the end of “Expert deinitialization function”.
  • Once you have placed all the 3 codes in your program. Click “compile”.
  • That’s it, now your program has been ready for license verification from the server.
  • Repeat the process for MT4 & MT5 both programs.

For ease of use, watch the related videos.

Demo Program Code

Insert the below code in the “Expert Initialization” function. For ease of use, watch the video.

				
					// Check if running in Strategy Tester
if (!MQLInfoInteger(MQL_TESTER))
  {
   Print("Error: This EA can only be used in the MetaTrader Strategy Tester.");
   Alert("Error: This EA can only be used in the MetaTrader Strategy Tester.");
   return INIT_FAILED;
  }

				
			

Steps :

Follow the simple instructions on the screen.

  • Open “MT5 Terminal”.
  • In the “Navigator Section” scroll to your Expert Advisor you want to insert the license code in.
  • “Right Click” on the expert advisor.
  • Click on “Modify”.
  • MT5 “Meta Editor” will open with your expert advisor code.
  • Now, in the code, scroll down to “Expert Initialization Function” or “OnInit Function”.
  • Now, open our website and “Log Into It’.
  • Now, from the header menu “more” section, go to “License Code”.
  • Copy the “License Code” and open your “MT5 Meta Editor”.
  • In the “Expert Initialization Function” paste the code just below the first bracket as you see here.
  • Compile the Expert Advisor. That’s it !

With the exact same way, you can add our demo program into “MT5 Indicator, MT4 Expert Advisor and MT4 Indicator” as well.