MQL Defender development kit - Matchpeg.com Defender developer kit.pdf · MQL Defender development...
Transcript of MQL Defender development kit - Matchpeg.com Defender developer kit.pdf · MQL Defender development...
MQL Defender development kit
The MQL Defender
development kit
Read page 4 first!
http://www.mqldefender.com
Page 1 of 42
MQL Defender development kit
Copyright Matchpeg Ltd
MQL Defender development kitDocument history:
Date Version Comments Approved04/10/08 1.0 Initial version n/a08/12/08 1.1 Addition of MSI Creator n/a
Contents:
1. Overview of MQL Defender .............................................................................................................. 4
1.1 How MQL Defender works ......................................................................................................... 5
1.2 Catering for licence expiry/termination ....................................................................................... 5
1.3 Subscriptions, and moving licences between computers ............................................................. 7
1.4 Windows Terminal Services ........................................................................................................ 8
1.5 Licence states in MQL Defender ................................................................................................. 8
1.6 Protecting and licensing multiple EX4 files ................................................................................. 8
1.7 MQL Defender system requirements ........................................................................................... 9
1.8 Licence releases by clients ........................................................................................................... 9
1.9 Frequently asked questions .......................................................................................................... 9
1.10 Help and support ...................................................................................................................... 10
2. The MQL Defender web-based admin console ................................................................................ 11
2.1 The structure of the console ....................................................................................................... 12
2.2 The Home section ...................................................................................................................... 12
2.3 The Clients section .................................................................................................................... 12
2.4 The Licences section ................................................................................................................. 13
2.5 The Indicators/EAs section ........................................................................................................ 15
2.6 The Admin Accounts section ..................................................................................................... 15
2.7 The Settings section ................................................................................................................... 15
2.8 The Support section ................................................................................................................... 15
3. MQL Protect .................................................................................................................................... 16
3.1 Before using MQL Protect ......................................................................................................... 16
3.2 What MQL Protect does ............................................................................................................ 16
Page 2 of 42
MQL Defender development kit
3.3 How to use MQL Protect ........................................................................................................... 17
4. The MQL Defender API .................................................................................................................. 18
4.1 Basics of using the API ............................................................................................................. 18
4.2 API objects ................................................................................................................................ 19
4.3 API functions ............................................................................................................................. 23
5. MQL Inspect .................................................................................................................................... 36
5.1 MQL Inspect syntax .................................................................................................................. 36
5.2 Wrapping MQL Inspect in a batch file ...................................................................................... 37
6. Creating an MSI installer for your EA/indicator .............................................................................. 38
6.1 What the MSI Creator tool does ................................................................................................ 38
6.2 Using the MSI Creator tool ........................................................................................................ 38
6.3 Upgrading previous installations ............................................................................................... 39
6.4 Uninstalling your product .......................................................................................................... 39
6.5 Files which already exist on disk ............................................................................................... 39
7. Troubleshooting licensing problems ................................................................................................ 40
7.1 The client is not prompted to enter a licence code ..................................................................... 40
7.2 The protected EX4 file keeps disappearing from disk ............................................................... 41
7.3 MQL Defender reports an error in communicating with the licensing server ............................ 41
7.4 MQL Defender says that the client’s computer clock is wrong ................................................. 41
7.5 MQL Defender says that a licence code is incorrect .................................................................. 41
7.6 MQL Defender says that a licence code has already been used on another computer ................ 41
7.7 The indicator/EA doesn’t display/do anything ........................................................................... 42
7.8 Starting again from scratch / deleting licence files .................................................................... 42
Page 3 of 42
MQL Defender development kit
1. Overview of MQL Defender
Getting started with MQL Defender is simple:
1. Use MQL Protect to encrypt your EX4 file.
2. Use the admin console to create a licence for yourself (for testing purposes).
3. Remove the unprotected version of your EX4 file from Metatrader’s experts directory (to
avoid confusion).
4. Copy the encrypted version of the EX4 file into the experts directory (if not already present).
5. Start up Metatrader, and add your protected indicator/EA to a chart.
You should be prompted to enter a licence code, and you simply type in the code you allocated to
yourself in step 2. Your indicator/EA should be displayed as normal (though its name will now end
in .x), and Metatrader should not need to prompt you again for the licence code.
Your EX4 file remains encrypted, and the licence code you typed in cannot now be used on any other
computers. Tada!
The process for one of your clients is almost identical:
1. You allocate a licence for them in the web-based console.
2. You send the client their licence code, the encrypted copy of your EX4 file, and the URL for
installing the MQL Defender desktop application:
http://www.mqldefender.com/mqldefender.msi
3. The client installs the MQL Defender desktop application first. (You don’t need to do this
because it is automatically installed as part of the developer kit containing this document.)
4. The client copies the encrypted version of your EX4 file into Metatrader’s experts directory
(as they would with a normal EX4 file).
5. The client starts up Metatrader, adds the indicator/EA to a chart, and types in the licence code
you allocated for them.
N.B. You can use the development kit to create an MSI installation package which carries out steps 3
and 4 automatically.
(We recommend that you send people the URL of the desktop application rather than the MSI file
itself. Many firewalls will block emails with MSI attachments, and prevent your message from getting
through.)
Page 4 of 42
MQL Defender development kit
1.1 How MQL Defender works
Repeating the information on our website, which you have doubtless read already:
• You encrypt your EX4 files using our MQL Protect tool.
• In order to use these encrypted files your clients need to install our MQL Defender software,
from the following URL:
http://www.mqldefender.com/mqldefender.msi
• MQL Defender only allows the client to use a protected EX4 file if they have a valid licence
code.
• You allocate a licence for the client using the web-based admin console.
• The client types in their code, and MQL Defender connects over the internet to the licensing
server in order to check the code. Once a code has been used on one computer it cannot then
be re-used on another computer.
• Periodically thereafter, on roughly a weekly basis, MQL Defender re-checks with the
licensing server to make sure that the client’s licence has not expired or been terminated.
1.1.1 Download address for the MQL Defender software
Repeating the information throughout this document (including just above), the URL for clients to
download the MQL Defender software is:
http://www.mqldefender.com/mqldefender.msi
1.2 Catering for licence expiry/termination
MQL Defender checks the licence on a protected EX4 file when Metatrader starts and/or when the
indicator/EA is added to a chart. In effect, there is an automatic licensing check whenever the init()
function is called in the indicator/EA.
However, if your client then leaves Metatrader running untouched for a month (or a year, or a
decade), there will be no further checks that the licence hasn’t expired or been terminated. Therefore,
you may want to make a small addition to your indicator/EA so that it does periodic checks of its own
licence.
N.B. The following step is not compulsory. You can ignore it, and leave your EX4 code unchanged,
unless you are concerned about customers “evading” licence expiry/termination by leaving Metatrader
open and untouched for weeks at a time.
Page 5 of 42
MQL Defender development kit
You need to do three simple things to implement this periodic licence check:
• Import a function from the MQL Defender DLL (using Metatrader’s #import directive).
• Call the DLL during the start() function in your MQ4 file.
• Check that DLL function calls are allowed, when your indicator/EA starts.
N.B. All these steps are illustrated by the example file MACD sample with periodic licence check.mq4
which you can find in the MQL Defender developer kit directory.
In order to do the import, you add the following lines at the top of your MQ4 file:
#import "MQLDefender.dll"
bool CheckLicence(int MyId, string MyName, int SecondsPerCheck);
#import
You then call this at the beginning of your start() function, and return immediately without doing
anything if the licence for your EX4 file is no longer valid:
int start()
{
if (!CheckLicence(999999, "Your indicator/EA name", 300)) return (0);
[…]
N.B. You may want to ensure that your EA has no open positions before checking the licence.
Otherwise, your client may be left with open positions which your EA then refuses to deal with any
further, putting your client at risk.
You replace the 999999 in the above example with the numeric ID allocated to your indicator/EA in
the Indicators/EAs section of the web-based console. The second parameter is the name to display for
your indicator/EA in any licensing messages. And the final parameter is how long to wait between
checks, in seconds. In the above example, the licence file on disk is checked every 5 minutes (300
seconds) – anything more frequent than this is inadvisable.
N.B. The time period only determines how often the licence file on disk is checked. It does not force
MQL Defender to re-validate the client’s licence over the internet with the MQL Defender server.
This happens automatically, on roughly a weekly basis.
Finally, we recommend that you check that DLL function calls are allowed, using Metatrader’s
IsDllsAllowed() function. Users must explicitly turn DLL calls on, by ticking the “Allow DLL
imports” setting in the “Safety” box for an indicator/EA, or in the Tools/Options/Expert Advisors
Page 6 of 42
MQL Defender development kit
global settings. The licence check will appear to fail if this option is not enabled, because the
CheckLicence() function never actually gets called.
The best way of making sure that DLL imports are permitted is to check for this during your
indicator/EA’s init() routine. For example:
int init()
{
if (!IsDllsAllowed())
{
Alert("Please allow DLL imports in order to use this indicator/EA");
return (1);
}
[…]
1.3 Subscriptions, and moving licences between computers
There are two ways of handling subscriptions – a “pessimistic” way and an “optimistic” way. The
pessimistic route is to set the expiry of a client’s licence to the date when their next subscription
payment is due. If the payment is indeed received, you then go into the web-based console and change
the expiry to the next subscription date. The optimistic way is to give clients open-ended licences (e.g.
with an expiry of 2099-12-31) and then only go into the console and terminate licences if subscription
payments are not received.
In either case, the EX4 file on the client’s computer stops working the next time that MQL Defender
checks the licence against the records held on the server. This happens on roughly a weekly basis.
“Moving” licences between computers works in much the same way – this is necessary if a client
wants to use your EX4 on a different computer, or if they upgrade their existing hardware so
substantially that MQL Defender sees it as a new computer.
There are two ways of “moving” licences:
• You terminate the existing licence, create a new licence replacing it, and send the new code to
the client. The new licence code can be used immediately, and the old licence stops working
after at most a week.
• You release the existing licence. The existing code can then be re-used on a new computer,
and the licence on the old computer stops working after at most a week. This is easier than
terminating a licence and creating a new one, but provides a weaker documentary trail.
Please note that, by default, customers can also release their own licences.
Page 7 of 42
MQL Defender development kit
1.4 Windows Terminal Services
MQL Defender licences are allocated and locked to computers, not people. This raises a potential
issue with Windows Terminal Services: a single computer can be used to host several people
simultaneously, and a single MQL Defender licence can therefore potentially be used concurrently by
multiple people.
For this reason the web-based console lets you specify whether each licence is allowed to work on
WTS. You will normally want to charge a premium for such licences because they are inherently
more valuable than a normal licence.
1.5 Licence states in MQL Defender
A licence for MQL Defender can be in any of four states, as reported by the admin console:
• Pending
• Issued
• Expired
• Terminated
Treating these in reverse order, “terminated” means that you have manually used the admin console to
terminate the licence and stop it working. “Expired” means that the licence is now beyond its expiry
date – please note that a licence can be both expired and terminated, and is reported as terminated if
so.
If a licence is active (i.e. not expired or terminated), and the client has typed in the licence code to
lock it against their computer, the licence is described as “issued”. If the client has not yet collected
their licence, it is shown as “pending”.
1.6 Protecting and licensing multiple EX4 files
Each EX4 file which you want to be able to license individually needs its own entry in the admin
console – i.e. needs to be listed in the Indicators/EAs section of the console.
Let’s say that you have two EAs, Yacht.ex4 and Ferrari.ex4, but only one registered indicator/EA in
the console. You can protect both EX4 files using MQL Protect/MQL Defender. However, any
licences you create will then work for both Yacht.ex4 and Ferrari.ex4. You can’t sell one EA without
Page 8 of 42
MQL Defender development kit
automatically giving your clients the ability to use the other EA as well (assuming, of course, that they
can get hold of the EX4 file from somewhere).
If you want to be able to charge separately for Yacht.ex4 and Ferrari.ex4, each EA needs to be
registered separately in the console. Please contact our sales department ([email protected]) to
arrange this.
1.7 MQL Defender system requirements
The MQL Defender software which your clients install requires Windows 2000 or later (Windows XP
strongly recommended). As usual, the installation requires Administrator rights. After that, MQL
Defender does not require any special privileges. For example, it will run perfectly happily on
Windows Vista without any changes to UAC settings.
1.8 Licence releases by clients
You can give your clients the ability to release their own licences, letting them re-enter licence codes
if they want to move your protected software to a new computer. The software will start working
immediately on the new computer, and will stop working on the old computer within at most one
week. (This is the same as you moving a licence between computers, but put in the hands of the
client.)
This facility is turned off by default, so that your clients need to ask you to release licences for them.
You can turn it on using the Settings tab of the admin console, and specify a minimum number of
days between each release of a licence. For example, you can allow clients to release licences no more
often than every 30 days.
The form for customers to release their own licences is at the following URL:
http://www.mqldefender.com/releaselicence.aspx
If you are going to allow clients to use this facility, you may want to advertise its URL to them in
things like your sign-up email.
1.9 Frequently asked questions
Please see the list of FAQs on our website at http://www.mqldefender.com/faq.aspx
Page 9 of 42
MQL Defender development kit
1.10 Help and support
For help and support, please use the Support section of the admin console.
If you have forgotten your password for the admin console, please contact us at
N.B. Please remember that you are responsible for providing support on licensing matters to your own
clients. We do not want to interfere in your client relationships.
Page 10 of 42
MQL Defender development kit
2. The MQL Defender web-based admin console
You use the MQL Defender web-based admin console to set up licences for your clients (though the
adventurous can also use the API or MQL Inspect).
The URL of the console is https://www.matchpeg.com/mqldefender/admin/
You log in using the email address you gave us, and the password we supplied to you. We
recommend that you change the initial password as soon as possible, using the Admin Accounts tab
described below.
The console is usually self-explanatory once you’ve read the following:
• Each licence you create has to be associated with a client.
• However, client records are only for your internal reference. The client details you enter do
not affect peoples’ ability to collect licences – there is no check that a user’s name or email
address matches the details you have provided.
• You can either create a client (from the Clients tab) and then create licences for them, or you
can create a new client and a new licence simultaneously using the button on the Licences tab.
• Licences in MQL Defender can be in one of four states at any given time:
o Pending – i.e. waiting for the client to collect it, by entering the code into Metatrader.
o Issued – i.e. the licence has been collected, and is now locked against the user’s
computer. The same licence code cannot then be used on any other computer.
o Expired – i.e. the licence is no longer usable (unless you change the expiry date)
o Terminated – i.e. you have marked the licence as inactive
• If a licence expires or is terminated, the client’s copy of your indicator/EA stops working
after at most one week.
• If you want to “move” a client’s licence to a new computer, the best way is to terminate the
existing licence and create a new one (which starts off as pending). The client enters the new
code on their new computer, and the old licence stops working after at most one week.
• Subscriptions can be handled in two ways. You can set expiry dates on licences, and change
them each month (or week, or whatever) as payment is received from your clients.
Page 11 of 42
MQL Defender development kit
Alternatively, you can leave the licences open-ended (with an expiry date of something like
December 31st 2099), and terminate licences if your clients fail to pay you.
2.1 The structure of the console
The console is divided up into six sections, each with its own tab at the top of the screen (plus a
seventh tab for logging out):
• Home
• Clients
• Licences
• Indicators/EAs
• Admin accounts
• Settings
• Support
2.2 The Home section
The Home section shows recent activity on your licences (e.g. licence creation, issue to a client etc)
plus any important news from us about the MQL Defender service.
2.3 The Clients section
The Clients section provides access to all the client information which you have recorded.
N.B. As explained above, client information is purely for your own reference. The client details you
enter do not affect people’s ability to collect licences. There is no check that the name or email
address of someone collecting a licence matches the details you have entered.
The format of the main Clients page depends on how many clients you have recorded. It starts by
showing a simple list of all your clients. Once the number of them grows too large to be manageable
(roughly 30+), the Clients page changes into a search form.
Page 12 of 42
MQL Defender development kit
2.3.1 Creating and amending clients
You create a new client using the button on the main Clients page, or view/edit an existing client by
clicking on their name in a list.
The only client information which is compulsory is the person’s name. However, optionally, you can
also record the person’s e-mail address and your own reference number for the client.
2.3.2 Listing and amending licences for a client
The view of a client’s details includes all the licences allocated to them (both active and expired). You
can create a new licence for an existing client using the button at the bottom of the list.. If a client has
active licences, you can also terminate all of them at once – e.g. because the client has failed to pay
their subscription to you.
N.B. You can create a new client and a new licence on one single form using the button on the
Licences page. This is marginally more efficient than creating a new client and then creating a new
licence for them.
2.3.3 Deleting clients
You can delete an existing client using the button at the bottom of their details. Please note that
deletion is permanent, irreversible, and also deletes any and all licences associated with the client.
2.4 The Licences section
The Licences section provides access to all the licences you have created, whether active or not.
However, if you want to look at the licences for a particular client, it is easiest to do so via their
details in the Clients section.
The format of the main Licences page depends on how many licences you have created. It starts by
showing a simple list of all your licences. Once the number of them grows too large to be manageable
(roughly 20+), the page changes into a search form.
Page 13 of 42
MQL Defender development kit
You can create both a new client and a new licence simultaneously using the button on the main
Licences page. If you want to create a new licence for an existing client, look up their details in the
Clients section and then create the licence from there.
2.4.1 Licence details
When creating or amending a licence, you must enter a code for it (see below), an expiry date (in the
form yyyy-mm-dd, e.g. 2099-12-31), and choose whether or not the licence is allowed to be used on
Windows Terminal Services. Optionally, you can also record your own internal reference number for
the licence.
You can terminate and then revive existing licences using the button at the bottom of the licence
details. If a licence has been issued, you can also release it, allowing the code to be “moved” to
another computer. You can also delete licences – permanently and irreversibly.
2.4.2 Licence codes
Licence codes must be alphanumeric, and cannot contain any punctuation other than underscores and
hyphens. Most importantly, spaces are not allowed.
All your licence codes must start with your firm’s numeric ID in MQL Defender, followed by a
hyphen (e.g. “372-whatever”). The rest of the code is entirely up to you, subject to the rule above. It’s
your decision whether you issue codes such as 372-JIMSMITH, or whether you use some sort of
consecutive numbering scheme, or random IDs etc.
Licence codes are not case-sensitive – because they are automatically converted to upper case.
The page for creating/amending a licence has an “Auto” button which automatically generates a new
licence code consisting of your firm’s ID, a hyphen, and a random 8-letter code.
Page 14 of 42
MQL Defender development kit
2.5 The Indicators/EAs section
Each EX4 file which you want to be able to sell separately needs to be registered in the admin
console, in the Indicators/EAs section. For more information, please read the section above about
protecting and licensing multiple EX4 files.
2.6 The Admin Accounts section
The Admin Accounts section lists all the accounts which can be used to log in to your admin area.
You start off with a single account, but can add more for your colleagues. Accounts can be disabled,
and can also be marked as read-only so that they can view all your client and licence data but cannot
change anything.
N.B. You change your own password for the admin console using the Admin Accounts section: click
on your name, enter a new password, and save the changes.
2.7 The Settings section
The Settings section lets you configure whether, and how often, clients are allowed to release their
own licences. You can set the release-period to zero, which completely prevents clients from releasing
their own licences and means that they need to contact you if they want to move your software to a
new computer. Alternatively, you can specify how many days there must be between each user-
release of a licence. (This setting does not affect your ability to release a licence via the admin
console.)
2.8 The Support section
The Support section contains information on contacting us for help and support about MQL Defender
and the developer kit.
It also provides access to various downloads such as the latest version of the developer kit.
Page 15 of 42
MQL Defender development kit
3. MQL Protect
MQL Protect is the tool which encrypts your EX4 files, protecting them against decompilation. In
order to use an encrypted EX4 file, your client needs a copy of MQL Defender, and this will only
decrypt the file if the client has a valid licence in the admin console.
3.1 Before using MQL Protect
Before you start using MQL Protect, you need three things:
• The compiled EX4 file which you want to encrypt.
• An account with the MQL Defender web-based admin console.
• A “private key” – a memorable, case-sensitive piece of text. You don’t have to reveal this to
clients, but you should make a note of it for the future – it can be used to prove that you are
the creator of an encrypted EX4 file.
N.B. Before protecting it, you may also want/need to make a minor addition to your indicator/EA
(and then recompile it) to cater for licence expiry and termination. This is explained above in section
1.2.
3.2 What MQL Protect does
MQL Protect takes a normal (i.e. compiled but unprotected) EX4 file, and encrypts it.
MQL Protect creates a new file in the same directory as the unencrypted original. It does not
overwrite the original file with the encrypted version. For example, if you tell MQL Protect to encrypt
the file InstantRiches.ex4, it will create a new file called InstantRiches.x.ex4.
N.B. The addition of the .x. to the filename is important. The MQL Defender software on your
client’s computer uses this to detect that an EX4 file is encrypted. If you remove the .x., MQL
Defender will be unable to decrypt your file.
Page 16 of 42
MQL Defender development kit
3.3 How to use MQL Protect
You start MQL Protect using the shortcut in the “MQL Defender developer kit” folder on the
Windows Start menu.
The first step is to enter your username and password for the admin console. MQL Protect uses these
details to download a list of the indicators/EAs which have been set up for your firm.
After logging on, you simply enter three pieces of information:
• The filename of the EX4 file you want to encrypt.
• The corresponding indicator/EA from the list registered in the admin console.
• Your private key, as described above.
And that’s it. MQL Protect should confirm that it has created an encrypted version of your file.
Page 17 of 42
MQL Defender development kit
4. The MQL Defender API
All actions which can be carried out manually through the web-based admin console can also be
automated using MQL Defender’s API. The API is exactly the same interface which the console uses
internally, and login details for the API are the same as for the console.
The API is a SOAP-based web service, and should be usable from any modern programming
language/environment. All the examples provided in this document are .NET-based, but they should
be readily translatable to other platforms.
The web service is available at the following address:
https://www.matchpeg.com/mqldefender/admin/licencehandler.asmx
(You can use an http rather https version of the address. This will be slightly faster, but your username
and password will then theoretically be vulnerable to interception while in transit over the internet.)
We strongly recommend that you take a look at MQL Inspect as part of your investigation of the
API. The full source code of this application is included in the Developer Kit, and it provides a
working example of every aspect of using the API – instantiating the web service, querying
information, creating licences etc.
All the example code in the following section uses VB.NET as a sort of lowest common denominator
between different programming languages and environments. Please note that this documentation
describes the purpose of API objects and functions. The exact details of the types of return values and
parameter (string, integer etc) are generally self-evident, can be obtained from the service description
at the above URL, and should anyway be provided by Intellisense (or equivalent) in any modern
development tool.
4.1 Basics of using the API
A few general points to note about using the API:
• You must call the Login function before using any other members of the web service.
Page 18 of 42
MQL Defender development kit
• Your credentials are maintained between calls using a session cookie. Therefore, in .NET you
need to attach a CookieContainer to the web service object before starting to use it. For
example:
Dim WebServiceObject As New MQLDefenderWebService
WebServiceObject.CookieContainer = New System.Net.CookieContainer
WebServiceObject.Login etc.
• All actions (such as logging in, or terminating a licence) return a FuncResult object describing
the success or failure of the action.
• All actions which make changes (client creation, licence deletion etc) will fail if your account
in the admin area has been marked as read-only.
• Licence codes must start with your firm’s numeric ID and a hyphen (e.g. 372-xxxx), and the
system will coerce them into this form if necessary (e.g. automatically turning “BOB” into
“372-BOB”).
4.2 API objects
The API provides/uses the following objects:
Name DescriptionFuncResult Used to describe the result of an action, e.g. the success/failure of logging
in or licence creationIndicator Describes an indicator/expert advisor which has been set up for your firmClient Describes a clientLicence Describes a licenceEditor Describes an admin account for your firmActivity Describes activity on a licence or client
4.2.1 The FuncResult object
The FuncResult object describes the success or failure of an action such as logging in or terminating a
licence. All functions in the API which carry out an action return a FuncResult.
After the call either the IsOkay or IsError member will be set to true. In the case of an error, the
ErrorMessage member provides a textual description of the problem.
Page 19 of 42
MQL Defender development kit
If a call succeeds, then either the ResultId or ResultString may contain information about the result of
an action. For example, using CreateOrUpdateClient() to create a new client sets ResultId to the new
client’s ID. Using CreateOrUpdateLicence() to create a new licence sets ResultString to the new
licence code.
The following example code shows the use of a FuncResult in relation to logging in:
Dim Result as FuncResult = WebService.Login(Username, Password)
If Result.IsOkay Then
‘ Continue…
Else
MsgBox (“Login in failed because...” & Result.ErrorMessage)
End If
4.2.2 The Indicator object
The Indicator object describes an indicator or expert advisor which has been registered for your firm
in the web-based console. (N.B. You cannot create new indicators yourself. This has to be done for
you by Matchpeg, because there are charging implications.)
Each indicator has a numeric identifier and a name: the IndicatorId and IndicatorName members.
In addition, the Indicator object contains a MaxLicences member showing the maximum number of
active licences which you are allowed to create for the indicator/EA, and a LicencesInUse member
showing the number which currently exist. (Please note that “active” means pending or issued, i.e. not
expired or terminated.) Attempts to create a new licence will fail if LicencesInUse is already equal to
MaxLicences.
N.B. The MaxLicences and LicencesInUse members are not populated (i.e. are left at zero) in the
context of a Licence object. In other words, the ForIndicator member of a Licence object obtained
using GetLicence() etc has zero values for these members.
4.2.3 The Client object
Page 20 of 42
MQL Defender development kit
The Client object describes… a client. The ClientId contains the client’s unique numeric id;
ClientName holds their name; ClientEmail contains their email address; and ExternalClientId contains
your own reference number for the client.
4.2.4 The Licence object
The Licence object describes… a licence. It is a tiny bit more complicated than usual because it
contains two sub-objects: the ForIndicator member is an Indicator object describing the indicator/EA
the licence is issued for, and the ForClient member is a Client object describing the client the licence is
issued to.
The LicenceCode is licence’s unique identifier. It is always in the form <firmid>-<text> where
<firmid> is the numeric ID assigned to your firm in the web-based console. (If you try to create a
licence with a code not in this form, the system will automatically add your firm’s ID at the
beginning.)
The StartDate and EndDate are the start and end (expiry) dates for the licence. Please note that the
web-based console hides the start date (and automatically sets it to today when creating new licences).
You can use StartDate to create licences which only become active at some point in the future, but
this is not recommended because the start date cannot then be controlled manually via the console.
The AllowWTS member specifies whether the client is allowed to use the licence on a computer
running Windows Terminal Services.
The ExternalLicenceId is your own reference number for the licence (if any), and LicenceNotes
contains any notes you want to record about the licence. (These notes cannot currently be maintained
via the web-based console; they are only available via the API.)
The status of a licence is indicated by a number of boolean members: IsIssued, IsTerminated, and
IsExpired. If none of these is set, the licence is pending, and has not been “collected” by the client. A
licence can be both terminated and expired.
Page 21 of 42
MQL Defender development kit
If a licence has been issued (even if it has subsequently expired or been terminated), the IssueDate
will contain the date and time the client collected it from the server. This member should be ignored,
and will contain an unpredictable value, unless IsIssued is true.
The Licence object also contains an IsIrrevocable boolean member. An irrevocable licence is one
where the client computer is instructed that it never needs to check the licence’s status against the
server (i.e. the usual weekly check is skipped). Therefore, once issued, an irrevocable licence cannot
expire or be terminated, or be altered in any way. The API does not currently provide a way of
creating irrevocable licences; the API ignores IsIrrevocable in calls to CreateOrUpdateLicence().
4.2.5 The Editor object
The Editor object describes an “editor” – an admin account for your firm. The EditorId member is the
account’s unique ID; the EditorName is the person’s name; and the EmailAddress is the email address
which is used for logging in to the web-based console or API.
The IsAccountDisabled member indicates whether the account is allowed to log on, and the
CanMakeChanges member indicates whether the account is marked as read-only.
The Password member is always blank after calls such as GetEditor(). It is only used with the
CreateOrUpdateEditor() function, to specify a new password for an account.
4.2.6 The Activity object
The Activity object describes licence activity. ActivityId is a unique ID for the action;
ActivityTypeName is a description of the type of activity; and ActivityDate is the date and time on
which the action occurred.
If the action related to a specific client, the ClientId and ClientName members will be non-blank. If the
action also related to a specific licence, then the LicenceCode member will also be non-blank.
Page 22 of 42
MQL Defender development kit
4.3 API functions
The functions provided by the API are most easily covered by dividing them into groups.
Logging in and logging out:
Login()
Logout()
General information functions:
FirmId()
OwnEditorId()
OwnEditorName()
CanMakeChanges()
Information about the indicators/EAs set up for your firm:
ListIndicators()
GetIndicator()
Client listing, searching, retrieval, and creation:
CountClients()
ListClients()
FindClients()
GetClient()
CreateOrUpdateClient()
DeleteClient()
Listing and searching for licences:
CountLicences()
CountActiveLicences()
CountActiveLicencesForIndicator()
ListLicences()
FindLicences()
ListLicencesForClient()
ListLicencesForIndicator()
GetLicence()
Page 23 of 42
MQL Defender development kit
Licence creation, deletion, and termination:
GenerateRandomLicenceCode()
IsLicenceCodeInUse()
CreateOrUpdateLicence()
TerminateLicence()
ReviveLicence()
ReleaseLicence()
DeleteLicence()
DeleteAllLicencesForClient()
TerminateAllLicencesForClient()
DeleteAllDeadLicences()
Admin account functions:
ListEditors()
GetEditor()
CreateOrUpdateEditor()
DeleteEditor()
Activity functions:
ListActivityForLicence()
ListActivitySince()
4.3.1 Login()
Login() logs you in to the web service, using the same username and password as for the web-based
console. Like all other actions, it indicates success/failure by returning a FuncResult object.
You must call Login() before using any other functions in the web service. Please note that your
credentials are subsequently maintained using a session cookie – see above for the use of a
CookieContainer in .NET etc.
4.3.2 Logout()
Page 24 of 42
MQL Defender development kit
Logout() logs you out of the web service. It returns a FuncResult object, but the call never fails – not
even if you were not previously logged in. Use of Logout() is not exactly necessary: in all
programming environments you will be automatically and implicitly logged out when your web
service object goes out of scope.
4.3.3 FirmId()
FirmId() returns the unique numeric ID assigned to your firm. (This is purely for your information; it
is not required in any calls to the web service.) A zero return value from this function is an indication
that you are not logged in.
4.3.4 OwnEditorId()
OwnEditorId() returns the unique numeric ID assigned to your admin account. In other words, calling
GetEditor() with this value returns the details of your account.
4.3.5 OwnEditorName()
OwnEditorName() returns your name, as specified in the details of your admin account.
4.3.6 CanMakeChanges()
CanMakeChanges() indicates whether your admin account is allowed to make changes, or whether
your account has been marked as read-only. If CanMakeChanges() returns false, all action-related
functions such as CreateOrUpdateLicence() will fail.
4.3.7 ListIndicators()
ListIndicators() returns a list of all the indicators/EAs which have been set up for your firm, as an
array of Indicator objects. An empty array indicates that your initial payment is still being processed,
and no indicators/EAs are yet available for licensing.
Page 25 of 42
MQL Defender development kit
4.3.8 GetIndicator()
GetIndicator() returns an Indicator object describing the indicator/EA which has the specified numeric
ID. The Indicator object is most useful for comparing the number of active licences you have created
versus the maximum number you are allowed to create. The function returns null (Nothing, in
VB.NET parlance) if the specified indicator ID is not valid (or if any other error occurs, such as not
being logged in).
4.3.9 CountClients()
CountClients() returns a simple count of the number of client records you have created. An error is
indicated by a return value of -1, though the only possible error is not being logged in.
4.3.10 ListClients()
ListClients() returns an array of Client objects describing all the client records you have created. For a
more filtered list of clients, use the FindClients() function.
4.3.11 FindClients()
FindClients() does a search of client records, matching a piece of text against any out of their name,
email address, or your reference for the client. Its return value is an array of Client objects. All
searches are case-insensitive.
You specify the text to search for in the ClientSearch parameter, and use the boolean SearchNames,
SearchEmail, and SearchExternalId parameters to indicate which fields to match the text against – you
can switch on anything between one and all three of these flags.
The MatchMode parameter specifies how to match your text against the field(s). Only the
tmmLetterRange value should be anything other than self-explanatory: this should be used with a
ClientSearch parameter such as “A-D” to find all clients with a name starting with the letters A to D.
Page 26 of 42
MQL Defender development kit
4.3.12 GetClient()
GetClient() returns a Client object describing the client with the specified numeric ID. The function
returns null (Nothing, in VB.NET parlance) if the client ID is not valid (or if any other error occurs,
such as not being logged in).
4.3.13 CreateOrUpdateClient
CreateOrUpdateClient() creates a new client, or makes changes to an existing client record. Its
parameter is a Client object describing the new or existing client, and its return value is the usual
FuncResult.
You can modify an existing client by creating a Client object; setting its ID to the existing client’s ID;
and setting all the fields to the values you want to store (not just the fields which are changing).
However, we recommend that you modify existing clients by using GetClient() to return a Client
object; make changes to the object; and then save those changes. For example:
‘ Change client’s e-mail address
Dim C as Client = WebService.GetClient(12345)
C.ClientEmail = “[email protected]”
Dim Result as FuncResult = WebService.CreateOrUpdateClient(C)
When creating a new client, you leave the ID set to zero and populate the name (which is
compulsory), plus any other members you want to record. For example:
‘ Create a new client
Dim C as New Client
C.ClientName = “John Smith”
C.ClientEmail = “[email protected]”
Dim Result as FuncResult = WebService.CreateOrUpdateClient(C)
When creating a new client, the numeric ID allocated to them by the system is returned in the ResultId
field of the FuncResult.
Page 27 of 42
MQL Defender development kit
N.B. Please note that CreateOrUpdateLicence() allows you to create a new client and a new licence
simultaneously.
4.3.14 DeleteClient()
DeleteClient() deletes the client with the specified numeric ID, and returns the usual FuncResult
object describing success/failure. Deletion of a client automatically deletes all licences associated with
the client.
4.3.15 CountLicences()
CountLicences() returns a simple count of the number of licences you have created (active and dead).
An error is indicated by a return value of -1, though the only possible error is not being logged in.
4.3.16 CountActiveLicences()
CountActiveLicences() returns the number of active licences you have – i.e. the number of licences
which are pending or issued, not expired or terminated. An error is indicated by a return value of -1,
though the only possible error is not being logged in.
4.3.17 CountActiveLicencesForIndicator()
CountActiveLicencesForIndicator() returns the number of active (non-expired, non-terminated)
licences you have created for a specific indicator/EA. An error is indicated by a return value of -1,
though the only possible error is not being logged in.
The return value from this function will be the same as the LicencesInUse field in the Indicator object
returned by GetIndicator().
4.3.18 ListLicences()
Page 28 of 42
MQL Defender development kit
ListLicences() returns a simple list of all the licence records you have created, as an array of Licence
objects.
4.3.19 FindLicences()
FindLicences() searches for licences which match various conditions. Its return value is an array of
the matching Licence objects.
The first two parameters for the function are part or all of a licence code to search for, and what sort
of textual comparison to perform – exact match, contains, starts with.
The third parameter allows you to list licences only for a specific client. You either set the ClientId
parameter to the required ID, or leave it at zero for no filtering by client.
The fourth parameter is a similar filter on a specific indicator/EA: you either set IndicatorId to a
specific ID, or leave it at zero for no filtering by indicator.
The fifth parameter lets you restrict the list to licences at a particular state. The Status parameter
should be set to zero for no restriction on licence state; 1 for pending, un-issued licences; 2 for issued,
active licences; 3 for expired licences; and 4 for terminated licences.
The final two parameters let you filter down the list of licences by expiry date: you supply the
ExpiryDate you want to compare against, and the DateMatchType for the comparison you want to
perform: equal, prior or up to, starting from.
4.3.20 ListLicencesForClient()
ListLicencesForClient() returns a simple list of all the licences, active or not, for a specific client ID,
as an array of Licence objects. (It is equivalent to using FindLicences() and only setting the ClientId
parameter.)
4.3.21 ListLicencesForIndicator()
Page 29 of 42
MQL Defender development kit
ListLicencesForIndicator() returns a simple list of all the licences, active or not, for a specific
indicator/EA, as an array of Licence objects. (It is equivalent to using FindLicences() and only setting
the IndicatorId parameter.)
4.3.22 GetLicence()
GetLicence() returns a Licence object describing the licence with the specified code. The function
returns null (Nothing, in VB.NET parlance) if the client ID is not valid (or if any other error occurs,
such as not being logged in).
As described above, the Licence object contains ForIndicator and ForClient sub-objects describing the
indicator/EA for which the licence was created, and the client to whom it is allocated. Please note that
the MaxLicences and LicencesInUse fields of ForIndicator are not populated by a call to GetLicence().
4.3.23 GenerateRandomLicenceCode()
GenerateRandomLicenceCode() generates a random new licence code, in the form X-ABCDEFGH
where X is your firm’s numeric ID, and ABCDEFGH is a random 8-character string. (The
CreateOrUpdateLicence() function uses GenerateRandomLicenceCode() internally if you do not
specify a code for a new licence.)
4.3.24 IsLicenceCodeInUse()
IsLicenceCodeInUse() checks whether a licence code already corresponds to an existing licence.
N.B. If the code you supply does not begin with your firm’s ID followed by a hyphen (e.g.
372-xxxxxx), it is automatically converted into the required form before doing the check.
4.3.25 CreateOrUpdateLicence()
Page 30 of 42
MQL Defender development kit
CreateOrUpdateLicence() creates a new licence, or modifies an existing one. The function’s
parameter is a Licence object describing the licence to create or amend. Its return value is the usual
FuncResult.
When creating a new licence, you instantiate a new Licence object and fill in the following members:
• A valid EndDate (e.g. December 31st 2099 if you want a licence which is effectively open-
ended)
• The AllowWTS flag, indicating whether the licence is allowed to be used on Windows
Terminal Services
• The ForIndicator member. You set this to an instance of an Indicator object, and set the
Indicator’s IndicatorId field to indicate which indicator/EA the licence is for.
• The ForClient member. You set this to an instance of a Client object. If the ClientId field of the
Client object is non-zero, the licence is assigned to an existing client and all other fields in the
Client object are ignored – the corresponding client record is not updated. Alternatively, you
can create a new client at the same time as the new licence by setting ClientId to zero, and
filling in the ClientName plus any of the other optional fields which you also want to record.
(Putting it another way, if ClientId is zero, the web service does an internal call to
CreateOrUpdateClient() before proceeding with the licence creation.)
• The LicenceCode member. If you leave this blank, the licence is given a random code in the
form generated by the GenerateRandomLicenceCode() function. If you do supply your own
code for the new licence, the system makes sure that it is in the required format: your firm’s
ID followed by a hyphen (e.g. 372-xxxxxx)
For example:
Dim L As New Licence
L.LicenceCode = “372-NEWLICENCEFORBOB”
L.EndDate = #12/31/2011#
L.ForIndicator = New Indicator ‘ Add an Indicator object into the Licence object
L.ForIndicator.IndicatorId = 123456 ‘ Set the ID of the indicator/EA which this is for
L.ForClient = New Client ‘ Add a Client object into the Licence object
L.ForClient.ClientId = 87654 ‘ Create the licence for existing client #87654
Dim Result as FuncResult = WebService.CreateOrUpdateLicence(L)
Page 31 of 42
MQL Defender development kit
When creating a new licence without specifying your own licence code, the ID which the system
allocates to the licence is returned in the ResultString field of the FuncResult.
When amending an existing licence, we recommend that you call GetLicence() to populate a licence
object, amend the details as necessary, and then use CreateOrUpdateLicence() to save the changes.
For example:
Dim L As Licence = WebService.GetLicence(“372-BOBSCURRENTLICENCE”)
L.AllowWTS = True ‘ Switch on permission to use WTS
L.EndDate = #12/31/2012# ‘ Change the expiry date
Dim Result as FuncResult = WebService.CreateOrUpdateLicence(L)
Please note that you cannot use the CreateOrUpdateLicence() function to alter a licence’s IsIssued,
IsExpired or IsTerminated flags. The latter two fields are controlled by the expiry date and the
TerminateLicence() function respectively. The IsIssued flag is modified by the system when a user
collects their licence.
4.3.26 TerminateLicence()
TerminateLicence() terminates the specified licence, and returns the usual FuncResult to indicate
success/failure. The function succeeds even if the specified licence has already been terminated. It
only fails if the specified licence code is not valid (or if you have not logged on).
4.3.27 ReviveLicence()
ReviveLicence() revives (i.e. un-terminates) the specified licence, and returns the usual FuncResult as
its return code. The function succeeds even if the specified licence was not previously marked as
terminated. It only fails if the specified licence code is not valid (or if you have not logged on).
4.3.28 ReleaseLicence()
ReleaseLicence() clears the marker on a licence which has already been issued, allowing it to be used
again on another computer. It returns the usual FuncResult to indicate success/failure.
Page 32 of 42
MQL Defender development kit
4.3.29 DeleteLicence()
DeleteLicence() permanently deletes the specified licence, and returns the usual FuncResult to
indicate success/failure.
4.3.30 DeleteAllLicencesForClient()
DeleteAllLicencesForClient() permanently deletes all the licences associated with the specified client,
and returns the usual FuncResult to indicate success/failure.
4.3.31 TerminateAllLicencesForClient()
TerminateAllLicencesForClient() terminates all the licences associated with the specified client, and
returns the usual FuncResult to indicate success/failure.
4.3.32 DeleteAllDeadLicences()
DeleteAllDeadLicences() permanently all deletes all licences which have expired or have been
terminated. It returns the usual FuncResult to indicate success/failure.
4.3.33 ListEditors()
ListEditors() returns an array of Editor objects describing all the admin accounts which have been set
up for your firm.
4.3.34 GetEditor()
GetEditor() returns an Editor object describing the specified admin account. The function returns null
(Nothing, in VB.NET parlance) if the supplied account ID is not valid (or if any other error occurs,
such as not being logged in).
Page 33 of 42
MQL Defender development kit
4.3.35 CreateOrUpdateEditor()
CreateOrUpdateEditor() creates a new admin account for your firm, or modifies an existing one. Its
parameter is an Editor object describing the account to create or amend, and its return value is the
usual FuncResult.
When creating a new account, you must fill in the EditorName, EmailAddress, and Password fields.
You must also explicitly set CanMakeChanges to true unless you want the new account to be read-
only. The ID of the new account is returned in the ResultId field of the FuncResult.
We recommend that you amend existing accounts by using GetEditor() to populate an Editor object;
make changes to the object; and then use CreateOrUpdateEditor() to save the changes. (You only
need to set the Password field of the Editor object if you want to change the user’s password.) For
example:
Dim E As Editor = WebService.GetEditor(2345)
E.IsAccountDisabled = True ‘ Disable the account, preventing the person from logging in
Dim R as FuncResult = WebService.CreateOrUpdateEditor(E)
Please note that the system prevents you from making changes which would leave your firm without
any accounts which are (a) enabled and (b) not read-only.
4.3.36 DeleteEditor()
DeleteEditor() deletes the specified admin account, and returns the usual FuncResult. The system does
not allow you to delete your own account.
4.3.37 ListActivityForLicence()
ListActivityForLicence() returns an array of Activity objects describing all the activity ever for the
specified licence code. The activity includes creation of the licence, issuance of the licence (i.e.
Page 34 of 42
MQL Defender development kit
collection by the customer), and all the subsequent checks by the customer’s computer that the licence
is still valid.
4.3.38 ListActivitySince()
ListActivitySince() returns an array of Activity objects describing all the activity for any client or
licence starting from the supplied date.
Page 35 of 42
MQL Defender development kit
5. MQL Inspect
MQL Inspect is an application which can be used to query and update licence information from the
Windows command line, i.e. instead of logging in to the web-based admin console. For example, you
can use MQL Inspect to terminate a licence by typing in the following:
MQLInspect <username> <password> TerminateLicence <licence code>
Therefore, MQL Inspect can be used to automate licence creation, e.g. by creating a Windows
scheduled task. In addition, MQL Inspect sets the %ERRORLEVEL% environment variable, and
batch files can therefore do conditional processing depending on the results of actions.
However, the main purpose of MQL Inspect is actually something different: its full source code is
included as part of the Developer Kit, and MQL Inspect is principally intended to provide a working
example of how to use the MQL Defender API.
5.1 MQL Inspect syntax
Typing MQLInspect without parameters displays general help on the application’s command-line
syntax. (Everything which follows here repeats that information.)
The standard syntax for using MQL Inspect is as follows:
MQLInspect <username> <password> <command> [<extra parameters>]
In other words, there are always at least three parameters. The first and second are your username and
password for the web-based console. The third parameter is a “command”, specifying the information
to retrieve or the action to carry out. Some commands require extra parameters, such as a licence code
or client ID. (N.B. As usual in Windows, parameters which contain spaces must be enclosed in
quotation marks.)
You can list all the available commands using MQLInspect commands or MQLInspect help commands
Page 36 of 42
MQL Defender development kit
For help on the syntax of an individual command, you can use MQLInspect help <command name>,
e.g. MQLInspect help CreateLicence
The help on a specific command also describes what value %ERRORLEVEL% is set to. For example,
the ListClients command sets %ERRORLEVEL% to the number of clients you have created.
5.2 Wrapping MQL Inspect in a batch file
Repeating the information from the application’s own syntax help (type MQLInspect help wrapper),
we recommend creating a batch file such as the following which wraps MQL Inspect:
@echo off
if "%1" == "help" goto help
if "%1" == "commands" goto help
MQLInspect <username> <password> %*
goto :exit
:help
MQLInspect %*
:exit
You insert your username and password in line 4, and name the batch file something like
MQLInspect2.bat.
You can then use MQLInspect2 in exactly the same way as MQLInspect, except you no longer have
to enter your username and password as part of every command. In other words, the following
commands have the same effect:
MQLInspect <username> <password> ListLicences
MQLInspect2 ListLicences
Page 37 of 42
MQL Defender development kit
6. Creating an MSI installer for your EA/indicator
The development kit includes an application which creates a simple MSI installer for your
EA/indicator. Your clients can then double-click on the installer, rather than manually copying files
into Metatrader directories – much more elegant and professional. The installer can also automatically
download and install MQL Defender, without you needing to instruct clients to do this manually.
However, there are four things which you need to be aware of in advance:
• MSI installers are heavyweight – the .MSI file will often be 10 times the size of the actual
EX4 files which are getting installed. (In other words, convenience comes at a high price in
terms of file size.)
• Many firewalls and e-mail services block messages with MSI attachments. You may need to
upload your MSI installer to a website, and let your clients download it from there, rather than
sending it out by e-mail.
• The tool in the development kit only provides a very limited set of options. If you want more
control over your installation, please consider purchasing a specialised, fully-fledged
installation tool such as Wise or Installshield.
• MSI installers can only be used once per computer, after which they switch into maintenance/
remove mode. Therefore, if your client has multiple installations of Metatrader on their
computer, the MSI can only be used against one of the installations. If they try to run the MSI
again, to update another Metatrader installation, they will instead be prompted to remove the
existing copy of your files.
6.1 What the MSI Creator tool does
The MSI Creator tool generates a simple .MSI installer which does the following:
• Copies files of your choice into Metatrader’s Experts directory.
• Copies files of your choice into Metatrader’s Experts\Indicators directory.
• Automatically downloads and installs MQL Defender if it is not already present on the
client’s computer.
• Optionally, upgrades a previous installation.
6.2 Using the MSI Creator tool
You start the MSI creator tool using the shortcut in the “MQL Defender developer kit” folder on the
Windows Start menu.
Page 38 of 42
MQL Defender development kit
You need to fill in the name of your product (i.e. your EA or indicator), your own name, and a version
number (in the format x.y.z). You then choose a list of files to be installed either into Metatrader’s
Experts directory, or its Indicators directory, or both.
Once you have provided the details of your product and selected the files to install, you simply click
on the “Create MSI file” button and choose where to save your new .MSI file.
6.3 Upgrading previous installations
You can create updates for previous installations by using Upgrades tab to specify the location of a
.MSI file which you created previously. (You should also set the version number of the new installer
to a higher value than the old one.)
The new .MSI will then completely remove the old installation before carrying out the new one.
Therefore, you need to re-include all applicable files in the new .MSI. If file X was included in the old
installer, but is not included in the new installer, then it will be removed by the upgrade.
Clients do not need to have installed the old version in order for the new installer to work. The new
version works on a standalone basis as well as being an upgrade.
6.4 Uninstalling your product
Clients can uninstall your product in the usual two ways: either by re-running the .MSI installer,
which will then give them a “Remove” option; or by using Add/Remove Programs in the Windows
control panel.
Please note that uninstalling your product does not automatically uninstall MQL Defender. Clients
need to do this manually (using Add/Remove Programs etc.)
6.5 Files which already exist on disk
Under normal circumstances the files which you are installing will be specific to your product, and
will not already exist on disk (unless an earlier version of your product is already installed).
However, if a file does already exist (e.g. you are trying to update Metatrader’s own “MACD
Sample.ex4” file) then Windows applies a very simple rule: the existing file is only overwritten from
your installer if your version of the file has a later timestamp than the one already on the customer’s
computer.
Page 39 of 42
MQL Defender development kit
7. Troubleshooting licensing problems
We recommend software such as Teamviewer (www.teamviewer.com) for getting temporary remote
access to a client’s computer in order to resolve problems.
The first steps in diagnosing any licence problem are always the same:
• Make sure that Metatrader has been closed and is not running.
• Make sure that MQL Defender has been correctly installed on the client’s computer, using the
“Check installation” shortcut under “MQL Defender” on the Windows Start menu). If this
tool says that an error occurred – or the shortcut doesn’t exist – get the client to uninstall
MQL Defender (using Add/Remove Programs in the Control Panel) and then reinstall MQL
Defender from the following address:
http://www.mqldefender.com/mqldefender.msi
• Make sure that your (encrypted) EX4 file has been copied into the correct place within the
Metatrader experts directory.
• If you have followed the recommended steps in section 1.2, make sure that the client has
enabled the setting in Metatrader allowing DLL imports. It’s easiest to turn this on “globally”,
rather than for an individual indicator/EA, using Metatrader’s Tools/Options/Expert Advisors
settings page.
Once these steps have been checked, re-open Metatrader.
N.B. If the client does not enter a valid licence code, or there is a problem with the MQL Defender
installation, Metatrader may delete your EX4 file from disk when it starts up. This is because
Metatrader sometimes removes EX4 files which it thinks are damaged. If the client does not enter a
licence code or MQL Defender has not been installed successfully, Metatrader cannot read the EX4
file, thinks it is damaged – and may delete it.
When investigating licensing problems, always check – and re-check – that your EX4 file is still
present in Metatrader’s experts directory.
7.1 The client is not prompted to enter a licence code
MQL Defender should ask the client for a licence code when Metatrader starts up, or when your EX4
file is added to a chart. If not, there are two main possibilities:
• MQL Defender is not installed properly.
Page 40 of 42
MQL Defender development kit
• Your EX4 file is in the wrong place, and Metatrader is not seeing it. Make sure that your
indicator/EA is listed in Metatrader’s “Navigator” pane.
7.2 The protected EX4 file keeps disappearing from disk
As explained in the opening of this section, Metatrader may delete an EX4 file from disk if the client
does not enter a valid licence code, or if there is a problem with the MQL Defender installation.
7.3 MQL Defender reports an error in communicating with the licensing
server
If MQL Defender reports that an error occurred while trying to communicate with the licensing server
then it almost certainly implies a problem with the client’s internet connection, or a firewall
preventing traffic from reaching the MQL Defender server.
(If you want to rule out problems with the MQL Defender server itself, try logging in to the web-
based console. If this works, then the problem is definitely with the client’s computer, internet
connection, or firewall.)
7.4 MQL Defender says that the client’s computer clock is wrong
MQL Defender cannot issue licences if the clock on the client’s computer is substantially wrong.
Adjust the clock and then try again.
7.5 MQL Defender says that a licence code is incorrect
If MQL Defender says that the licence code which the user is entering does not match any current or
expired licence, check that the client is entering the correct code – there must be some sort of problem
with it. Either the code is being misspelled, or the licence has expired or been terminated, or the
licence is for a different indicator/EA.
7.6 MQL Defender says that a licence code has already been used on
another computer
If the client upgrades their hardware (e.g. changes the processor), MQL Defender may think that it is
running on a new computer, and that the existing licence code is no longer valid.
Page 41 of 42
MQL Defender development kit
You need to “move” the licence to the new computer, as described above: you terminate the existing
licence, and create a new licence.
7.7 The indicator/EA doesn’t display/do anything
If Metatrader says that your protected EX4 file has been successfully licensed and attached to a chart,
but the indicator is blank/the EA doesn’t do anything, then the problem is almost certainly related to
the recommended steps described in section 1.2 above.
Please check that you have implemented the call to the MQL Defender CheckLicence() function
correctly, and that DLL imports have been enabled in Metatrader’s settings.
7.8 Starting again from scratch / deleting licence files
If you want to resolve licensing problems by starting again from scratch, then try the following steps:
• Close Metatrader
• Uninstall MQL Defender (using the Windows control panel)
• Remove your protected files from Metatrader’s experts directory
• Delete all licence files from the hard disk (see below)
• Reboot the computer
As explained in the FAQs on the website, licence files are stored in the All Users document area, in
the Application Data directory. This directory is marked as hidden, and you may need to change
options in Windows Explorer in order to be able to see it: choose Tools/Folder Options/View, and
then select the “Show hidden files and folders” option.
On Vista, licence files are stored in a directory called “Metatrader licences” directly below “All
users”. In other words, the location on Vista is usually:
C:\Users\All Users\Metatrader licences
On Windows XP, the “Metatrader licences” directory is under “Application Data” within “All Users”.
In other words, the location on Windows XP is usually:
C:\Documents and Settings\All Users\Application Data\Metatrader licenses
Once you have located the directory, you can simply delete all the files within it (which should all
have the extension .lic). Once MQL Defender has been reinstalled, and Metatrader is restarted, the
user should be prompted to re-enter their licence code for each protected EX4 file.
Page 42 of 42