The Meta-Trader 4/5 Bridge

Meta-Trader 4 and 5 (MT4 and MT5 in short) are popular trading platforms that are provided by many Forex or CFD brokers, sometimes under different names. Due to the many shortcomings in algo trading, professional trading systems normally win't run directly on MT4 or MT5. But the platforms can be used for connecting to the broker and executing trades for a system that runs on a different software such as Zorro. The connection from Zorro to MT4/5 is established by a bridge software.

Zorro's MT4/5 bridge allows C/C++ algo trading strategies to receive prices or trade assets through the MT4 or MT5 "client terminal". This way Zorro can trade with almost all Forex/CFD brokers.

The client terminal runs on the trader's PC and communicates with the broker's MT4 / MT5 server via Internet. This server generates prices with a mechanism determined by the broker, manages the trades, and calculates their wins or losses. The MT4/5 bridge DLL has two sides. On the MT4/5 side it appears as a 32 bit or 64 bit library DLL that can be called from any Expert Advisor (EA). On the Zorro side it appears as a Broker Plugin. The bridge can theoretically be used not only by the Zorro platform, but also by any other software for reading prices and sending orders to the MT4 or MT5 terminal.

Zorro login fields:

User Account number (as in the terminal's title bar)
Password Empty

Installation and setup

Installing the MT4/5 bridge requires copying some files. For this you should be familiar with the concept of files and folders on a Windows PC. You should also know your broker's provided assets and their symbols. First make sure that you have installed Zorro and the broker's MT4 or MT5 platform (for MT5 the 64 bit version is required). Despite the lower version number, MT4 is better suited than MT5 for automated trading, since it requires less code, is more robust, and supports more broker commands. If your broker offers both, use MT4. Start the platform and connect to your account with the login data from your broker.

Installation troubleshooting

For some reason, following the 4 steps above turned out to be not easy for all users. Failure in installing the bridge is one of the most frequent support issues. The most common mistakes are installing the bridge in a wrong folder, not starting the Zorro EA, or not enabling automated trading in the platform. If you had no success in installing the bridge, here's what to check first:

By carefully following the installation steps, anyone so far got the bridge running - success rate 100%. If the above installation instructions are not enough, you can get a much more detailed instruction with many illustrations and screenshots from a RobotWealth Algo Bootcamp. But if you really feel unable to install the bridge for whatever reason, we can do it for you. Order the installation service on the support page. We'll then install Zorro with MT4/5 bridge on your PC or VPS by remote access, ready to trade and optionally with an asset list adapted to your broker. This, also, has 100% success rate.

MT4/5 connection issues

MT4/MT5 live trading issues

MT4/MT5 Symbols

Many MT4/5 versions use special asset names with broker specific suffixes. For instance, the "EUR/USD" currency pair is called "EURUSD" in the MT4 version by FXCM™, "EURUSDm" in the IBFX™ version, "EURUSDi" in the version by Traders Way™, and "EURUSD.G" in the Global Prime™ version. The Zorro EA automatically adapts the names by removing the slash and adding the broker specific suffix from EURUSD symbol name of the EA chart window. So no symbol adaption is required on your side.

If this automated suffix appending is not desired, use a chart window for Zorro with an asset that does not contain a suffix.

For non-currency assets with names longer than 6 characters, or for names that can not be automatically adapted this way - for instance, "GOLD" instead of "XAU/USD" - the symbols used by Meta Trader must be entered directly in the Symbol column of the used asset list. Otherwise your selected assets are not found in the terminal's symbol list, your script won't start, and you'll get "asset unknown" error messages in the Experts log. Fix the asset name, then close MT4 and Zorro and start them again.

All assets you want to trade must be visible in the Market Watch window. If you still get error messages, you can find the reason in the Experts Log that the terminal generates. It normally tells you what the problem is.

Additional data and commands

The MT4/5 bridge supports the following features:

The MT4/5 bridge supports the brokerCommand function with the following commands:

You can add your own commands for sending or retrieving further information from the MT4/MT5 client. For this, edit the zorro.mq4 / zorro.mq5 EA. Any brokerCommand(Command,Parameter) call in a Zorro script triggers the CMD_BCOMMAND part of the Zorro EA run loop. Use a Command number between 2000 and 2999 for not getting into conflict with future official broker commands. The parameter is transferred in arr[1] and can be used for calling arbitrary MT4 / MT5 functions. Use arr[0] for transferring a numerical return value back to Zorro. Be aware that sent parameters are stored on the terminal side and thus affect all Zorro instances connected to that terminal - not only the instance that sent the parameter.

 

Zorro EA functions

Zorro can directly trade with MT4/5 through the Zorro Expert Advisor. This EA is included in MQ4/MQ5 source code, so it can be used as a template for writing own EAs that evaluate trade signals from Zorro. For this the following four functions are available in the ZorroMT4.ex4 or ZorroMT5.ex5 libraries:

ZorroInit () : int

Open the Zorro plugin. Normally called in the MT4 init() function.

Returns:

0 when the initialization failed, otherwise nonzero.
 

ZorroExit ()

Release the Zorro plugin. Normally called in the MT4 deinit() function.
  

ZorroRequest (double& array[]): int

Receive a request from the DLL, f.i. for opening a trade. Normally called in a loop in the MT4 start() function.

Parameters:

array Array of up to 10 double variables that are filled with the request parameters.

Returns:

0 if no request is pending, otherwise one of the following commands: CMD_COMMENT, CMD_PRINT, CMD_ASSET, CMD_HISTORY, CMD_BALANCE, CMD_BUY, CMD_TRADE, CMD_SELL, CMD_STOP, CMD_BCOMMAND (see Zorro.mq4). The zstring() function returns a string containing the requested asset name or a text message. Asset names need possibly be converted to the specific symbol names of the MT4 version (see remarks).
 

ZorroRespond (int cmd, double& array[])

Respond to a request from the DLL. Normally called to transfer the result after receiving a request.

Parameters:

cmd One of the following commands: CMD_ASSET, CMD_TICK, CMD_HISTORY, CMD_BALANCE, CMD_BUY, CMD_TRADE, CMD_SELL,CMD_STOP, CMD_BCOMMAND (see Zorro.mq4).
array Array of up to 10 double variables containing the response parameters.

 

Example: see Zorro.mq4 or Zorro.mq5

See also:

Brokers, brokerCommand, broker plugin, MQL4 language

► latest version online