Instructions

Step-by-step instructions on how to build the advertising into your MQ4 or MQ5 code.

See the bottom of the page for complete code examples.

1. Download and install the FXAdverts DLL

You need to download and install the DLL which is used by FXAdverts: MT4HelperSetup.zip

Your users will also need to download and install the DLL in order to use your EA/indicator. (If you want to install the DLL yourself, as part of your own installation package for your EA/indicator, please see the instructions below.)

2. Copy and paste the advertising code

Download the template code for MT4 or MT5, and simply copy and paste it into the bottom of the MQ4/MQ5 code for your indicator or EA:

3. Fill in your subscriber ID

In the code you have copied and pasted, change the text <FILL IN YOUR SUBSCRIBER ID HERE>

Your subscriber ID is allocated after you sign up, and is shown in your account details.

4. Display the advertising when your EA/indicator loads

You need to add one line of code to make your advertising appear.

MetaTrader 4

In start(), add the following line of code:

LoadAdvertising();

MetaTrader 5

Add the following line of code either to the OnTick() function (for EAs), or to the OnCalculate() function (for indicators):

LoadAdvertising();
5. Remove the adverts when your EA/indicator ends

You need to add one line of code to make your advertising disappear when your EA/indicator is unloaded.

MetaTrader 4

In deinit(), add the following line of code:

RemoveAdvertising();

MetaTrader 5

In OnDeinit(), add the following line of code:

RemoveAdvertising();
6. Check that the advertising is loaded

In MetaTrader 4 only, you may want to check that the advertising can be loaded. (This step is not necessary in MetaTrader 5 because an EA or indicator which uses DLLs cannot be added to a chart unless the user turns on "Allow DLL imports".)

In the MetaTrader 4 start() function, before the call to LoadAdvertising(), you may want to add something like the following code to make sure that people cannot use your EA/indicator without the advertising being available and turned on:

if (!IsAdvertisingInstalled())
{
Alert("Please turn on \"Allow DLL imports\"");
return (0);
}
7. All finished!

You have now successfully added the advertising to your EA/indicator. All you have to do is re-compile it, and the advertising will start to be displayed. You distribute your EA/indicator via forums, our app store, or your own website, and you can then monitor the clicks in real-time from your account details.

Changing where the advertising is displayed

Optionally, you can control where on the chart the advert is displayed. The standard position is the bottom left corner, but you can change this by specifying three parameters for the call to LoadAdvertising()

  • Parameter 1: the corner in which to display the advert. 0 = top left, 1 = top right, 2 = bottom left, 3 = bottom right
  • Parameter 2: the number of horizontal pixels from the edge of the chart
  • Parameter 3: the number of vertical pixels from the edge of the chart

For example, the following code displays the advert 100 pixels from the top and 50 pixels from the edge of the top right corner of the chart:

LoadAdvertising(1, 50, 100);
Examples

If you are having any difficulties, you can check the steps involved by looking at the following examples where advertising has been added:

  • MT4 - Accelerator indicator.mq4 - a modified version of the standard MT4 "Accelerator" custom indicator
  • MT4 - MACD Sample.mq4 - a modified version of the standard MT4 "MACD Sample" EA. The advertising is displayed in the top left of the chart using the parameters for LoadAdvertising()
  • MT5 - Accelerator indicator.mq5 - a modified version of the standard MT5 "Accelerator" custom indicator (32-bit)
  • MT5 - Moving Average EA.mq5 - a modified version of the standard MT5 "Moving Average" EA (32-bit). The advertising is displayed in the top left of the chart using the parameters for LoadAdvertising()
Installing the DLL in your own installation package

You can install the FXAdverts DLL yourself in your own installation package, rather than using the installer above. The DLL can be put in the Libraries subdirectory of each MT4/5 installation, or it can be installed once, centrally, in the System32 directory. We recommend using the System32 directory because it can be difficult to establish the correct Libraries directory to use with MetaTrader 5.

N.B. On 64-bit versions of Windows, the DLLs for 32-bit software such as MetaTrader 4 are loaded from SysWOW64 instead of System32. Therefore, if MetaTrader 4 is installed on 64-bit versions of Windows, then the correct directory for the DLL is SysWOW64, not System32.

  • MetaTrader 4 (on 32-bit Windows): install MT4HelperLib.dll into the System32 directory
  • MetaTrader 4 (on 64-bit Windows): install MT4HelperLib.dll into the SysWOW64 directory
  • MetaTrader 5 (on 32-bit Windows): install MT4HelperLib.dll into the System32 directory
  • MetaTrader 5 (on 64-bit Windows): install MT4HelperLib64.dll into the System32 directory