mt5 expert-advisor deployment vps algorithmic-trading

MT5 Expert Advisor Deployment Guide: From Development to Production

person
FXVPS Team
Share

MT5 Expert Advisor Deployment Guide: From Development to Production

Getting an EA to pass a backtest is one problem. Getting it to run reliably, unattended, on a remote VPS — week after week, through broker disconnections, Windows updates, and unexpected reboots — is an entirely different one.

We have seen every way a deployment can fail. EAs that trade the wrong symbol suffix. Terminals that silently disable AutoTrading after an update. Strategies that run perfectly in the tester but never open a single trade in production because the account is netting when the EA expects hedging.

This guide is the checklist we wish someone had given us years ago. It covers every step from validating your strategy in the tester through to disaster recovery. Bookmark it. You will come back to it.


1. Pre-Deployment Checklist

Before your EA touches a live VPS, run through every item below. Skipping even one has cost traders real money.

Strategy Tester Validation

Run a final backtest on the exact symbol and timeframe you intend to trade live. Not “close enough” — exact. If your broker lists EURUSD.r and you tested on EURUSD, the results may differ due to spread, commission, and swap differences baked into the symbol specification.

  • Use “Every tick based on real ticks” mode for the final validation pass. “Open prices only” is fine for rapid iteration, but it hides slippage-sensitive logic bugs.
  • Confirm the modeling quality is above 99%. Anything less means gaps in tick data that could mask problems.
  • Run a forward test on a demo account for at least two weeks before deploying to a live VPS. This catches issues that backtests structurally cannot — requotes, partial fills, and trade server latency.

Parameter Verification

Export your EA’s input parameters from the tester using File > Save in the Inputs tab. This creates a .set file. You will use this exact file on the VPS to guarantee parameter parity. Do not retype parameters by hand. One wrong decimal place in a lot size multiplier and you have a position ten times larger than intended.

Magic Numbers

Every EA instance on every chart must have a unique magic number. If you run the same EA on three symbols, that is three distinct magic numbers. If you run two different EAs that both trade EURUSD, again, distinct magic numbers. Collisions cause EAs to close each other’s trades or miscalculate position sizing.

We recommend a convention: [strategy_id][symbol_id][instance]. For example, 10101 for Strategy 1, Symbol 01, Instance 01. Document your scheme somewhere outside the terminal.

Account Type Check

This one catches people constantly. Verify two things:

  1. Demo vs. Live — Confirm the account number and server name in MT5 match what you expect. It is disturbingly easy to connect to a demo server by accident.
  2. Hedge vs. Netting — Open File > Open an Account and check the account type. Hedge accounts allow multiple independent positions on the same symbol. Netting accounts aggregate into a single net position. An EA coded for hedging will behave unpredictably on a netting account — it may reverse positions instead of opening new ones, or fail to close individual trades.

2. VPS Setup for MT5

A trading VPS is not a web server and should not be configured like one. The goal is maximum stability and minimum interference with the terminal process.

Disable Windows Update Auto-Restart

Windows Update is the single largest cause of unexpected VPS reboots. On Windows Server:

  1. Open gpedit.msc (Group Policy Editor).
  2. Navigate to Computer Configuration > Administrative Templates > Windows Components > Windows Update.
  3. Set “Configure Automatic Updates” to Enabled, then select “2 - Notify for download and notify for install”.
  4. Set “No auto-restart with logged on users for scheduled automatic updates installations” to Enabled.

This lets you install updates on your own schedule — weekends when markets are closed.

Disable Windows Defender Real-Time Scanning

Defender’s real-time scanning adds latency to every file operation the terminal performs, including writing to log files and loading tick data. On a dedicated trading VPS, it is unnecessary overhead.

  1. Open Windows Security > Virus & threat protection > Manage settings.
  2. Turn off Real-time protection.
  3. For a permanent solution, open gpedit.msc and navigate to Computer Configuration > Administrative Templates > Windows Components > Microsoft Defender Antivirus and set “Turn off Microsoft Defender Antivirus” to Enabled.

