hft

Expert Advisor guide for MT4/MT5: Build, Test, Deploy

MF
Marco Ferraro· Head of Quantitative Research
Published ·Last reviewed ·9 min read

Practical Expert Advisor guide for MT4/MT5 traders: learn types, red flags, tick-level testing, VPS needs, and safe live steps to deploy robots.

Expert Advisor guide for MT4/MT5: Build, Test, Deploy

Definition:

Expert Advisor (EA) is an automated trading program for MetaTrader 4 or MetaTrader 5 that executes orders based on rules without human intervention; EAs can run 24/5 when hosted on a VPS and have been used in retail forex since at least 2005.

Key Takeaways

- Use tick-level backtests and 2–3 months forward demo testing before live deployment.

- Watch for unrealistic backtests, hidden drawdown, and martingale without discipline.

- Host EAs on a low-latency VPS and pair with a fast broker for reliable execution.

- Start live with micro-lots, fixed risk per trade, and continuous monitoring.

What is an Expert Advisor (EA) and how does it work?

An EA is an automated trading robot that places, manages, and closes trades according to programmed rules. It reads market data (ticks or bars) inside MetaTrader 4 or MetaTrader 5, applies indicators and order logic, and sends execution requests to the broker. EAs can be simple (moving average crossover) or complex (tick-level HFT strategies) and operate 24 hours per weekday when hosted on a reliable server.

EAs use the platform API: MQL4 for MT4 and MQL5 for MT5. MQL5 supports native multi-threading and access to market depth, which matters for advanced strategies. Institutional-style EAs often rely on tick data for backtests rather than 1-minute bars to capture slippage and spread variation.

Methodology note: conclusions in this article are derived from hands-on strategy testing (tick-level backtests), live demo forward performance, and industry best practices as outlined by regulators such as the Financial Conduct Authority (FCA). A limitation: retail broker execution differs from institutional FIX venues, so live results may vary from simulated ones.

What types of EAs exist and which suit my goal?

There are several EA archetypes; pick the one that matches your risk tolerance and market view. Trend-following EAs attempt to capture large moves using breakouts or moving-average systems. Grid EAs place buy and sell orders spaced by price levels to capture oscillations. Martingale EAs increase lot size after losses to recover — they magnify both recovery and ruin risk. High-frequency trading (HFT) EAs exploit micro-structure and need colocation or ultra-low-latency links. News-based EAs enter around scheduled economic releases.

Each type has operational and risk requirements. Trend EAs need sensible stop/exit rules to avoid large drawdowns. Grid and martingale require drawdown ceilings and account-sizing rules. HFT requires a VPS or colocated server with <5 ms latency to the broker's execution server. News EAs must handle spreads and slippage spikes.

Practical tradeoff: simple trend EAs often survive longer in changing markets; martingale can produce attractive simulated returns but high real-world blow-up risk. The Bank for International Settlements (BIS) has noted that high-frequency strategies materially affect liquidity during stress periods, a consideration for HFT-style EAs.

What red flags should traders watch for when evaluating EAs?

Red flag one: unrealistic backtests that show extremely high returns, 90%+ win rates, and no drawdown. These tests often use tick data gaps, curve-fitting, or omitted commissions. Red flag two: martingale logic presented without explicit maximum drawdown or stop-loss rules. Red flag three: no forward demo test or no live track record at all. Red flag four: opaque execution model — if the vendor will not disclose average slippage, spread assumptions, or broker type, treat results skeptically.

Concrete example of a red flag: a vendor claims a 200% annual return on EURUSD with 0.0 spread and zero slippage. Realistic testing should include spreads (for example 0.6 pips average on EURUSD) and commission (e.g., 3 per side per standard lot). Demand tick-level backtests and at least 2 months of forward demo trading.

Regulatory note: retail traders should consider guidance from consumer protection agencies such as the FCA when assessing performance claims. Always ask for verifiable, timestamped trade logs and independent proof of live performance.

How to test an EA properly (backtest, forward test, live start)

Answer: test EAs using tick-level backtests, followed by 2–3 months forward demo testing, then phased live deployment with micro-lots.

Step 1 — Backtest in Strategy Tester: use tick data and realistic spread/commission. In MT4/MT5 Strategy Tester, enable 'Use Date' and 'Every Tick' for accuracy. Validate by comparing equity curves at different timeframes and performing walk-forward optimization rather than curve-fitting single-parameter best fits.

Step 2 — Forward demo test: run the EA on a demo account for 2–3 months or 500+ trades if the strategy is high-frequency. Monitor real fills, slippage, spread widenings around news, and order rejection rates.

Step 3 — Live start: begin with minimum position size (micro-lots) and fixed risk per trade. Scale only after demonstrated positive expectancy and acceptable drawdown. Keep a trade log and reconcile reported results with broker statements — publish results to an independent tracker if you want external verification.

See our detailed articles on backtesting-methods and expert-advisors for test checklists and sample reports.

Required infrastructure: VPS, broker selection, data, and uptime

Answer: reliable infrastructure requires a 24/5 VPS with low latency, a broker with fast execution, and stable data feeds.

VPS: choose a provider offering Windows VPS with 99.9% uptime, automated restart, and latency <10 ms to your broker's server if possible. Many traders use VPS locations in London, New York, or Frankfurt depending on their instrument's liquidity. For HFT-style strategies, latency targets are typically <5 ms.

Broker: pick a broker with consistent spreads, low latency, and transparent execution. A low-latency broker like VT Markets can be suitable for retail EAs because of competitive spreads and execution; verify their server locations and typical slippage on the instruments you trade. If you intend to trade XAUUSD or cross-asset strategies, ensure the broker offers the necessary liquidity and margin model.

Data: store tick-level data for at least 2 years for backtesting; maintain daily backups. For MT5, market depth and faster testing help for advanced strategies. Trade reconciliation and periodic replays of tick data are part of professional maintenance.

Monitoring, maintenance, and operational risk management

Answer: continuous monitoring and proactive maintenance prevent losses from software errors or market shifts.

Automated alerts: set email/SMS alerts for system offline, margin calls, large drawdowns, or unexpected high slippage. Use a heartbeat script to confirm the EA is attached and trading as intended. Check logs daily for rejections or repeated errors.

Version control and change management: track EA versions and maintain a rollback plan. When you update logic, perform A/B testing on demo accounts before switching live. Regularly re-run backtests on updated tick data; a change in market micro-structure (wider spreads, lower liquidity) can invalidate parameters.

Risk controls: enforce a hard daily loss limit, equity stop, and per-trade risk cap. If an EA triggers the equity stop, remove it from live trading and perform forensic analysis before re-enabling.

How Vortex HFT meets institutional EA standards for XAUUSD strategies

Answer: Vortex HFT is designed to meet institutional standards by using tick-level data, strict risk controls, and low-latency execution for automated XAUUSD trading.

Vortex HFT employs direct market access techniques and tick-level testing, supports colocated or VPS deployment, and uses maximum drawdown ceilings per day and per week. Backtests use realistic spreads and commissions and are audited against live reconciliation records — see our published strategy snapshots on performance. Detailed execution logs and fixed risk-per-trade parameters align Vortex with institutional operational controls.

Limitations: even institutional-grade EAs can underperform during regime changes, central bank interventions, or extreme market dislocations (for example, fast moves in XAUUSD on a surprise interest rate decision). We recommend pairing Vortex deployments with broker execution monitoring and, where available, low-latency links such as a nearby VPS.

For more on deployment specifics and system architecture, see vps-setup and our Vortex overview: https://fazencapital.com/vortex.

Concrete examples and worked calculations

Example 1 — Position sizing using fixed-risk per trade (EURUSD):

Account balance: 10,000

Risk per trade: 1% of equity = 100

Stop-loss: 50 pips

Pip value for 1 standard lot (100,000) on EURUSD ≈ 10.00 per pip.

Step-by-step calculation:

1) Dollar risk = 10,000 × 1% = 100.

2) Dollar risk per pip if trading 1 standard lot = 50 pips × 10/pip = 500.

3) Position size (lots) = Dollar risk / (Stop-loss pips × per pip per lot)

Position size = 100 / (50 × 10) = 100 / $500 = 0.2 lots.

So open 0.20 standard lots (equivalent to two mini lots or 2 × 0.1 lots).

Example 2 — Backtest realism: vendor claims 150% annual return with 2% max drawdown on EURUSD from 2015–2020. Red flag: verify using tick data with spreads averaged over that period (for example average EURUSD spread 0.6 pips in 2019) and include commissions to validate the equity curve.

What this means for traders

If you use EAs, treat them as systems requiring DevOps and risk management rather than set-and-forget tools. Always start with tick-level backtests, then a 2–3 month demo forward test. Use a VPS with low latency and choose a broker with good execution for your instrument set; VT Markets is an example of a retail broker offering competitive spreads and execution profiles to consider. Start live with micro-lots, hard-enforced risk rules, and continuous monitoring. Expect occasional underperformance; be prepared to pause and re-test when markets change.

FAQ

How long should I forward-test an EA before going live?

Forward-test on a demo account for at least 2–3 months or until you have 500+ trades for high-frequency strategies. Monitor slippage, spread widening during news, and order rejection rates. If the EA's key performance metrics (win rate, expectancy, drawdown) materially differ from backtests, do not go live until you diagnose the cause and retest.

Can I run the same EA on MT4 and MT5 without changes?

No. MT4 uses MQL4 and MT5 uses MQL5; code and execution differences matter. MT5 supports multi-threading and market depth that can change order handling. Porting often requires rewriting logic for order handling, symbol conventions, and event processing, and retesting fully on the destination platform.

Are grid and martingale EAs inherently dangerous?

They carry amplified risk. Grid and martingale can show strong short-term returns but can produce large, rapid drawdowns. If used, require strict equity limits, maximum cumulative drawdown stops, and small position-sizing relative to account equity. Always simulate prolonged adverse trends to test survivability.

How do I verify an EA vendor’s live performance claims?

Request broker statements or public trade history from third-party trackers. Reconcile trade logs with broker reports and verify timestamped fills. Independent verification reduces the risk of fabricated or cherry-picked results. If verification is refused, treat claims with skepticism.

Conclusion

Expert Advisors can automate disciplined trading when tested and managed like software systems: tick-level backtests, forward demo validation, low-latency infrastructure, and strict risk controls. Start small, monitor continuously, and demand verifiable performance before scaling.

Disclaimer: This article is for informational purposes only and does not constitute investment advice. CFD trading carries high risk of capital loss.

Want to automate this strategy? Get AiX Breakout free — our Expert Advisor trades XAUUSD on MT4.

Get Free

AiX Breakout runs on our regulated broker partner. Tight spreads, fast execution, MT4 & MT5.

Open Account