Course Overview
Algorithmic trading means letting a computer execute your strategy for you — systematically, without emotion, 24 hours a day. It sounds like the answer to every trader's psychological struggles. In many ways, it is. In other ways, it introduces an entirely new set of challenges that discretionary traders never face.
This course teaches you to design, test, and deploy automated trading strategies using Expert Advisors (EAs) on MT4 and MT5 — the platforms available through virtually every retail forex broker. No programming background is required to understand the concepts; basic MQL4/MQL5 exposure is helpful but not a prerequisite.
More importantly, this course teaches you what most algo trading resources skip entirely: how to know if your backtest results are real or illusory. The graveyard of retail algo traders is littered with brilliant-looking backtests that failed catastrophically in live trading. You'll learn exactly why that happens and how to avoid it.
Prerequisites: Technical Analysis Masterclass + Risk & Money Management (both required). This is an advanced course.
Lessons
Lesson 1 — What Is Algorithmic Trading?
25 min · Foundation
Algorithmic trading means executing trades automatically based on pre-programmed rules, without human intervention in the execution process. The rules govern: entry conditions, exit conditions, position size, and risk management parameters.
Three categories of algorithmic trading:
High-Frequency Trading (HFT): Institutional-only. Requires co-location at exchange data centers, latency measured in microseconds, and capital in the tens of millions. Not accessible to retail traders.
Systematic/Quantitative Trading: Rules-based strategies executed automatically, typically holding positions from minutes to weeks. This is what retail algo traders do. Accessible via MT4/MT5 Expert Advisors.
Semi-Automated Trading: Computer generates signals or alerts, human decides whether to execute. Useful for traders who want assistance without full automation.
The genuine advantages of algorithmic trading:
- No emotional interference in execution — rules are followed 100% of the time
- Backtesting allows strategy validation before risking real capital
- Can monitor markets 24/5 without trader presence
- Eliminates hesitation — entries and exits are instant
- Can run multiple strategies simultaneously
The genuine limitations:
- Strategies can fail to perform live even with strong backtests (overfitting)
- Technical failures (internet, VPS, broker issues) require monitoring systems
- Markets change — strategies that worked in 2020 may fail in 2026
- Requires significant time investment to develop and validate properly
Lesson 2 — Why Automate? Pros and Cons
25 min · Decision Framework
Before committing to algorithmic trading, honestly assess whether it's right for your situation.
Algorithmic trading is well-suited for traders who:
- Have identified a clearly definable edge that can be expressed in exact rules
- Struggle with emotional execution (hesitating on entries, moving stops, overtrading)
- Want to trade while maintaining another career (EA runs while you work)
- Enjoy the process of systematic strategy development and testing
- Have the discipline to leave a working EA alone without constantly interfering
Algorithmic trading is poorly suited for traders who:
- Cannot define their edge in exact, unambiguous rules
- Want to "set and forget" without any ongoing monitoring
- Expect that automation eliminates all psychological challenges (it doesn't — watching drawdowns in a live EA is still emotionally difficult)
- Don't have time to properly validate a strategy before deploying with real capital
The most dangerous misconception: Many retail traders automate because they think it will solve their trading problems. If your manual trading is unprofitable, automation will make it unprofitable faster and more consistently. Automation amplifies existing edge (or lack of edge) — it doesn't create edge.
Lesson 3 — MT4/MT5 Expert Advisors Overview
30 min · Platform Knowledge
An Expert Advisor (EA) is a program written in MQL4 (MetaTrader 4) or MQL5 (MetaTrader 5) that runs within the trading platform and can automatically execute trades based on pre-defined rules.
MT4 Strategy Tester — the key interface: Found under View → Strategy Tester. This is where you backtest EAs against historical data.
Strategy Tester settings you must understand:
- Symbol: Which pair to test on
- Model: "Every tick" is most accurate; "Open prices only" is fastest for daily chart EAs
- Date range: How far back to test (more data = more reliable, but older data may be less relevant)
- Spread: Use the typical spread for your broker; testing with 2 pips on EUR/USD is realistic
- Initial deposit: Start with your actual planned trading capital
- Optimization: Leave unchecked for initial testing — enables optimization later
Reading basic backtest results:
- Total net profit
- Profit factor (gross profit ÷ gross loss — must be > 1.3 to be considered)
- Maximum drawdown (percentage and absolute)
- Total trades (need enough for statistical significance — minimum 100, ideally 300+)
- Win rate and average win/loss
Lesson 4 — Strategy Design Principles
35 min · Core Skill
Before writing a line of code or running a single backtest, you must define your strategy in exact, unambiguous terms. This step is where most retail algo traders fail.
What "exact and unambiguous" means:
❌ Wrong: "Buy when the trend is up and RSI is oversold" ✅ Right: "Buy when the 50 EMA is above the 200 EMA on the H4 chart AND RSI(14) closes below 30 on the H1 chart. Enter at the next H1 open. Stop-loss at 1.5× ATR(14) below entry. Take-profit at 2× the stop-loss distance."
The wrong version cannot be turned into code. The right version can be implemented exactly.
The four components every strategy must specify:
- Entry conditions: Exactly which indicators, at which values, on which timeframe trigger an entry
- Entry price: Market order at next open? Limit order at specific price?
- Stop-loss: Exactly how calculated and placed
- Exit conditions: Take-profit target + any trailing stop rules + time-based exits
Additional filters to define:
- Maximum spread allowed (avoid entering during high-spread news periods)
- Trading hours (some strategies should only run during London session, for example)
- Maximum number of simultaneous open positions
- Minimum gap between trades (avoid overtrading)
Write all of this down in plain English before touching the strategy tester. Vague strategies produce meaningless backtests.
Lesson 5 — Backtesting Fundamentals
40 min · Critical Skill
A backtest simulates how your strategy would have performed on historical data. It is the primary tool for strategy validation — but also the most abused tool in retail algo trading.
Running a valid backtest:
Step 1: Set date range to at least 3 years of data. 5 years is better. Use high-quality tick data if testing intraday strategies.
Step 2: Use realistic spread settings. For EUR/USD: 1.5–2 pips typical spread. For GBP/USD: 2–3 pips. Underestimating spread dramatically inflates results.
Step 3: Run the test without optimization first — accept the default parameters.
Step 4: Evaluate results against minimum thresholds:
| Metric | Minimum Acceptable | Good | Excellent |
|---|---|---|---|
| Profit Factor | > 1.30 | > 1.60 | > 2.0 |
| Max Drawdown | < 30% | < 20% | < 15% |
| Win Rate | Strategy-dependent | — | — |
| Total Trades | > 100 | > 300 | > 500 |
| Sharpe Ratio | > 0.5 | > 1.0 | > 1.5 |
What a backtest cannot tell you:
- How the strategy will perform in changing market conditions
- Whether the results are genuine edge or statistical coincidence
- Execution quality in live trading (slippage, requotes)
- How you will emotionally respond to a 15% live drawdown
A great backtest is a necessary but insufficient condition for a working live strategy.
Lesson 6 — Overfitting & Curve Fitting
35 min · Critical Warning
Overfitting (also called curve fitting) is the single most common reason retail EA strategies fail in live trading despite strong backtests. Understanding it thoroughly is essential.
What is overfitting? Overfitting occurs when a strategy is adjusted — either consciously or unconsciously — until it perfectly explains historical data. The result is a strategy that describes the past perfectly but has no predictive power for the future.
How overfitting happens:
- You run a strategy, get mediocre results
- You change a parameter (RSI period from 14 to 11, for example)
- Results improve
- You change another parameter
- Results improve again
- After enough iterations, you've found parameter values that perfectly fit the historical data — but those values are meaningless for future data
The illusion: A strategy with 100 optimization runs has essentially been fitted to historical data. The fact that it produced 2,000% returns in the backtest means almost nothing.
How to detect overfitting:
- Too many parameters relative to number of trades (rule of thumb: at least 10 trades per parameter)
- Results are dramatically sensitive to small parameter changes
- The strategy works only on specific currency pairs or specific date ranges
- Backtest results are suspiciously perfect (profit factor > 3.0, drawdown < 5%)
The overfitting test: Take a strategy that backtests well on 2018–2022 data. Now test it on 2023–2026 data without any changes. If it fails on the unseen data, it was overfit.
Lesson 7 — Walk-Forward Optimization
35 min · Validation Method
Walk-forward analysis is the only statistically rigorous method for optimizing a trading strategy without overfitting. It is how professional quant funds validate strategies before deployment.
The walk-forward process:
- Divide your data into multiple windows — for example, 12 months of "in-sample" (optimization) data followed by 3 months of "out-of-sample" (validation) data
- Optimize on the in-sample period → find the best parameter set for that window
- Test those parameters on the following out-of-sample period → record the results
- Advance the window forward by one period and repeat
- After 6–10 walk-forward cycles, concatenate all out-of-sample results
- Evaluate the concatenated out-of-sample equity curve — this is the most realistic estimate of live performance
Interpreting walk-forward results:
- If the out-of-sample equity curve is profitable and shows a Sharpe > 0.5, the strategy has demonstrated genuine out-of-sample edge
- If the out-of-sample results are dramatically worse than in-sample, the strategy is likely overfit — discard or redesign
- The ratio of out-of-sample to in-sample performance (walk-forward efficiency) should be > 0.3
MT4's built-in Strategy Tester supports basic walk-forward in the Expert Optimization mode. More rigorous analysis requires third-party tools or manual data management.
Lesson 8 — Key Performance Metrics
30 min · Evaluation
When evaluating a backtest, look beyond net profit. These six metrics together provide a complete picture.
1. Profit Factor Gross Profit ÷ Gross Loss. Measures how much profit is generated for each dollar lost.
- Below 1.0: Strategy loses money
- 1.0–1.3: Marginal — insufficient edge
- 1.3–1.6: Acceptable
- Above 1.6: Good
- Above 2.0: Excellent (also raises overfitting suspicion)
2. Maximum Drawdown The largest peak-to-trough decline during the test period. This is your "worse case lived scenario" — though live trading can exceed the historical maximum.
- Keep below 20% for acceptable risk
- Keep below 15% for a well-designed system
3. Sharpe Ratio (Average Return − Risk-Free Rate) ÷ Standard Deviation of Returns. Measures return per unit of risk.
- Below 0.5: Poor risk-adjusted returns
- 0.5–1.0: Acceptable
- Above 1.0: Good
- Above 1.5: Excellent
4. Win Rate Percentage of trades that close in profit. Evaluate in context of average R/R — a 35% win rate with 2.5:1 R/R is excellent; a 65% win rate with 0.5:1 R/R is unprofitable.
5. Average Trade Duration How long positions are typically held. Very short average trades (minutes) suggest the strategy is sensitive to spread costs and may not survive realistic execution conditions.
6. Total Trade Count Statistical significance requires a minimum of 100 trades; 300+ is preferred. A 10-trade backtest with 90% win rate means nothing.
Lesson 9 — Moving Average Crossover EA
40 min · Practical Exercise
The moving average crossover is the "Hello, World" of EA development. It is simple enough to understand completely yet illustrates all the principles of EA construction.
Strategy rules:
- Entry Long: 20 EMA crosses above 50 EMA on H1 chart → Buy at market open
- Entry Short: 20 EMA crosses below 50 EMA on H1 chart → Sell at market open
- Stop-Loss: 1.5× H1 ATR(14) from entry
- Take-Profit: 3× H1 ATR(14) from entry (2:1 R/R)
- Filter: Only trade when H4 trend aligns (price above 200 EMA for longs, below for shorts)
- Max spread: Do not enter if current spread > 2 pips
Backtest this strategy yourself:
- Open MT4 Strategy Tester
- Select any MA-crossover EA from your broker's library (or download free from mql5.com)
- Set EUR/USD, H1, 2019–2026, spread 2 pips
- Run without optimization first
- Compare results to the minimum thresholds from Lesson 8
- Note: This strategy is intentionally simple — most will find it barely profitable at best. The exercise is about process, not the strategy itself.
Lesson 10 — Breakout Strategy EA
40 min · Practical Exercise
A channel breakout strategy trades the break of a defined high or low over a lookback period.
Strategy rules:
- Lookback period: 20 H4 candles
- Entry Long: H4 candle closes above the highest high of the previous 20 H4 candles → Buy at next open
- Entry Short: H4 candle closes below the lowest low of the previous 20 H4 candles → Sell at next open
- Stop-Loss: Below/above the breakout candle's opposite extreme + 5-pip buffer
- Take-Profit: 2× the stop-loss distance
- Filter: ATR(14) must be above its 50-period average (only trade in normal-to-high volatility conditions — avoids low-volatility false breakouts)
This type of breakout strategy tends to have a low win rate (30–40%) but generates large wins when successful. Requires 1.5:1 minimum R/R just to break even — which is why the 2:1 target is important.
Backtest on GBP/USD 2019–2026 and evaluate results. Pay attention to how performance varies across different market conditions — trending years will show strong performance; ranging years will show losing periods.
Lesson 11 — Position Sizing in Algos
30 min · Risk Automation
Hard-coding a fixed lot size (e.g., 0.1 lots always) into an EA is one of the most common and damaging mistakes in retail algorithmic trading.
Fixed lot problems:
- Does not scale with account growth or loss
- Means you are risking a different percentage of your account on each trade depending on stop-loss distance
- Creates inconsistent risk that makes backtest results unreliable predictors of live performance
Implementing fixed-fractional position sizing in an EA:
// Pseudocode for 1% risk per trade
risk_percent = 0.01
account_equity = AccountEquity()
dollar_risk = account_equity * risk_percent
stop_pips = distance from entry to stop-loss in pips
pip_value = pip value per lot for this symbol
lot_size = dollar_risk / (stop_pips * pip_value)
lot_size = NormalizeDouble(lot_size, 2) // Round to 2 decimal placesIn MQL4/MQL5, the functions AccountEquity(), MarketInfo(Symbol(), MODE_TICKVALUE), and SymbolInfoDouble() provide the inputs needed for this calculation.
The result: Every trade risks exactly 1% of the current account equity, regardless of stop-loss distance. As the account grows, position sizes grow proportionally. During drawdowns, position sizes shrink — reducing further losses automatically.
Lesson 12 — Portfolio of Strategies
30 min · Advanced Concept
Running a single EA is fragile — it will inevitably go through losing periods, and without other strategies to offset losses, the psychological pressure to interfere is enormous.
The portfolio approach: Run 3–5 strategies simultaneously that are as uncorrelated as possible. Correlation means the strategies tend to win and lose at the same time — which creates amplified drawdowns and defeats the purpose.
How to create low-correlation strategies:
- Different timeframes (H1 EA + Daily EA)
- Different pair types (EUR/USD + Gold + USD/JPY)
- Different strategy types (trend-following + mean-reversion + breakout)
- Different session filters (London-only + New York-only)
Portfolio mathematics: If two strategies each have a 15% maximum drawdown and are 0% correlated, the portfolio drawdown is approximately 15% / √2 = 10.6%. If they are 100% correlated, portfolio drawdown remains 15%. If they are negatively correlated (one wins when the other loses), portfolio drawdown is minimized further.
True negative correlation is rare in practice — but even zero correlation between strategies meaningfully reduces portfolio drawdown.
Lesson 13 — Live Trading Checklist
30 min · Pre-Deployment
Before switching an EA from demo to live trading, verify every item on this checklist:
Broker selection:
- Does the broker allow EAs and automated trading? (Most do, but verify)
- Is the broker's execution fast enough for your strategy? (Critical for scalping EAs)
- Does the broker have any restrictions on trading during news events?
- What is the typical slippage on market orders during normal hours?
VPS (Virtual Private Server):
- Required for 24/5 operation without leaving your computer running
- Use a VPS located in the same data center or city as your broker's servers (minimizes latency)
- Windows VPS with 2GB RAM minimum for MT4; 4GB for MT5
- Test VPS connection stability for 48 hours on demo before live deployment
Monitoring:
- Set up email or push notifications for when the EA opens/closes trades
- Check the EA's journal log daily for error messages
- Set calendar reminders to check the VPS connection weekly
Kill switch:
- Know exactly how to stop the EA immediately if needed (Uncheck "AutoTrading" button in MT4/MT5)
- Keep the platform login credentials accessible at all times
- Have your broker's emergency phone number saved
Capital:
- Start live trading with the minimum viable capital — do not deploy full capital until the EA has demonstrated it works in live conditions over 60+ days
- Reconcile the live results with the backtest expectations weekly
Lesson 14 — Common EA Pitfalls & Fixes
35 min · Troubleshooting
Pitfall 1: Slippage destroys a profitable backtest Many EAs backtest profitably using "Open prices" model (which assumes perfect fill at the open) but fail live because real slippage is 1–3 pips per entry.
Fix: Always backtest using "Every Tick" model with realistic spread. Add a 1–2 pip "slippage cushion" by using limit orders instead of market orders where strategy allows.
Pitfall 2: Broker-dependency Some EAs were designed for a specific broker's pricing and may not work with another broker's feed.
Fix: Test on multiple brokers' demo accounts before choosing a live deployment broker.
Pitfall 3: Data snooping / selection bias Testing only on pairs and date ranges that make the strategy look good.
Fix: Test on at least 3 different pairs. If the strategy only works on one specific pair, it may be overfit to that pair's historical quirks.
Pitfall 4: Regime change A strategy optimized for 2019–2022 may underperform in the post-COVID, high-rate 2023–2026 environment.
Fix: Re-run walk-forward analysis annually. Be prepared to retire strategies that no longer demonstrate edge. Markets evolve — strategies must adapt or be replaced.
Pitfall 5: Interference Going live, watching the EA trade, getting uncomfortable during a normal drawdown, and manually overriding the EA's decisions.
Fix: This is the hardest pitfall because it's purely psychological. Set a maximum intervention threshold in advance (e.g., "I will only manually stop the EA if drawdown exceeds X% or if there is a technical malfunction") and write it down. The EA's whole value is removing emotion from execution — interfering destroys this.
Recommended Next Steps
- Trading Psychology — Managing emotion during EA drawdowns
- Risk & Money Management — Review position sizing before going live
- Best Brokers for EA Trading — IC Markets ranks highest for EA execution
MarketFocus.net · Free Trading Education · Updated May 2026