lewis ngugi f5pTwLHCsAg unsplash 3t1 - Preparing for a Forex VPS Failure

Preparing for a Forex VPS Failure

If you operate a VPS with Expert Advisors for automatic trading, you cannot independently check around the clock that everything is working smoothly. Especially the use of VPS and Expert Advisors are perfectly suited for automatic trading in the background. Due to unforeseen circumstances or complications, the user should, among other things, ensure that

  • the VPS is started
  • Windows is started and the Windows user is logged in
  • Windows has an active Internet connection
  • all relevant MetaTrader terminals are started
  • the correct profile is loaded in MetaTrader
  • there is a connection between MetaTrader and the broker’s server

It can always happen that a MetaTrader terminal crashes. In this case, it must be automatically detected and the affected terminal must be restarted, making sure that the correct profile is loaded. It is also possible that a terminal loses the connection to the broker server. This problem must also be detected and corrected. It must also be assumed that the VPS or also the Windows server can crash due to an error and must be restarted. In this case, the Windows user must be logged in completely automatically and all relevant MetaTrader terminals must be started with the correct profile.

In the following, we show from years of experience how we set up our VPS and protect ourselves from VPS total failure.

Preparing Windows and VPS

This section is dedicated to the settings, for preparing the VPS and the Windows server for a total failure.

The figure below shows the simplified overview of the preparation of the VPS, Windows Server and MetaTrader 4.

Preparing for a VPS Total Failure 02 - Preparing for a Forex VPS Failure
Overview of preparing the VPS, Windows Server and MetaTrader 4 for the total failure

Enable Autostart of the VPS

First, you should make sure that your server is restarted after a failure or crash. Every VPS provider offers a corresponding setting in the administration area of the server. The picture below shows this setting at netcup.

netcup Autostart - Preparing for a Forex VPS Failure
Autostart of the VPS at netcup

Enable Autologin to Windows

Next, enable the Autologin for Windows users. This will automatically log in the user when Windows starts. The following method works on Windows Server 2008 R2 and newer.

Copy the following text into a text file. The text parts “Windows User” and “Pasword” must be adapted according to your login data (quotation marks must remain). Then save the file as “Windows Auto Login Enable.reg”. Now execute the registry file created in this way with administrator rights.

Windows Auto Login Enable.reg


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"DefaultUserName"="Windows User"
"DefaultPassword"="Password"
"AutoAdminLogon"="1"

To disable Autologin save the text below as “Disable auto login to Windows.reg” and execute it with administrator privileges.

Disable auto login to Windows.reg


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"AutoAdminLogon"="0"

Alternatively, the two ready-made registry files can also be used. In the login file, however, the “Windows User” and the corresponding “Pasword” must be adapted. For this purpose, the two files can be opened and edited with a text editor.

It should be noted that the password is stored unencrypted in the registry, so that any Windows user can see it. With the tool Autologon by Mark Russinovich the password can be entered encrypted. Follow the link for more information.

Disable Shutdown Event Tracker in Windows Server

The “Shutdown Event Tracker” from the Windows server should be turned off so as not to interfere with the user’s autologin. If the shutdown event tracker is enabled and the server shuts down or restarts unexpectedly (either due to a hardware failure or a power interruption), the first user to log in when the server restarts is prompted to enter a reason. Furthermore, the server cannot be shut down or restarted without specifying a reason.

The image below shows an example of a prompt when trying to shut down the server.

Shutdown Event Tracker - Preparing for a Forex VPS Failure
Shutdown Event Tracker

You can disable the Shutdown Event Tracker by following the steps below.

  1. In the start menu, type “gpedit.msc” and launch it.
  2. Go to: Computer Configuration > Administrative Templates > System > Display Shutdown Event Tracker
  3. Edit the policy and set to Disabled

Uptime monitoring of the VPS

To make sure that our VPS is online, we use UptimeRobot. With this online service a ping is sent to the VPS every few minutes. If the VPS does not respond, we are notified by email, SMS or push notification via the iOS or Android app and we can take care of the problem. The service of UptimeRobot can be used up to 50 monitors with 5-minute checks for free. Here’s how to set it up.

Preparing Windows Server

On your Windows server, you must first enable the feature that the VPS should respond to ping requests. On a Windows Server 2008 and newer you can enable this rule from the command prompt.Run as Administrator “cmd.exe”, type and then execute the following:

  • Enable Ping Replies: “netsh firewall set icmpsetting 8”
  • Disable Ping Replies: “netsh firewall set icmpsetting 8 disable”
Enable Ping Replies - Preparing for a Forex VPS Failure
Enable Ping Replies

Set up UptimeRobot

Open an account to use UptimeRobot at uptimerobot.com and go to “Add New Monitor”. Here you have to select “Ping”, then choose any “Name” for the VPS and enter the IP of the VPS, which is also used to login via Remote Desktop. The whole thing will look like this.

UptimeRobot Dashboard VPS Netcup 01 - Preparing for a Forex VPS Failure
UptimeRobot - Dashboard
UptimeRobot VPS Netcup 01 - Preparing for a Forex VPS Failure
UptimeRobot - Add New Monitor
UptimeRobot iOS VPS Netcup 01 - Preparing for a Forex VPS Failure
UptimeRobot - iOS

Reboot log

Sometimes it can be helpful to check when the server was last started. Start “cmd” with administrator rights and execute the following: “wmic os get lastbootuptime”. The time windows was last rebooted will be displayed.

lastbootuptime - Preparing for a Forex VPS Failure
Time windows was last rebooted

Preparing MetaTrader 4

This section is dedicated to the settings, for the preparation of MetaTrader terminals.

