Overview — Why Automate?
Automation removes emotional bias, enforces risk rules, and enables 24/5 execution. However, it introduces engineering risk (data quality, slippage, downtime). Treat algotrading as a software + research project.
Platforms & Languages
- MT4 / MQL4: Forex‑focused, massive ecosystem of indicators/EAs; single‑threaded tester.
- MT5 / MQL5: Multi‑asset, multi‑threaded strategy tester, more advanced language features.
- Bridges/APIs: Some brokers offer FIX/REST/WebSocket APIs; require custom infrastructure.
Strategy Design — From Idea to Spec
- Hypothesis: e.g., “Trend pullbacks to 20–50 EMA during London open have positive expectancy.”
- Signals: define entry/exit precisely (indicators, candle patterns, time filters).
- Risk: position sizing (fixed fractional or ATR‑based), max daily loss, max open risk, news filters.
- State machine: draft a flow: Flat → Setup → Armed → In‑Trade → Manage → Exit.
- Spec doc: write I/O, parameters, and invariants (e.g., never add to losers).
Data Quality — The Hidden Edge
- Tick vs 1‑min: MT5 “Every tick based on real ticks” gives highest fidelity; 1‑min synthesis can misestimate slippage and stops.
- Spread/commission: Use broker‑specific values; model variable spreads during news.
- Timezones & DST: Normalize timestamps; session logic must handle DST shifts.
Backtesting — Do the Math Right
- Select representative symbols/timeframes and ≥ 5–10 years of data where possible.
- Model commission, swap, and realistic slippage.
- Use walk‑forward splits: in‑sample (optimize) → out‑of‑sample (validate).
- Run Monte Carlo resampling on trade sequences and slippage to estimate drawdown risk.
Optimization — Avoid Curve‑Fitting
- Limit parameters; prefer robust ranges over single magic numbers.
- Use walk‑forward optimization (WFO) with rolling windows; compare stability across windows.
- Apply out‑of‑sample and forward demo before live.
Risk Management for EAs
- Risk per trade ≤ 0.5–1.0% (reduce for high‑freq systems).
- Daily max loss (e.g., 2–3R) and equity‑based circuit breaker (disable EA after threshold).
- Cap simultaneous exposure by symbol and by currency (USD, EUR, JPY buckets).
- Implement hard stops server‑side if possible; client‑side trails with fail‑safes.
Execution, Slippage & Latency
- Prefer ECN/STP brokers with tight spreads and transparent commissions.
- Use VPS near broker servers (ping < 5–10 ms) for stability.
- Throttle order frequency; respect broker min distance, min lot, and freeze levels.
- Handle requotes/rejections gracefully with retry/backoff logic.
Deployment — From IDE to VPS
- Compile and version (Git) your EA; tag stable releases.
- Prepare config files for parameters per symbol/timeframe.
- Run on a VPS with auto‑restart, platform autologin, and Windows Update paused.
- Set alerts (email/Telegram) for fills, errors, slippage spikes, and equity thresholds.
Monitoring & Logging
- Log all orders: timestamp, price, spread, slippage, ticket, error codes.
- Daily health check: open trades, equity, margin, VPS uptime, ping.
- Weekly KPI review: expectancy, drawdown, win rate, average R, by symbol/timeframe.
Compliance & Broker Rules
- Check broker terms: scalping, news trading, latency arbitrage restrictions.
- Prop firm rules: daily loss, max drawdown, lot limits, consistency rules; ensure EA enforces them.
- Data privacy and API keys: store securely, rotate periodically.
Worked Examples — From Spec to Numbers
Example 1 — Position size by risk Account $20,000; risk 0.5% → $100 Stop = 25 pips; pip value (1 lot) ≈ $10 → $250 per lot Lots = $100 / $250 = 0.40 lots
Example 2 — Equity circuit breaker Daily start equity: $20,000; max daily loss 2R; 1R = $100 → 2R = $200 If equity ≤ $19,800 then: disable EA, close opens, send alert
Example 3 — Walk‑forward plan 2018–2021: optimize; 2022: out‑of‑sample; 2023: forward demo (6 months); 2024: small live Only promote to live if each phase expectancy ≥ 0.15R and max DD ≤ 8%
FAQ
- Q: Should I use martingale or grids?
- A: We advise against unlimited martingale/grid logic due to tail‑risk blowups. If used, cap attempts, size, and time in market strictly.
- Q: MT4 or MT5?
- A: MT5 offers superior tester and multi‑asset support. Use MT4 only if required by your broker or legacy tools.
- Q: How do I handle news?
- A: Include a calendar filter to pause entries X minutes around high‑impact events; widen stops or skip entirely based on strategy.
Next Steps
Create a one‑page spec for your first EA, define parameters and invariants, gather quality tick data, and run a disciplined backtest → WFO → demo → small live sequence. Build monitoring and circuit breakers before increasing size.
Back to Course Home


Leave A Comment