How to install Metatrader 4 under Linux

n today’s tutorial, I would like to show how to install Metatrader 4 or Metatrader 5 for Debian Linux distribution. The license fees for Windows Server are more than high and this can be the way how to save money for the VPS or physical server operating system.

Considering that some unexpected installation issues may occur during the installation or when running the Metatrader 4/5 process alone, this article is more considered for advanced users.

So let´s start. What are we going to need?

Now let’s start with the Wine installation:

 1. In order to avoid writing sudo with every command, switch to root user with the command and insert password.

su –


2. First we allow the installation of the 32-bit packages

dpkg –add-architecture i386

3. Add a key for wine repository:

wget -nc https://dl.winehq.org/wine-builds/Release.key
apt-key add Release.key

4. Add this repository line to the file /etc/apt/source.list file

deb https://dl.winehq.org/wine-builds/debian/ jessie main

5. Install package support from https using the command:

apt-get install apt-transport-https

6. Then update the list of packages from the repository using the run command:

apt-get update

7. Then install Wine using the command:

apt-get install –install-recommends winehq-stable

8. After Wine is installed, it is necessary to configure the wine and run it with the command:


after running this command, the pop up window will appear with the message that there are missing additional packages, that has to be installed, so click to download and install them.

9. When you start a winecfg, you need to set the emulation for Windows 7 (check the screen bellow):

We can now install Metatrader 4

1. Run the Metatrader 4 installation package and change the installation folder

2. Run Metatrader 4 and enter your login details

If we want to install MT5, we will use the same procedure. Metatrader 4 runs on Linux directly in portable mode, but the MT4 data are in a different location than in Windows.

!!! ATTENTION !!! Metatrader 4 data with strategies and indicators can be found in the following folder:


Note at the end

I wanted to know how the MT4 on Linux is demanding CPU vise, so I made an experiment. I ran the same amount of MT4 instances on Linux and Windows. My measurements were clear, the Windows emulation is worth some HW costs. On Linux, the CPU usage was roughly twice as on Windows.

The most common errors in Metatrader 4 and how to solve them

Metatrader is the most widely spread platform and it may happen that it will report us an error during our trading. In today’s article, we will have a look at the list of most common errors and we will describe how to deal with them.

 I put the strategy into MT4 but nothing happens. Is anything wrong? What should I do?

There may not be anything wrong. Sometimes it takes time until the strategy starts trading. Check the MT4 log (the “log” tab in the terminal) and if there is no error, the smiley laughs, then just wait until the strategy starts trading.

 I found the Trade is Disabled error in the log. What should I do?

This is the most common error with XTB broker and Purple Trading and it means that trading is forbidden.

XTB Broker Solution – Trading is forbidden on a standard account, and you must switch to Standard +.

Purple Trading Broker Solution – Probably, you have put the strategies in the wrong chart. You need to add a strategy to the right chart. If you use a STP account, you need to put strategies in a graph without the _ecn suffix if you have an ECN account, you need to use symbols with the _ecn suffix.

What should I do if Metatrader 4 is disconnected from the broker´s server?

Here are two options. The first option is to restart MT4. The second option is to click on the account with the right mouse button and click on sign in. If it still does not help, contact the broker if there is a problem on his side.

Error Indicator is missing is shown it the metatrader. What should I do?

Make sure you have a copied StrategyQuant indicators. Indicators can be found in C: \ StrategyQuant \ custom_indicators \ mt4 \ indicators. Copy these indicators into the MT4 MQL4 \ Indicators folder

In the Metatrader 4 log appeared error the trade context is busy. What should I do?

Most often, this error occurs when a lot of strategies (10 or more) are in one MT4 and MT4 cannot handle so many commands at a time. In this case, I recommend splitting strategies into multiple MT4s – simply said, for example install 10x MT4 and then logging 10 times under the same account. The recommended maximum strategy for one MT4 is 10. This is the tested number of strategies in which the program runs steadily and without problems.

Errors in Metatrader

Here is the list of errors and messages in MT4. If you would meet one of them and did not know how to proceed, please contact us.

