Blog & News

Request for Quote

Using SLiM 2.0?

Get information about better functions for license validation techniques and about better place in mql code to check for license settings.

Preface

This article related to Metatrader programming and AirBionicFX SLiM 2.0 MQL API programming.
Product homepage: http://www.airbionicfx.com/slim/

SLiM 2.0 is License Management Software for Metatrader platform based programs such as Custom Indicators, Expert Advisors, Scripts and Libraries. SLiM 2.0 allows to protect and control programs by serial number.

What needed before start?

  1. Download Metatrader Terminal from the official site (www.metaquotes.net) and install in.
  2. Download SLiM 2.0 library (http://www.airbionicfx.com/downloads/SLiM.ex4) and place it to Metatrader/experts/libraries/

Local time or Current time?

There are two methods to determine time in Metatrader system.

datetime TimeCurrent() – returns the last known server time.
datetime TimeLocal() – returns local computer time.

Time taken from broker’s server (TimeCurrent()) by far not always matches the current local time (TimeLocal()). However local time is easy to change while broker’s side time will continue its even flow untouched.

Therefore, if license is time limited, one must use TimeCurrent() function.

Take a look at the following example.


#property copyright "AirBionicFX"
#property link      "http://www.airbionicfx.com/"

// SLiM 2.0 API Functions Declaration
#import "SLiM.ex4"
   bool      SLiM_ApplyLicense(string SN, string Key, string ProductTitle);
   int       SLiM_GetProductId();
   int       SLiM_GetMajorProductVersion();
   int       SLiM_GetMinorProductVersion();
   int       SLiM_GetLicenseType();
   bool      SLiM_GetLockedByTime();
   bool      SLiM_GetLockedByAccountNumber();
   int       SLiM_GetAccNum();
   datetime  SLiM_GetExpirationDate();
#import

// SLiM 2.0 License Information Section
extern string License_SerialNumber="";
       string License_Key="slimtestkey";
       string License_ProductTitle="slimtestea1";

int init()
{
   return(0);
}

int start()
{
   bool ApplyResult=SLiM_ApplyLicense(License_SerialNumber,License_Key,License_ProductTitle);
   if (!ApplyResult)
      Alert("FAILED");
   else
   {
      if (SLiM_GetLockedByTime())
         if (TimeCurrent()>SLiM_GetExpirationDate())
            Alert("License has expired!");
         else
            Alert("SUCCEED");
   }
   return(0);
}

int deinit()
{
   return(0);
}

Start function takes the following steps:

  1. Checks the serial number for match
  2. Checks if license is time limited
  3. If license is time limited checks whether usage duration is ended or not. It is imperative to use TimeCurrent() function while checking time limits.

Init() or Start()?

Any program written in MQL contains three predefined functions Init(), Start(), Deinit()

Init() – is called by framework in the start of the program.
Deinit() – is called in the end of the program.
Start() – is the main function called multiple times whenever current currency pair price is changed.

We can use Init() function for license validation. In this case program will do the check once in the beginning of its executions. If license is not time limited it is the most optimal to put license check in Init() function.

But if the license is time limited, it makes sense to put that check in Start() function. In this way the check will be performed every time current currency pair price is changed and if license runs out of time during program execution the logic will be stopped at once.