When your Indicator is opened for the first time you need to record the date and store it somewhere. It can be stored in a file. Next, you should regularly compare the current date with the stored date to see if the difference is more than, for example, two days. If it is, then stop the indicator and show a expiry message to the user. You can place the code that checks for the expiry in
onTimer. So in short, here are the steps
- check if a file setting exists, if not create one and store the current date as
- read the date from the file
- compare the date with current date and if the difference is more than 2 days (or any number of days), disable the EA.
There are other ways to secure an EA/Indicator:
Password protection : The first most used solution for a protection of computer software is password or license key protection. During first run after installation the user is queried with a dialog box to insert a password tied with a software copy (like the Microsoft Windows or Microsoft Office serial key) and if the entered password matches the user is allowed to use a single registered copy of a software. We can use an input variable or a direct textbox to enter the code
Key generator: Key generators are a mechanism that allows to use a set of passwords based on predefined rules. I will give an overview by providing a stub for a keygenerator below. In the example presented below the key must consist of three numbers separated by two hyphens. Therefore the allowed format for a password is XXXXX-XXXXX-XXXXX.
Single Account LicenseSince the Account number of the terminal of any given broker is unique this can be used to allow usage of the EA on one or a set of account numbers. In such case it is enough to use AccountInfoString(ACCOUNT_COMPANY) and AccountInfoInteger(ACCOUNT_LOGIN) methods to fetch the account data and compare it against precompiled allowed values:
Time-limit Protection: This is what you want. Time-limit protection is useful when the license is granted on temporary basis, for example using trial version of the software or when the license is granted on monthly or yearly basis. Since this is obvious that this can be applied for Expert Advisors and Indicators. First idea is to check server time and based on that let the user use the Indicator or Expert Advisor within given period of time. After it expires the licensor is able to partially or totally disable its functionality to the licensee.
Remote licenses :Wouldn’t it be good to have a total control wheter to disable the license or extend the trial period on per user basis? This can simply be done using MQL5-RPC call that would send a query with the account name and receive the value whether to run the script in trial mode or disable it.
For more information see this article: