Home PythonDLL Agents MQL5Doc JavaDoc GitHub Русский

MetaTrader 5 Agents & AWS EC2

Using MetaTrader 5 (MT5) Agents on Amazon servers VPS/VDS. This is an excellent option for checking the trading strategy for the currency and stock markets Forex, CFD and Futures.

MetaTrader 4 (MT4) does not have Test Agents.

The difference from the use of the Agents cloud:

Agents are run with the flag “/local” as with local use.

The cost of using Amazon servers can be much more economical than using the Cloud of Agents. Calculation of the cost of the Cloud occurs by a mysterious formula, so it is very difficult to estimate the cost of full optimization.

What is the profit?

Prices for spot-instances are available here. But after registration, the table is available that can be obtained by creating a spot-instance (blue “Request Spot Instances” button) and clicking on the gray “Change instance type” button.
Spot Prices

There is a special instance:
cc2.8xlarge CPUs 32 Memory 60.5GiB SSD 4 x 840 GB
The price ranges from $0.20 to $0.30 per hour, which corresponds to instances with 16 CPUs. This instance has an out-of-date status and can periodically disappear from the list of available instances. It makes sense to view all 4 US regions for its availability before ordering the instance.

The cc2.8xlarge is ideal for Agents.

Initialization

It makes sense in four US regions to create a rule for Security Groups.
Security Groups
N. Virginia, Ohio, N. California, Oregon
You need to open ports for access from outside. Since the server will exist for a limited time and will not be used for public purposes. You can not bother with the choice of ports and open them all, although this is contrary to security rules.
Security Groups AllPorts

You need to create a Role with access rights to the bucket S3.

  1. Go to the Role Management section and click on the blue “Create role” button.
  2. Select the EC2 service and click on the blue “Next” button.
    ubuntu
  3. The script for launching Agents only downloads files from the S3 bucket, so just select “AmazonS3ReadOnlyAccess” and click on the blue “Next” button.
    ubuntu
  4. Now you need to set the Role name and click on the blue “Create role” button.
    ubuntu

You can create access keys for using programs to upload files to the S3 bucket. These keys also allow you to receive spot prices from all regions in AmazonUtils. Forgotten access keys in a source code can cause trouble (RU).

Uploading files to S3

  1. First you need to create an S3 bucket with the default settings.
  2. Create a folder “MetaQuotes”.
    AWS S3 root
  3. Download the file “c:\Program Files\MetaTrader 5\metatester64.exe” to the folder “MetaQuotes”.
    AWS S3 MetaQuotes
  4. Download the necessary files from the folder “c:\Users\USER\AppData\Roaming\MetaQuotes\Terminal\Common\Files" to “MetaQuotes/Terminal/Common/Files/”.

The download should be done for each region in which the Agents are scheduled to be launched.

Request server for Agents

In the Spot Requests click on the blue “Request Spot Instances” button.

A new request design will appear, in which all the settings are hidden under “Additional configurations”. You can switch to the old design at the very bottom of the page by “Previous version of Request Spot Instances”.

In the new design, select “Defined duration workloads”.
Defined duration workloads

The script I created for running Agents is designed for Ubuntu.
Ubuntu

I usually choose cc2.8xlarge with a built-in SSD on 840GB. It is often a great discount, because this instance of the previous generation, but for Agents it is great.
Instance Type

If the instance has built-in disk space, then the number of gigabytes for EBS can be set at a minimum (paid separately).
EBS
All Agents are run in “/mnt”. The first partition of the built-in disk is automatically mounted in this folder. If the size of the first partition is not enough, then you need to take an instance only with EBS or edit the script. Add a second partition does not make sense, because it will be the last.
lsblk

Set the rule for opening ports in “Security groups”.
Security groups

If you use a pre-created role in the “IAM instance profile”, then the script does not need to specify the key to Amazon.
IAM instance profile

Open the aws_ubuntu_user_data.sh and paste the contents into “User data”.
User data

After clicking on the blue button “Launch” a request to create an instance.

Instance can be issued by Amazon with a delay, so you need to update the page until it appears in the “Instances” list.
Instance

After that, you can go to the instance page and click on the gray “Connect” button to get the IP.
IP

Adding Agents to MetaTrader 5

Now you can add Agents to the list for optimization in MetaTrader 5 (MT5).
MT5 Add
MT5 Add 2

The script needs time (approximately 5 minutes) to run Agents in Ubuntu.
MT5 Agents

On all questions to address in this topic.