The purpose of this EA is to automate the Turtle Trading System, originally developed by Richard Dennis and William Eckhardt, using Donchian Channel breakouts and ATR-based volatility stops. The EA will execute entries, exits, and risk management automatically.
The EA should:
Trade any MT5-compatible instrument (Forex, Crypto, Commodities, Indices, Synthetic Indices).
Support backtesting and live trading.
Implement both System 1 (short-term) and System 2 (long-term) Turtle breakout rules.
Manage trade sizing, pyramiding, stop-loss, and trailing stops based on ATR volatility.
System 1 (Short-term):
Buy when price closes above the Donchian Channel high (N = 20).
Sell when price closes below the Donchian Channel low (N = 20).
System 2 (Long-term):
Buy when price closes above the Donchian Channel high (N = 55).
Sell when price closes below the Donchian Channel low (N = 55).
Filter Option:
Enable/disable each system independently.
Optionally confirm with trend filter (e.g., 200 EMA direction).
Exit all long positions when price closes below the Donchian Channel low (N = 10).
Exit all short positions when price closes above the Donchian Channel high (N = 10).
Optional trailing stop exits (ATR-based).
Each trade has a fixed stop loss equal to:
Default ATR_Multiplier = 2.0.
Risk-based sizing:
Position Size = (Account Balance × Risk%) / (Stop Distance)
Default Risk% = 1% per trade.
Minimum lot size enforced by broker specifications.
Allow multiple entries (up to 4) in the direction of profit.
New positions are opened every +0.5 ATR move in favor of trade.
Each added position has its own stop-loss based on most recent ATR.
Optional Take Profit at user-defined R:R ratio (default = 2.0).
If disabled, rely solely on Donchian or trailing exits.
Dynamic trailing stop based on ATR(20) × Trailing Multiplier.
Updates on every new candle or tick.
Volatility Filter: Trade only when ATR > ATR_SMA(20).
Session Filter: Trade only during selected hours (e.g., London/NY).
Trend Filter: Only take trades aligned with a higher timeframe trend (EMA direction).
| Parameter | Description | Default |
|---|---|---|
| System1_Period | Donchian Channel Period (Short-term) | 20 |
| System2_Period | Donchian Channel Period (Long-term) | 55 |
| Exit_Period | Donchian Exit Period | 10 |
| ATR_Period | ATR calculation length | 20 |
| ATR_Multiplier | Multiplier for stop distance | 2.0 |
| Risk_Percent | % of balance risked per trade | 1.0 |
| TP_Multiplier | Take-profit multiplier (R:R) | 2.0 |
| Allow_Pyramiding | Enable additional entries | true |
| Max_Pyramids | Max pyramided entries per direction | 4 |
| TrailStop_Enable | Enable trailing stop | true |
| TrailStop_ATRMult | Trailing stop ATR multiplier | 1.0 |
| Use_TrendFilter | Trade with EMA trend confirmation | false |
| Trend_EMA_Period | EMA period for trend | 200 |
| SessionStart | Start time (HH:MM) | 00:00 |
| SessionEnd | End time (HH:MM) | 23:59 |
| Slippage | Max price slippage | 3 pips |
| MagicNumber | Unique EA trade ID | 20250507 |
EA must execute in under 100 ms per tick.
Backtest-compatible across all timeframes (1M–1D).
Platform: MetaTrader 5.
Accounts: Supports both Hedging and Netting modes.
Broker Types: ECN, Market Maker, Deriv, Forex.com, etc.
Check all indicator handles before use.
Prevent duplicate entries.
Handle “Off Quotes” and “Invalid Volume” gracefully with retry logic.
Print trade entries, exits, and risk calculations to the Experts tab.
Store key variables (ATR, Donchian levels, stops) for debugging.
Setup Detection
ATR(20) = 120 pips.
Donchian high = 1.1200; Donchian low = 1.1000.
Price closes at 1.1205 → Long breakout triggered.
Order Calculation
Stop Distance = ATR × 2.0 = 240 pips.
Risk = 1% of $10,000 = $100.
Lot size = 100 / 240 = 0.0416 ≈ 0.04 lots.
Execution
Buy 0.04 lots at 1.1205.
Stop Loss at 1.0965.
Take Profit at 1.1685 (2R).
Management
If price rises by 0.5 ATR, add 0.04 lots (pyramid #1).
If price closes below Donchian(10) low → Exit all longs.
Equity stop: close all trades if drawdown exceeds MaxDrawdown% .
Spread filter: disable new entries if spread > average × 2.
News filter (optional): disable entries during major news events (via external calendar or user input).
Slippage protection on order placement.
Source Code ( TurtleTrader.mq5 )
Compiled EA ( TurtleTrader.ex5 )
User Guide (parameters, setup, and backtest instructions)
Backtest Report (e.g., EURUSD and Boom1000 examples)
Optimization Template ( .set files)