Roll Your Own Metatrader VPS
If you are a serious forex trader then sooner or later you would give serious consideration to running your trading platform on a Virtual Private Server (VPS), which is essentially a computer hosted in a service provider’s data center. This data center is set up for 24×7 operation with high availability facilities, computer infrastructure, and internet connection. Leaving your laptop or desktop running all the time may not be practical because your office may go green and there is still a risk of electricity or internet failure in your house. You certainly need these 24×7 capabilities to run your trading platform without any interruption or downtime, if:
- You keep track of some indicators that will give you a warning when a certain condition happens, without having to sit in front of your computer all the time.
- You run mechanical or algorithmic trading with Expert Advisors (EAs).
- You are a frequent traveler who may not be able to connect to the Internet reliably in certain places.
There are many VPS providers offering this kind of service, and some forex brokers even provide it for free if you trade with certain transaction volumes. Nevertheless, if you are already acquainted with the cloud server, you can actually run your own trading platform in the cloud and treat it as a VPS. Here are some of the benefits:
- It is cheaper. You can rent a cloud server as low as $2.5 a month. Further, you will be billed per minute or per hour of use.
- You can cancel the service at any time you like, without a minimum contract. In fact, after setting up your cloud server and if for some reason you don’t like it, you can just shut down and delete it. You just need to pay for a few hours of usage and you can move on to try another cloud provider. Many trading platform VPS providers require a term of at least a few months.
- Many cloud providers have a global infrastructure and present in many locations in the world. You can easily choose the cloud server location that is closer to your broker’s server to minimize network latency.
- It is easy to scale. You can start with the minimum configuration that later you can easily upgrade to a larger configuration with just a few clicks and reboot. Definitely, you will need a larger server if you later run more indicators and more complex EAs.
Nowadays the difference between VPS hosting and cloud hosting is subtle so people are using the term interchangeably but for you who are really curious, please refer to this explanation.
Installing MetaTrader in an Ubuntu Cloud Server
In this tutorial, I’ll show how to install and run MetaTrader 4 in the cloud. MetaTrader 4 is the most popular retail trading platform for trading Forex. Since MetaTrader 5 which is the next version of MetaTrader is identical to MetaTrader 4 from the installation point of view, this tutorial is also applicable to MetaTrader 5.
Metatrader is windows application and although you can deploy a cloud server with Windows Server OS, it will be more expensive than a cloud server with Linux OS. Herewith I will use Ubuntu 18.04 OS and Wine that enable windows application to run on Linux. By the way, I assume that you already know how to deploy a cloud server and how to use MetaTrader 4 so that I won’t explain it in this tutorial.
Cloud Server Requirements
I started with the following configuration:
- 1x vCPU or Core
- 1GB RAM
- 10GB SSD
- Ubuntu 18.04 Minimal (barebone) LTS
RAM is the most pricey so to reduce its requirement, beside barebone Ubuntu 18.04 OS, I chose the lightweight LXDE desktop environment. However, when Wine and Metatrader are installed and 4 default charts are opened, it just requires 422MB and basically no swap space.
$ free -h
total used free shared buff/cache available
Mem: 979M 422M 162M 6.8M 394M 405M Swap: 2.0G 35M 2.0G
Based on this information, to reduce the cost further, you could try 512MB or even 256MB but you need to properly configure the swap space as explained in this article. Keep in mind that this swap space will only be effective if you use SSD instead of the standard HDD. Fortunately, most cloud providers now provide it as the standard offering.
Installing GUI on Ubuntu Server
Unlike Windows Server, a minimal Ubuntu server only comes with CLI. You need to add GUI desktop environment with its remote access. There are two tutorials in this blog that show you how to do that:
While I use X2Go in this tutorial you are free to use VNC instead by following the tutorial.
Once you get your Ubuntu server deployed, you need to log in and perform the commands below. SSH is the standard tool to remotely access Linux server if your local computer is Windows then there are two options:
Install LXDE desktop environment
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install lxde
Install X2Go server and its bindings
$ sudo apt-add-repository ppa:x2go/stable
$ sudo apt-get update
$ sudo apt-get install x2goserver x2goserver-xsession x2golxdebindings
Install X2Go client
You need to install X2Go client on your local computer. Please follow this instruction because it depends on your local computer platform. With X2Go client, you can now access your remote cloud server using GUI.
Installing MetaTrader with Wine
Although you can continue to use SSH to perform the following commands but let’s use X2Go client instead. Open LXTerm and perform Wine and MetaTrader installation from the LXTerminal window.
$ sudo dpkg --add-architecture i386
$ wget -nc https://dl.winehq.org/wine-builds/winehq.key
$ sudo apt-key add winehq.key
$ sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'
$ sudo apt update
$ sudo apt install --install-recommends winehq-stable
You need to add the Metatrader installation file that you get from your forex broker to your home directory on the cloud server. You can use Firefox which is LXDE’s default browser to download the file directly. You can also transfer the file from your local computer using X2Go shared folder feature or use SCP Linux utility (part of PUTTY for Windows).
$ scp Metatrader-MT4Install.exe email@example.com:.
Metatrader-MT4Install.exe 100% 1188KB 128.5KB/s 00:09
Go back to LXTerm terminal on the server and verify if the installation file exists in the home directory then install Metatrader using Wine:
$ lsDesktop Downloads Music Public Videos Documents Metatrader-MT4Install.exe Pictures Templates winehq.key
$ wine Metatrader-MT4Install.exe
You may get pop up windows of Wine Mono Installer and Wine Gecko Installer, in that case just install it. From then on, it is the same as installing on your windows laptop.
You now have your Metatrader running 24×7 on the cloud (VPS). There is no difference in how to use it, including the location of indicators, EAs, profiles, etc, just open the Data Folder from the File pull-down menu.