MT4 (Manager API) to MT4

This tool uses the MetaTrader 4 Manager API to read trade activity from a source MT4 server and replicate it to other MT4 servers.

This tool uses the MetaTrader 4 Manager API to read trade activity from a source MT4 server and replicate it to other MT4 servers.

Installation

Put all files into a separate folder

Keep the tool isolated in its own directory.

Add the Manager API libraries

Obtain the mtmanapi.dll files and copy them into the application's folder.

Add the server API library

Obtain the M4ServerAPI.dll file and copy it into the application's folder.

Generate the settings file

Run the program once to let it generate an empty settings file.

The Chocolatey package is available here: CPlugin.CopyTrade.ManAPITool.NET versions.

Settings

The first time you run the application it generates a sample settings file named CPlugin.CopyTrade.ManAPITool.NET.xml. The file is self-explanatory XML. For your convenience we also include an example settings file, CPlugin.CopyTrade.ManAPITool.NET.xml.example.

Source MT4 server

In the <source> node you put the source MT4 server address and the credentials for the manager account.

Destination MT4 servers

Many <copy> nodes can describe destination accounts, which may even live on different servers.

Filtration

The where parameter describes an expression using FLEE notation to check that a trade meets your requirements. You can use the trade variable to check its volume, symbol and other fields.

For example:

where="trade.Login = 1000 and trade.Volume > 100"

Checks that the login is 1000 and the volume is greater than 1 lot (100 in the MT4 API).

where="trade.Login in (1000;1001;1002) and trade.Symbol = EURUSD"

Checks that the login is one of 1000/1001/1002 and the order symbol is EURUSD.

The ; separator follows your local Windows OS settings → regional settings → list separator.
Copying settings
  • guid — a unique GUID that must be set once and never changed. The program stores its cache and, after closing, needs this GUID to understand which server holds which trades.
  • address, port, login
  • coef — coefficient of the volume to be copied. For example, 1 means 100%, and -1.5 means 150% in the opposite direction.
  • open_slippage, close_slippage — allowed slippage on trade open/close respectively.
  • copy_sl, copy_tp — whether to copy SL/TP levels.
  • copy_commenttrue/false to enable copying the trade comment from the source trade to the copied one.
  • set_comment — if copy_comment is set to false, you can put any string here to use as the comment for the copied order.
Symbol names mapping

Each <copy> can have multiple <map> nodes. A <map> node describes a mapping between different symbol names.

The from field contains a regular expression for the source server symbol name that has to be mapped into the to expression.

For example, to map from regular symbols to a symbol with a dot suffix:

<map from="(\w+)" to="$1." />

Here we use the $1 substitution and . as the suffix.

Another example:

<map from="(...)(...)p" to="$1$2c" />

This maps every symbol ending with p and containing six characters before it to the same symbol with a c character at the end. For example, EURUSDp is mapped to EURUSDc.

Using

Using the tool is simple: just run the application and watch its journal on screen and/or in a file, depending on your NLog settings, which you can adjust through the NLog.config file.

To exit, press the Q key on your keyboard.

Even after you close and start it again, the tool maintains its open trades list in the storage.bin file cache.

Do not remove the storage.bin file without a real reason. The program might lose the binding between its internal orders database and the real MT4 orders.

A full example settings file:

<?xml version="1.0" encoding="utf-8"?>
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <source
    address="127.0.0.1"
    port="443"
    login="1"
    password="password123" />
  <copy
    where="trade.Login = 1000">
    <to
      address="127.0.0.1"
      port="443"
      login="1002"
      password="Trader"
      coef="-0.5"
      open_slippage="2"
      close_slippage="10"
      copy_sl="false"
      copy_tp="false"
      copy_comment="false"
      set_comment=""
      guid="050b29c5-0d55-4dbd-bb78-a4dfd24858ed">
      <map
        from="(...)(...)p"
        to="$1$2c" />
    </to>
    <to
      address="127.0.0.1"
      port="443"
      login="1002"
      password="Trader"
      coef="-0.5"
      open_slippage="2"
      close_slippage="10"
      copy_sl="false"
      copy_tp="false"
      copy_comment="true"
      set_comment=""
      guid="050b29c5-0d55-4dbd-bb78-a4dfd24858ed">
    </to>
  </copy>
</settings>