If your security policy requires antivirus, at minimum add exclusion paths for the MT5 data directory and installation folder.

Visual Effects and Power Plan

Disable visual effects to free memory and CPU cycles:

  1. Open System Properties > Advanced > Performance Settings.
  2. Select “Adjust for best performance” to disable all visual effects.

Set the power plan to High Performance:

powershell -Command "powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"

This prevents the CPU from throttling during low-activity periods, which can introduce latency spikes on tick processing.

Firewall Rules

MT5 needs outbound TCP access to your broker’s trade server, typically on port 443 or a custom port listed in your broker’s server configuration. Outbound is generally allowed by default on Windows Server, but if you have tightened firewall rules, ensure terminal64.exe has an explicit allow rule:

netsh advfirewall firewall add rule name="MT5 Terminal" dir=out action=allow program="C:\Program Files\MetaTrader 5\terminal64.exe" enable=yes

3. Terminal Installation & Configuration

Portable Mode vs. Installed

We strongly recommend portable mode for VPS deployments. It keeps all configuration, data, and EA files inside the installation directory rather than scattering them across %APPDATA%. This makes backups trivial and allows running multiple independent terminal instances side by side.

To enable portable mode, create an empty file named portable (no extension) in the terminal’s root directory before the first launch:

cd "C:\MT5_Instance1"
type nul > portable

The terminal will store all data in C:\MT5_Instance1\MQL5\ instead of C:\Users\<user>\AppData\Roaming\MetaQuotes\Terminal\<hash>\.

Multi-Terminal Setup

To run multiple MT5 instances — for example, one per broker or one per strategy cluster — install each to a separate directory:

C:\MT5_Instance1\
C:\MT5_Instance2\
C:\MT5_Instance3\

Each must have its own portable file. Each runs as an independent process with its own configuration, login, and EA set. You can launch them simultaneously without conflict.

Reducing Memory Footprint

Every open chart consumes memory. On a VPS with 2-4 GB of RAM running multiple terminals, this matters.

  • Minimize charts: Only open the charts your EAs are attached to. Close everything else.
  • Disable news: Go to Tools > Options > Server and uncheck “Enable news”.
  • Limit history: Under Tools > Options > Charts, set “Max bars in chart” to 5000-10000. Your EA does not need 500,000 bars of M1 data loaded into memory at runtime.
  • Disable unused symbols: In the Market Watch window, right-click and select “Hide All”, then manually show only the symbols you trade. This reduces the volume of incoming tick data the terminal must process.

4. Auto-Login & Recovery

Your EA cannot trade if the terminal is not running. The VPS must be configured to recover from reboots without human intervention.

MT5 Auto-Login

In Tools > Options > Server, check “Keep personal settings and data at startup”. This stores your login credentials so the terminal reconnects automatically on launch. Without this, the terminal opens to a login dialog and sits there waiting — while your EA misses every trade.

Windows Auto-Logon

The terminal needs a Windows desktop session to run. Configure auto-logon so the VPS signs in automatically after a reboot:

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d "your_username" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d "your_password" /f

Replace your_username and your_password with the actual Windows credentials. Yes, the password is stored in plaintext in the registry. This is a dedicated trading VPS — if someone has registry access, you have bigger problems.

Scheduled Task for Terminal Startup

Create a scheduled task that launches each MT5 instance at logon:

  1. Open Task Scheduler (taskschd.msc).
  2. Create a new task (not a basic task — you need the full options).
  3. Set the trigger to “At log on” for your user.
  4. Set the action to Start a program: C:\MT5_Instance1\terminal64.exe
  5. Under Settings, check “Run task as soon as possible after a scheduled start is missed”.
  6. Optionally add a 10-second delay on the trigger to let the network stack initialize before the terminal tries to connect.

For added resilience, create a second scheduled task that runs every 5 minutes and checks if the terminal process is alive:

$process = Get-Process -Name terminal64 -ErrorAction SilentlyContinue
if (-not $process) {
    Start-Process "C:\MT5_Instance1\terminal64.exe"
}

Save this as C:\Scripts\watchdog.ps1 and point the scheduled task at it.


5. EA Installation & Activation

Copying EA Files

Place your compiled .ex5 file in the terminal’s MQL5\Experts\ directory. If your EA depends on include files (.mqh) or libraries (.ex5 in MQL5\Libraries\), copy those too. The exact paths in portable mode:

C:\MT5_Instance1\MQL5\Experts\MyEA.ex5
C:\MT5_Instance1\MQL5\Include\MyLibrary.mqh
C:\MT5_Instance1\MQL5\Libraries\MyDLL.ex5

After copying, right-click in the Navigator panel and select Refresh — or simply restart the terminal.

Loading Parameters

To load the .set file you exported during testing: drag the EA onto a chart, and in the Inputs tab click Load, then navigate to your .set file. This guarantees parameter parity with your tested configuration.

Enabling Algo Trading

Two switches must be on:

  1. Global switch: Click the “Algo Trading” button on the main toolbar (or press Ctrl+E). The button icon should appear green.
  2. Per-chart switch: In the EA’s properties dialog (right-click the chart > Expert Advisors > Properties), ensure “Allow Algo Trading” is checked.

If either switch is off, the EA loads but never sends orders. The smiley face in the chart’s top-right corner will appear grayed out instead of blue.

DLL Imports

Only enable “Allow DLL imports” if your EA explicitly requires it and you trust the source completely. A malicious DLL has full access to the Windows system — it can read files, make network requests, and install software. Legitimate use cases include EAs that interface with external data feeds or custom risk management systems. If you downloaded an EA from a marketplace and it asks for DLL permissions, treat that as a red flag until you can verify what the DLL does.


6. Monitoring & Alerts

Deploying an EA is not “set and forget.” You need eyes on it, even if those eyes are automated.

MT5 Built-In Notifications

Configure email and push notifications in Tools > Options > Notifications and Tools > Options > Email. Your EA can then call SendNotification() or SendMail() to alert you on trade events, errors, or custom conditions.

At minimum, set up alerts for:

  • Trade opened / closed
  • Connection lost to trade server
  • EA removed from chart (this happens silently after terminal updates)

External Monitoring

For monitoring that does not depend on MT5 itself being healthy, use a simple external script. The following PowerShell checks whether the terminal is running and whether it has an active network connection:

$proc = Get-Process -Name terminal64 -ErrorAction SilentlyContinue
if (-not $proc) {
    # Send alert — terminal is not running
    Send-MailMessage -To "[email protected]" -From "[email protected]" -Subject "MT5 DOWN" -SmtpServer "smtp.example.com"
}

$connections = Get-NetTCPConnection -OwningProcess $proc.Id -State Established -ErrorAction SilentlyContinue
if (-not $connections) {
    # Terminal is running but has no active connections — likely disconnected from broker
}

Trade Context Busy

When MT5 returns “trade context busy,” it means another operation (another EA or a manual trade) is currently using the trade execution pipeline. Well-written EAs handle this with a retry loop and a short Sleep(). If you see this error frequently, you are likely running too many EAs on a single terminal that trade the same symbols simultaneously. Spread them across multiple terminal instances.


7. Backup & Disaster Recovery

What to Back Up

At minimum, back up these paths from each terminal instance:

  • MQL5\Experts\ — your EA files
  • MQL5\Presets\ — saved parameter sets
  • MQL5\Files\ — any data files your EA reads or writes
  • config\ — terminal configuration including server list and chart templates
  • profiles\ — chart layout and EA assignments
  • Bases\ — account-specific trade history and settings

A nightly robocopy to a second drive or network location works:

robocopy "C:\MT5_Instance1" "D:\Backups\MT5_Instance1" /MIR /XD logs /XF *.log

Handling VPS Reboots