Auto Launch and Watch Function for MetaTrader 4 Terminals

To ensure that all desired MetaTrader 4 terminals are executed, we use the MT4BAR from Fx1.net. Even though further development was discontinued some time ago, this program still runs very stable. MT4BAR monitors all relevant MetaTrader terminals to see if they are running. If the VPS or Windows server is restarted or if one or more terminals crash, the terminals are restarted by MT4BAR. Additionally, you can be notified by email when a terminal is started, so you can check promptly if there is a need for action. Unfortunately, the email notification was poorly implemented or it is already outdated, we could only successfully integrate the outlook.com email service. With many other email providers it failed because of the security settings of the providers. In addition, this program is very well suited to manage all MetaTrader terminals, as they are displayed very clearly. Furthermore, MT4BAR includes an indicator, but it is not mandatory for the described functions.

After installing MT4BAR, a shortcut of this program should be added to the startup folder so that MT4BAR starts automatically with Windows. This is how you can open the folder:

Start > All Programs, then right-click on Startup and select “Open”.

The image below shows the Dashboard of MT4BAR as an example.

MT4BAR 02 1 - Preparing for a Forex VPS Failure
MT4BAR Dashboard

To use MT4BAR you should watch the short but very informative video.

Watchdog for the connection between MetaTrader 4 and the Forex broker

It may happen that MetaTrader loses connection to the broker’s server. This can be fatal, because then the Expert Advisor is no longer able to act and high losses can occur during trading, especially if you have not set a stop loss. See also Our Requirements on Expert Advisors. To ensure that there is always a connection to the broker and if the connection is lost it is restored, we use the Watchdog developed by us. The Watchdog is added to a chart like an Expert Advisor, then it continuously monitors the connection between MetaTrader 4 and the broker. If the connection is lost, it restores it, for this purpose the watchdog uses the broker account added to the favorites. Currently, the Watchdog is only available for MetaTrader 4 and must be set up as follows.

Add broker account to favorites

Use the Watchdog on EACH MetaTrader terminal you want to monitor. Add the desired broker account to the Favorites in MetaTrader, please add only one account to the Favorites. To do this, right-click on the account and select “Add to Favorites”.

MetaTrader Broker Account Add to Favorites 01 - Preparing for a Forex VPS Failure
Add a Broker Account to Favorites on MetaTrader 4
MetaTrader Broker Account Favorites 01 - Preparing for a Forex VPS Failure
Broker Account at the Favorites on MetaTrader 4

Uncheck “Disable automated trading when the account changes”

Furthermore, each terminal should be configured so that automated trading is NOT disabled when the account changes. To do this go to “Tools > Options > Expert Advisors” and uncheck the option “Disable automated trading when the account has been changed”.

MetaTrader Uncheck Disable automated trading when 01 - Preparing for a Forex VPS Failure
Uncheck the option “Disable automated trading when the account has been changed”

Download and start the watchdog

Download the Watchdog for MetaTrader 4.

Now the watchdog can be added to any chart. Make sure that the option “Allow DLL imports” is enabled. Furthermore you can enter the interval in seconds for the connection check under Inputs. With a click on “OK” you activate the watchdog.

MetaTrader Allow DLL imports 01 - Preparing for a Forex VPS Failure
MetaTrader 4 - Allow DLL imports
Watchdog started - Preparing for a Forex VPS Failure
Watchdog monitors the connection

Set the profile to be loaded at MetaTrader 4 startup (Important!)

Unfortunately, it can happen at any time that the MetaTrader 4 terminal crashes due to a program error. This happens rather rarely, but there is a certain probability, especially if an Expert Advisor causes an error, or if too many Expert Advisors are loaded. The next time the terminal is started (both after a crash and after a proper terminal exit), the profile that is entered in the “lastprofile.ini” file is loaded (by default, the profile with the name “Default” is entered). The MetaTrader terminal will replace the profile with the one that was last loaded after a proper terminal shutdown. When the terminal crashes, this file is not updated, so the next time the terminal is started, the profile that was last used by the user when the terminal crashed is not necessarily loaded. Therefore, one should deal with how to set the desired profile to be loaded both after a proper exit and after a terminal crash.

Set up default profile

When MetaTrader 4 terminal is started, the profile that is entered in the “lastprofile.ini” file, located in the “profiles” folder, is always loaded automatically. By default, the profile with the name “Default” is entered. The desired profile, which should be loaded at startup, should best be saved under this name (“Default”), this is the recommended procedure. However, if you want to save a profile, which should be loaded automatically at startup, under a name other than “Default”, you can enter the name of the desired profile in the file “lastprofile.ini” or manually close the terminal with the currently loaded profile, this will automatically enter the name of the last profile in the “lastprofile.ini” file (Note: this option only works if the terminal was closed properly by hand, it does not work if the terminal crashed, because the “lastprofile.ini” file is not changed when the terminal crashes).

Create a backup of the default profile

It is very worthwhile to create a backup of the profile for all MetaTrader terminals. You can do it as follows.

Create a backup of the profile:

  • File > Profiles > Save As
  • Enter a backup profile name (e. g. “Backup”) & click OK

After that you should load the default profile again.

Load the default or backup profile:

  • File > Profiles
  • Select your default or backup profile (e. g. “Backup”)
Traders Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

There will be moderation of all comments. Please also read our comment rules:

For open discussion, we reserve the right to delete any comment that is not directly on topic or has the sole purpose of disparaging readers or authors. We want people to communicate respectfully with each other, as if the discussion were with real people present. By submitting this form you agree to our Privacy Policy and the storage of your personal data.

Menu