April 2020

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 –

password:

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:

winecfg

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:

/home/USER_NAME/.wine/drive_c/MT4/MT41/MQL4/

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_REQUOTE138Requote.
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.

How to run the Metatrader in portable mode and what it is good for?

What is the portable version of Metatrader 4? What benefits does it bring? Learn all this is in our today’s article.

What is the portable version of Metatrader 4?

Portable is a portable program that can be booted from a portable device such as a flash drive, memory card or other disk location different from program files. The portable program is typically designed to store its configuration and user data in its own location and not on the system disk in the user’s data folder. In newer Windows, it can be usually found in:

“C \ Users \ ‘username’ \ appdata”, which is quite uncomfortable to work with. If we choose a portable version, we will have indicators, strategies, etc. in a folder such as C: \ mt4 \ MQL, which is more convenient.

What brings the portable version of Metatrader 4?

For me, it personally brings better overview and better handling of the MT4 platform. For example, I do not have to install MT4 every time, I can just copy the MT4 folder and use it for another account. Another advantage is greater simplicity when backing up the MT4 configuration or a possible shifting to another VPS – How to run Metatrader 4 on VPS.

Another advantage is that when I go for a holiday, I can have a MT4 backup on flash disk and if I there is a problem with my mobile or laptop, I can connect from any computer without installing MT4.

How to set up a portable Metatrader 4?

It’s fairly easy. In the shortcut icon/desktop icon just add / portable, as you can see bellow:

  • Right click on the mt4 icon
  • Select properties
  • Add to the target / portable

After this change, save the changes and then run MT4 as a portable from the directory where we you run it. I recommend to do this change right after installing MT4, if you modify an already running MT4, you may need to copy the original user data from the MT4 app data directory, which I do not recommend because you could forget something and then wonder that you have lost your indicator etc.

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

Tips for reducing Metatrader 4 CPU usage on VPS

Metatrader can take a lot of CPU resources because it does some extra operations that we do not need in order to run our automated strategies on VPS and this, of course, increases heavily the VPS usage. It renders charts, downloads unnecessarily long data, unused symbols, plays notifications and other features that are not necessary for running automated trading strategies. In today’s article, we’ll show you how to disable these features and reduce the CPU usage on VPS. Thanks to optimizations, we can multiply the number of running instances of Metatrader 4 to maximize the VPS potential. Regarding the VPS usage itself, I recommend tracking it with the Task Manager.

So, let’s start with the tips:

Minimize the MT4 application on the Windows bar

Minimizing the windows in MT4 – From practice, it turned out that at the moment when Metarader 4 renders charts, CPU usage is increased rapidly.

Hide all unnecessary symbols as shown in the picture – so the platform will not download unnecessary data for other symbols

Hiding the terminal with open commands – Metatrader does not have to render anything and the usage is smaller

Disabling news displayed in the platform,  please see the picture- this setting can be found in tools -> options

Disabling audio alerts, please see the picture – this setting can be found in tools -> options

Minimalizing the number of candles in the chart, see the image – here I recommend using a minimum value of 5000, when you put less candles, some strategies may not work accordingly.

Disabling the automatic movement of the candles in the chart, see the picture

After these optimizations, the Metatrader 4 platform may look like this.

As you can see it is not complicated and it is definitely worth running optimized mt4, so you can run as many MT4 platforms as possible on your VPS. You can save a lot of money 😉

Get access to the #1 Dashboard for AlgoTraders

Register for FREE and get access to:

By registering you agree with our Terms and Conditions