If you have followed Section 4 (auto-logon, scheduled tasks, and MT5 auto-login), the terminal should recover automatically after a reboot. However, verify that your EAs are actually attached to charts and trading after recovery. Some updates reset chart profiles. A post-reboot verification script that checks the MQL5\Logs\ directory for recent EA initialization messages gives you confidence without needing to RDP in manually.

Migrating Between VPS Instances

To move to a new VPS:

  1. Copy the entire portable MT5 directory to the new server.
  2. Verify the portable file is present.
  3. Launch the terminal — it should connect with the stored credentials.
  4. Confirm EAs are attached and AutoTrading is enabled.
  5. Run both old and new VPS in parallel for 24 hours, with the old instance’s EAs set to read-only (disable trading in each EA’s properties), to verify the new instance is trading correctly before decommissioning the old one.

8. Common Deployment Failures

These are the problems we see most often. When something goes wrong, start here.

”EA not loaded” or EA Missing from Chart

  • The .ex5 file is not in MQL5\Experts\. Double-check the path — in portable mode it is relative to the terminal directory, not %APPDATA%.
  • The EA was compiled for a different MT5 build version. Recompile it with the MetaEditor that matches the terminal version on the VPS.
  • The EA requires .mqh include files or library dependencies that are not present. Check the Experts tab in the terminal’s toolbox for specific error messages.

Chart Symbol Mismatch

Your EA expects EURUSD but the broker lists it as EURUSD.r, EURUSDm, or EURUSD.ecn. The EA attaches to the chart but cannot find its symbol to trade. Either configure the symbol as an input parameter in your EA, or ensure you open the exact chart symbol the EA was designed for. This is the single most common “EA runs but never trades” issue.

Insufficient Margin

The EA attempts to open a position larger than the account can support. This often happens when moving from a demo with $100,000 balance to a live account with $5,000, without adjusting lot sizes or risk parameters. Always recalculate position sizing relative to the live account balance. If your EA uses fixed lots instead of risk-based sizing, this is where it will bite you.

Trade Context Busy

As discussed in Section 6, this means the trade pipeline is occupied. If it happens on every trade attempt, ensure you are not running multiple EAs that trade on the same OnTick() event without proper queuing. The fix is either retry logic in the EA code, or splitting EAs across separate terminal instances.

AutoTrading Disabled After Update

MT5 terminal updates can reset the global AutoTrading flag to off. After any update — and updates happen automatically unless you disable them — RDP into the VPS and verify the Algo Trading button is green. To disable automatic updates, add this to your terminal’s terminal64.ini (in the config directory):

[Common]
NewsEnable=0
[StartUp]
AutoUpdate=0

Note that MetaQuotes does not officially support disabling updates, and some broker builds may override this setting. Check after every update.

EA Works in Tester but Not Live

Beyond the symbol mismatch and account type issues already covered, check for these:

  • Tick mode dependency: The EA only triggers logic on new ticks. If the market is closed (weekends, holidays), it will do nothing. This is normal, but surprises traders who deploy on a Friday night and panic by Saturday morning.
  • Time zone differences: The VPS system clock, the broker server time, and UTC are likely three different times. If your EA uses time-based logic (session filters, news avoidance), ensure it references the broker’s server time via TimeCurrent(), not the local system clock via TimeLocal().
  • Spread filter too tight: Live spreads are wider than the fixed spreads used in most backtests. If your EA has a maximum spread filter, it may never find a spread narrow enough to trade during volatile sessions.

Final Thought

A properly deployed EA on a well-configured VPS is one of the most reliable ways to execute a trading strategy. But “properly deployed” is doing a lot of heavy lifting in that sentence. Every item in this guide exists because we have seen the failure it prevents. Take the time to get the foundation right. The market will be there tomorrow — your edge will not survive sloppy infrastructure.

If you are running your EAs on an FXVPS server and need help with any of these steps, contact our support team. We configure trading VPS instances every day, and we are happy to walk you through it.