"Meta"-Trader 4/5 Bridge Plugin
"Meta"-Trader 4 and 5 (MTR4 and MTR5 in short) are popular trading platforms that are
provided free by most Forex or CFD brokers, sometimes under different names.
Zorro's MT4/5 bridge controls
the MTR4 or MTR5 platform - the "client terminal" - through an "Expert Advisor" (EA)
This way Zorro can trade with almost all Forex/CFD brokers.
MTR4 Terminal with attached Zorro
The client terminal runs on the trader's PC and communicates with the
broker's MTR4 / MTR5 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 MTR4/5 side it appears as a 32 bit or 64 bit library DLL that can be called from any EA. On the Zorro side it appears as a Broker Plugin DLL. This way the bridge can theoretically be used not only by Zorro, but also by any other software for reading prices and sending orders to
the MTR4 or MTR5 terminal.
Zorro login fields:
||Account number (as in the terminal's title bar)
Accounts.csv example entries:
Installation and setup
Installing the MT4/5 bridge requires basic Windows knowledge: you should be
familiar with the concept of folders and how to copy files between them, and you
should also know your broker's available assets and their symbols. First make sure that you have installed Zorro and the broker's MTR4 or MTR5 platform (for MTR5 the 64 bit version is required).
If you have the choice, use MTR4, which is more reliable than MTR5 and supports
more broker commands. Connect to your MTR4/5 account with the login data from your broker.
- For MTR4: Locate the ZorroMT4.zip archive in your Zorro folder. In the Terminal, select File / Open Data Folder for locating the MQL4\Experts and MQL4\Libraries folders. Unzip the archive. It contains 3 files: Zorro.mq4 goes into the Experts folder, and ZorroMT4.ex4 and ZorroMT4.dll both go into the Libraries folder. Zorro.mq4 is the EA, ZorroMT4.ex4 is its library for connecting MTR4 to Zorro, and ZorroMT4.dll handles the communication between the two programs.
- For MTR5: Locate the ZorroMT5.zip archive in your Zorro folder. In the Terminal, select File / Open Data Folder for locating the MQL5\Experts\Advisors and MQL5\Libraries folders. Unzip the archive. It contains 4 files: Zorro.mq5 and zmq4.mqh go into the Experts\Advisors folder, ZorroMT64.ex5 and ZorroMT64.dll both go into the Libraries folder. Zorro.mq5 is the EA, zmq4.mqh is a header file for converting mql4 to mql5 code, ZorroMT64.ex5 is the library for connecting MTR5 to Zorro, and ZorroMT64.dll is a 64 bit DLL that handles the communication between the two programs.
As long as your MTR version is not running in "portable mode", the Experts and Libraries folders are normally located in your user directory (under C:\Users\YourName\AppData\Roaming\MetaQuotes\Terminal\SomeStrangeCodeSequence). There is also a MQL4 or MQL5 subfolder directly
in the terminal's installation directory - that's NOT the folder that you need, and copying files there will have no effect!
- In the Terminal, open the Expert Options under Tools / Options / Expert Advisors.
Make sure that [Allow Automated Trading] and [Allow DLL Imports] are
both enabled. The Auto Trading button below the menu bar must also be enabled. In the Navigator under Expert Advisors you should now find the entry [Zorro].
If not, right click on Expert Advisors and select Refresh.
If you copied a new version or modified the Zorro EA, compile it: double click on Zorro.mq4/mq5
in the Data Folder for opening it with the MetaEditor, then hit
Compile, afterwards do a Refresh
again. Make sure that the terminal is connected to a valid account and that you are logged in;
otherwise it can crash as soon as you start an EA. Open a chart window with the asset that you want to trade; for multiple assets use an EUR/USD chart. The time frame of the chart does not matter.
Drag the Zorro EA onto the chart window. Confirm in the pop-up dialog that DLL imports and live trading are enabled. You should now see the comment "Controlled by Zorro
EA" with a version number in the upper left corner of the chart, and a smiling face (MTR4) or a head with a green arrow button (MTR5) next to "Zorro" in the upper right corner. If the EA does not start, look for the reason under the Experts
tab: you might have forgotten to copy a file or to check an option.
- Check the assets that you want to trade, and make sure that they are available in the Market Watch window (a right click and Show All enables all assets). Make also sure that the assets have similar names as the assets traded by your strategy. Forex pairs that differ in a missing slash and an added suffix (f.i. "EURUSDpro" instead of "EUR/USD") are corrected automatically. But if you want to trade other assets that have
very different names (f.i. "GOLD" instead of "XAU/USD", or "DE30EUR" instead of "GER30"), convert the names as described below under Symbols. Also make sure that the time and time zone on your PC or VPS are set up correctly - Zorro needs the correct time while trading.
- Now start Zorro. Select [TradeTest] in Zorro's Script scrollbox and [MT4/5] or [MT4/5 (demo)] in the Account scrollbox. Enter your account number (visible in the
terminal's title bar) in the [User] field. The content of the [Password] field does not matter. Make sure that [Demo] / [Real] is set to the same account type as in the
terminal's title bar. For a demo account the word "- Demo Account - " must be visible in the title bar. Otherwise, open a demo account in
the terminal through File / Open an Account. If the account number and type are correct, clicking [Trade] will now attach Zorro to
the terminal and handle price quotes and orders through the broker's Meta
You should see the broker's name in Zorro's message window on login, and a "Zorro connected" comment in the upper left corner of the
terminal's hart window. The asset prices are now downloaded from the server. When accessing an asset the very first time,
the terminal will need a minute or longer for downloading it from the server (equivalent to the "Waiting For Update" message when opening a chart
in the terminal the first time). You'll then see an error message in the Zorro window since the data is not yet available; just connect again after a minute until all assets are loaded. If you get other error messages, look under Known issues .
For some reason, following the 4 steps above is 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:
- Do you see the Zorro EA under Expert Advisors?
If not, you probably installed it in a wrong folder. Start over.
- Do you see the "Zorro" icon in the upper right corner of the chart? If
not, you have not successfully dragged the Zorro EA on the chart. Aim
- Do you see the "Zorro EA" message in the upper left corner? If not, you
have probably not enabled automated trading or DLL import. Try again.
- Does Zorro not connect on session start? You possibly mistyped the
account number or used a wrong account type (Demo/Real). Try harder.
- Does it still not work? Check out if one of the connection issues
mentioned below affects your configuration.
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 with the 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
We'll then install Zorro with MT4/5 bridge on your PC or VPS by remote access,
ready to trade, together with an asset list adapted to your broker. This, also, has 100% success
MTR4/5 connection issues
- The MT4/5 bridge requires Zorro S for
trading on real accounts. The "Meta"-Trader terminal and Zorro must run on the same PC in the same Windows environment, and must be started by the same user.
- With Zorro S, several Zorro instances can connect simultaneously to a single terminal. Otherwise, only one Zorro instance can connect. Do not attach the Zorro EA to more than one chart window in a single
terminal instance. For running several terminals simultaneously for special purposes - for instance, signal providing - install
them several times in separate folders.
- MTR4 and MTR5 both have a heavy resource and bandwidth footprint. This can cause long response times, dependent on VPS performance and Internet connection.
Do not run more than a single MTR4/5 client on a low-performance VPS (such as the free Amazon VPS) and not more than 3 clients on a high-performance VPS.
Connect not more than 2 or 3 Zorros to a single MTR4/5 client. For making
MTR4/5 a bit faster, close all chart windows except for the Zorro EA chart,
and remove all assets except for the traded assets from the
Market Watch window.
- While Zorro is connected to MTR4/5 in [Trade] mode, do not close or reset the chart with the Zorro EA. Closing the chart will stop the EA and disconnect Zorro (visible by a red square next to the
Server window, and a frozen server time). It must then be stopped and restarted. Same issue with changing the account: the Zorro EA must be restarted by
removing and attaching it again.
- Some MTR4 versions are set up to not automatically compile EAs. In this case the Zorro EA will appear grey in the Navigator and can not be attached to a chart. Open it
in the Experts folder with the MetaQuotes Language Editor and click [Compile] - this will encode the source code and store it as an .ex4 file, which can then be attached to a chart.
- Some old MTR4 versions physically delete .ex4 files that have been generated with a newer MTR4 version. The reason for that bizarre behavior is unknown, but you'll find that the
ZorroMT4.ex4 file suddenly disappears from the libraries folder upon lauching MTR4. Consequently the Zorro EA will generate an error message because the ZorroMT4 library is not found. In that case just update MTR4 to the current version, and copy
ZorroMT4.ex4 again into the libraries folder.
- When getting a practice account number and password directly from a broker, it's sometimes displayed as "Real Account" in the MTR4/5 title bar. Since the 'demo only' version of the bridge can not trade with real accounts, you need to open a true demo account. You can open any number of demo accounts directly in MTR4 by selecting
File / Open an Account.
- The MT4/5 bridge was tested with all currently available Meta Trader
terminal builds, and is tested with any new upgrade. Since new builds are often not fully compatible to their predecessors, do not upgrade a working system.
If the terminal upgrades behind your back and you experience problems afterwards, please report on the user forum or to Zorro Support.
MTR4/MTR5 trading issues
- If a trade does not open or close (Error 075), you can
see the reason in the MTR4/5 Experts Log. The live log is displayed under the
Experts tab. The Experts log is also stored in the Data Folder
under MQL4\Logs (MTR4) or MQL5\Logs (MTR5).
There's also a journal unter Logs. Valid reasons for not opening or closing a trade are not enough funds, no
permission to trade that asset, a wrong asset symbol, a wrong NFA flag, market
closure, FIFO violation, or a wrong stop distance. All this, except for the
funds and permission, can be fixed in your script, in the account list, or in the asset list.
- The OrderLimit variable is supported by MTR4, but
does not create a limit order, but only an 11 minutes pending trade.
- Some MTR4/5 client terminals have not all assets enabled by default. Disabled assets are not visible in the "Market Watch" window and not available for trading. For enabling them, right click on "Market Watch", select "Symbols", select the symbol(s) you want to trade, and click "Show". But do not select more than you actually trade, since any additional asset in the Market Watch requires bandwidth, memory, and CPU resources.
- Some MTR4/5 brokers - for instance, LMAX - provide
several different symbols for the same asset. Only one of these symbols is really traded, so make sure that you have the right symbol on the chart window with the Zorro EA.
- MTR4/5 clients of some brokers can consume a lot of
especially when many assets are traded simultaneously. This is apparently
caused by a slow access to the broker's MTR4/5 server. For reducing the CPU
load in such a case, edit the Zorro.mq4/mq5 EA and change
the MSTIMER definition at the begin of the EA to a higher
number, such as 500. Then compile the EA again. The
disadvantage is a slower reaction to commands.
- Some MTR4/5 brokers provide correct rollover, margin, and commission
values, others don't; it depends on the MTR4 server setup. If trading cost
parameters are unavailable, the values entered in the
asset list are used. Asset lists downloaded from MTR4 servers often need manual correction.
- Some MTR4/5 servers need a long time for the initial access of the price history of previously unused assets. This can cause a timeout. The strategy will then not start, and a Error 054 or Error 055 message is displayed. In that case just restart the strategy by clicking [Trade] again. Inbetween the server had enough time to upload the missing asset. You might need to repeat that step
a few times until all assets load properly.
- Some MTR4/5 servers have insufficient price history for systems with a long lookback period, such as Z1, Z2, or Z12 - especially when starting after a holiday. The strategy will then not start, and a Error 047 message is displayed. In that case use the PRELOAD flag or the Preload .ini setup for using Zorro's own history instead of the
Meta Trader server.
- Some MT4 brokers were reported to route historical price data requests
on weekends to a different server and return dubious
price data for out-of-market hours.
- Most MTR4/5 servers can download only a limited live price history, such as 2000 hours. Therefore the assetHistory function and the Download script normally does not work with MTR4 or MTR5; downloading large historical price data requires direct access to your broker's API.
- Trades via MTR4/5 are usually executed not on the real market, but on a
virtual market generated
by the MTR4 server. In that case you must NOT set the NFA flag, as the virtual trades are not NFA compliant. Still, hedging can be prohibited, so set
Hedge mode to 0 or 4 in that case. If the account complies with NFA FIFO rules (first in, first out), you must close old trades before closing new trades. Otherwise you'll see an error message like
"Close failed - prohibited by FIFO rules" in the Experts log. Use
Hedge = 4 in such a case, which automatically ensures FIFO compliant closing of trades. Note that you can not run multiple strategies in parallel on no-hedging or FIFO compliant accounts.
- Not all MTR4/5 brokers support partial closing of trades. You can see this from an error message like
"invalid trade volume" in the Experts log,
or from 'remainders' of trades that stay open due to failed partial closes.
Some brokers emulate partial closing by closing the whole position and opening
a new one with the remainder. If the closing fails, trades are not under Zorro
control anymore. In case of any problems with partial closing, set
Hedge to 4 or below for disabling
- Some MTR4/5 brokers use odd PIP sizes for CFDs, such as 0.25, and don't accept stop limits that are not a multiple of this pip size. In this case set up the correct PIP size and PIPCost value in the
- Some MTR4/5 brokers use their own units for rollover. Sometimes it's per
lot, sometimes per 10,000 contracts. Check the rollover and other parameters
in your asset list when trading through MTR4 or MTR5. Wrong values are not
harmful for trading, but give a wrong result in the backtest.
- If the communication between the MTR4/5 client and server breaks down,
the Experts Log contains messages such as "communication lost"
or "trade timeout". In the latter case, orphaned positions
are possible. It is not recommended to trade with an unstable client/server
- The terminal displays prices as Bid prices, while Zorro always uses
Ask prices. So you'll see different prices on the
terminal's charts and in the Zorro window. This has no effect on trading, as Zorro internally converts all prices to Bid or Ask dependent on the trade direction.
- Communication between Zorro and the terminal on the same PC is normally very fast, so trading with the MTR4/5 bridge does not add noticeable
latency compared to directly trading with an "Expert Advisor". Still, if a broker offers both API and MTR4/5 access, using the API is normally preferable. If they offer both MTR4 and MTR5, MTR4 is preferable. The API is faster than the MTR4/5 server, and MTR4/5 accounts are
said to be often slightly more expensive due to additional spread and slippage.
Many MTR4/5 versions use special asset names with broker specific suffixes. For instance, the "EUR/USD" currency pair is called "EURUSD" in the MTR4 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 adaption is required on your side.
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, and you'll get "asset unavailable" error messages when starting your script.
All assets you want to trade must be visible in the Market Watch window. If you still get error messages about unavailable assets,
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 MTR4/5 bridge supports the following features:
- marketVal: Not supported in historical data,
spread in live data.
- marketVol: Normally not supported in historical data, tick frequency in live data.
- Partial closing: Supported by some, but not all MTR4 brokers; see
remarks above. Normally not
supported by MTR5.
The MT4/5 bridge supports the brokerCommand function with the following commands:
- GET_POSITION (MTR4 only)
- PLOT_HLINE (MTR4 only)
- PLOT_TEXT (MTR4 only)
- PLOT_MOVE (MTR4 only)
- PLOT_REMOVE (MTR4 only)
- PLOT_REMOVEALL (MTR4 only)
- PLOT_STRING (MTR4 only)
You can add your own commands for sending or retrieving further information from the MTR4/MTR5 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 and can be used for calling arbitrary MTR4 / MTR5 functions. Use arr 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 MTR4/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 MTR4 init() function.
0 when the initialization failed, otherwise nonzero.
Release the Zorro plugin. Normally called in the MTR4 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 MTR4 start() function.
||Array of up to 10 double variables that are filled with the request parameters.
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 MTR4 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.
||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 of up to 10 double variables containing the response parameters.
Example: see Zorro.mq4 or Zorro.mq5
Brokers, brokerCommand, order, broker plugin