Deploy and Maintain Your EA — From Code to Live Trading Safely
You've built your EA, added risk management and filters. Now you need to deploy it correctly and maintain it so it trades reliably. According to the MetaTrader 5 Strategy Tester documentation, you must test on historical data before live trading — the tester lets you run backtests in minutes instead of weeks. This guide walks you through compile → backtest → Demo → Live, plus VPS setup, logging, debugging, and ongoing maintenance — no guesswork.
Why Deploy & Maintain Properly
What goes wrong if you skip steps? Many traders deploy an EA straight to Live without proper backtesting or Demo validation. Result: bugs surface in real money, parameters are over-fitted to past data, or the EA stops when the PC goes to sleep. A structured process — compile → backtest → Demo → Live — reduces risk and catches issues early.
What we'll cover:
| Topic | Purpose |
|---|---|
| Compile and verify | Fix errors before testing; ensure .ex5 is built |
| Backtest thoroughly | Test on historical data; choose tick mode, date range |
| Deploy to Demo first | Validate on real ticks before Live; no real money risk |
| VPS setup | Run EA 24/5 near broker; no PC dependency |
| Logging and debugging | Track EA behavior; diagnose OrderSend failures |
| Go Live checklist | Final checks before switching to real account |
| Ongoing maintenance | Monitor performance; update parameters; check logs |
Step 1: Compile and Verify
What is this? Compilation turns your .mq5 source into an .ex5 executable. MetaTrader 5 runs .ex5 files — if you have compile errors, no .ex5 is created and the EA won't appear in the Navigator.
Why it matters: Typos, missing semicolons, wrong types, or undefined variables cause compile errors. Fix them in MetaEditor before testing.
How it works: Open your EA in MetaEditor, press F7 (or Compile). Check the Toolbox — Errors tab. Zero errors means success; the .ex5 file is created in the same folder as the .mq5. Warnings don't block compilation but may indicate logic issues — fix them when possible.
Checklist:
- 0 errors in Toolbox
- .ex5 file exists in MQL5\Experts (or subfolder)
- Right-click Navigator — Refresh to see the EA in MetaTrader 5
Step 2: Backtest Thoroughly
What is this? Backtesting runs your EA on historical data — the Strategy Tester simulates ticks or bars and the EA places virtual trades. You get a report: profit, drawdown, number of trades, etc. Per MetaTrader 5 Strategy Tester, the tester uses accumulated quotes and performs virtual transactions according to your algorithm.
Why it matters: Backtesting shows how the EA would have performed in the past. It doesn't guarantee future results, but it helps find bugs (e.g. no trades, wrong lot, logic errors) and evaluate robustness.
Testing modes (from official docs):
- Every tick — Most accurate, slowest. Best for scalping or tick-sensitive logic.
- 1 minute OHLC — Good balance of speed and accuracy. Recommended for most EAs.
- Open prices only — Fastest, least accurate. Rough estimation only.
Steps:
- Open View — Strategy Tester (Ctrl+R)
- Select your EA, symbol, timeframe, date range
- Set Deposit (e.g. 10000), Leverage (e.g. 1:100)
- Choose 1 minute OHLC or Every tick depending on your strategy
- Click Start
- Review Results, Graph, Journal tabs after completion
Forward testing: Use the built-in forward testing option to split data — optimize on the first part, validate on the second. This reduces over-fitting.
Step 3: Deploy to Demo First
What is this? Before Live, run your EA on a Demo account — real market data, real broker execution, but virtual money. This catches issues that backtesting might miss (e.g. requotes, slippage, broker-specific behavior).
Why it matters: Demo uses the same server as Live (often). If the EA works on Demo, it's more likely to work on Live. Run for at least a few days (or weeks) to observe behavior across different market conditions.
How it works:
- Open a Demo account (File — Open an Account — Demo)
- Open a chart (e.g. EURUSD H1)
- Drag your EA from Navigator onto the chart
- Configure inputs, click OK
- Enable AutoTrading (Ctrl+E) — toolbar button must be green
- Check Tools — Options — Expert Advisors: "Allow Algo Trading" must be checked
- In EA Properties — Common tab: check "Allow live trading" (required for Demo too)
- Monitor the Experts tab for messages and errors
Step 4: VPS Setup
What is this? A VPS (Virtual Private Server) is a remote computer that runs 24/7. You install MetaTrader 5 on it, attach your EA, and it runs even when your home PC is off. Many brokers offer a free VPS if you meet minimum deposit or volume.
Why it matters: EAs need continuous execution. Power cuts, internet outages, or PC sleep will stop the EA — you miss trades or can't close positions. A VPS near the broker also reduces latency.
How it works:
- Request VPS from your broker (or use a third-party VPS provider)
- Connect via Remote Desktop (RDP) to the VPS
- Install MetaTrader 5 and your EA
- Log in with your Live (or Demo) account
- Attach EA to chart, enable AutoTrading
- Disconnect — the EA keeps running on the VPS
Tip: Choose a VPS in the same region as your broker's server (e.g. London for UK brokers) for lowest latency. For a full guide, see VPS for Expert Advisors.
Step 5: Logging and Debugging
What is this? Logging means writing messages from your EA to the Experts tab and log files. Print() writes to the Experts log; Comment() displays text on the chart. Use them to track variable values, entry/exit reasons, and errors.
Why it matters: When the EA doesn't trade or behaves unexpectedly, logs help you find the cause. After OrderSend, check GetLastError() to see the trade server return code (e.g. 134 Not enough money, 130 Invalid stops).
How it works:
// Log key values
Print("Signal: Buy. Price=", SymbolInfoDouble(_Symbol, SYMBOL_ASK), " Lot=", lot);
// After OrderSend
if(!OrderSend(req, res))
Print("OrderSend failed: ", GetLastError(), " ", res.comment);
// Display on chart (useful for debugging)
Comment("Positions: ", countMyPositions(), " | Last error: ", GetLastError());
Note: Print() does not work during Strategy Tester optimization. It works in single run and live/Demo.
Step 6: Go Live Checklist
What is this? Before switching to a Live account, run through a final checklist to avoid common mistakes.
Checklist:
- EA backtested and Demo-tested for at least a few days
- Risk settings (lot, SL, TP) appropriate for Live account size
- AutoTrading enabled (Ctrl+E)
- Allow Algo Trading checked in Options
- EA Properties — Allow live trading checked
- VPS running (if using) and EA attached
- Symbol in Market Watch; sufficient margin
- Experts tab monitored for errors
Step 7: Ongoing Maintenance
What is this? Once Live, you should monitor the EA regularly: check the Experts tab, review open positions, and review periodic performance. Update parameters if market regime changes; fix bugs if errors appear.
Why it matters: Markets change. Parameters that worked last month may underperform now. Logs can reveal broker issues (e.g. frequent requotes) or EA bugs.
Practices:
- Check Experts tab daily (or use email/SMS alerts for critical errors)
- Review weekly: profit, drawdown, number of trades
- Re-optimize or adjust parameters periodically (e.g. quarterly) if performance degrades
- Keep a backup of working .mq5 and .set files
Summary
You learned: compile and verify (F7, 0 errors), backtest (Strategy Tester, tick modes, forward testing), deploy to Demo first, VPS setup for 24/5 operation, logging and debugging (Print, Comment, GetLastError), Go Live checklist, and ongoing maintenance. Follow this flow — compile → backtest → Demo → Live — and your EA deployment will be safer and more reliable.
Bonus Tip: Want to skip the compile-and-deploy steps? Try AlfaTactix Strategy Builder free — design your EA visually, export production-ready MQL5, then deploy to MetaTrader 5. Backtest-ready code in minutes. Same deployment flow, faster start.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| EA not in Navigator | Compile errors, or file not in MQL5\Experts | Fix errors in MetaEditor (F7), save in Experts folder, refresh Navigator. |
| No trades in backtest | Wrong symbol, date range, or EA logic | Ensure symbol in Market Watch, history downloaded, check Journal for messages. |
| "Trade not allowed" (64) | AutoTrading off, or Allow Algo Trading unchecked | Enable AutoTrading (Ctrl+E), Options — Expert Advisors — Allow Algo Trading. |
| "Not enough money" (134) | Lot too large for deposit | Reduce lot size or increase deposit in Strategy Tester / Live account. |
| EA stops when PC sleeps | EA runs on local PC | Use VPS — EA runs on remote server 24/7. |
| Print() shows nothing | Running optimization | Print() doesn't work during optimization; use single run or Live. |
See MQL5 Trade Return Codes for all error codes.