ErrorError IDDescription
ERR_NO_ERROR0No error returned.
ERR_NO_RESULT1No error returned, but the result is unknown.
ERR_COMMON_ERROR2Common error.
ERR_INVALID_TRADE_PARAMETERS3Invalid trade parameters.
ERR_SERVER_BUSY4Trade server is busy.
ERR_OLD_VERSION5Old version of the client terminal.
ERR_NO_CONNECTION6No connection with trade server.
ERR_NOT_ENOUGH_RIGHTS7Not enough rights.
ERR_TOO_FREQUENT_REQUESTS8Too frequent requests.
ERR_MALFUNCTIONAL_TRADE9Malfunctional trade operation.
ERR_ACCOUNT_DISABLED64Account disabled.
ERR_INVALID_ACCOUNT65Invalid account.
ERR_TRADE_TIMEOUT128Trade timeout.
ERR_INVALID_PRICE129Invalid price.
ERR_INVALID_STOPS130Invalid stops.
ERR_INVALID_TRADE_VOLUME131Invalid trade volume.
ERR_MARKET_CLOSED132Market is closed.
ERR_TRADE_DISABLED133Trade is disabled.
ERR_NOT_ENOUGH_MONEY134Not enough money.
ERR_PRICE_CHANGED135Price changed.
ERR_OFF_QUOTES136Off quotes.
ERR_BROKER_BUSY137Broker is busy.
ERR_ORDER_LOCKED139Order is locked.
ERR_LONG_POSITIONS_ONLY_ALLOWED140Long positions only allowed.
ERR_TOO_MANY_REQUESTS141Too many requests.
ERR_TRADE_MODIFY_DENIED145Modification denied because an order is too close to market.
ERR_TRADE_CONTEXT_BUSY146Trade context is busy.
ERR_TRADE_EXPIRATION_DENIED147Expirations are denied by broker.
ERR_TRADE_TOO_MANY_ORDERS148The amount of opened and pending orders has reached the limit set by a broker.

Tips for safe VPS operation with Metatrader 4

In today’s article, I will show you how, with a few tricks, we can secure our VPS, where our real accounts are running. This is the reason why we need to prevent our server from being hit by potential attackers. I know from my own practice that if you have opened a VPS port for a few minutes, the first attacks or attempts to connect are emerging. VPS security should not be underestimated.

Let’s take a look at some tips:

Tip 1: Restrict Remote Desktop Access (RDP) to a specific IP address

The most effective way is to restrict access to a specific IP address only. In order to connect, we need to have a fixed IP address or secure VPN server address from which we connect to VPS. If you do not have a static public IP or VPN, we recommend at least changing the default remote desktop port.

Tip 2: Change the remote desktop access port

Most RDP attacks take place on the default port 3389. You can easily change this port, but you need to consider other services that are using this port.

Tip 3: Back up

Most VPS providers offer the possibility to back up entire images – so-called snapshot VPS or they offer some backup space. In case of a server attack, the entire image of the disc with minimal downtime can be restored.

Tip 4: Do not open other than needed ports

Keep the firewall set strictly only for the services and IP addresses you need on internet.

Tip 5: Use strong passwords for Administrator and User Accounts

We recommend using a password that contains both uppercase and lowercase letters, digits and at least one special character.

Get access to the #1 Dashboard for AlgoTraders

Tip 6: Do not overload VPS

Monitor the VPS usage with Resource Monitor or Task Manager. When the Metatrader 4 is in the steady mode, the usage should not exceed 40% of the total VPS CPU. Ideally even less. We should not forget the sufficient reserve when the market starts to move and there is a high volatility. This moment is absolutely critical, and the VPS must stand this situation too. At this point, the platform must be stable and have sufficient power to keep robots working, as they were programmed. At this point, it is mainly about the trailing stop and the possible exit order.

If you use VPS from some commercial VPS providers, you should be cautious because some of them block VPS, which exceeds 60% of CPU for more than 30 minutes. In this case, there will be limitations to 200 MHz CPU power. This is causing that the VPS is lagging and can hardly be controlled when connected over a remote area.

Tip 7: Ensure that the VPS server is running

VPS Providers Offer Server Monitoring Service. In the event of a downtime, you will be informed about the possible problem by email or SMS to avoid unnecessary complications.

Tip 8: Update regularly

Keep the system up to date and apply the latest security patches. More at https://technet.microsoft.com/en-us/library/cc731322(v=ws.11).aspx. The same applies to Linux. After you apply the system update, restart it. This activity is appropriate during the weekend when the trading is stopped.

Tip 9: Update the Metatrader 4 platform

Metatrader 4 has automatic updates, so it is enough to turn the platform on and off, the update is done in the background when the platform is started. After updating, it’s a good idea to go through all charts if the strategy runs properly. From time to time, the strategy may disappear.

Get access to the #1 Dashboard for AlgoTraders