Specification
I have a working Python backtester for my “DC-WAD Donchian” strategy. I need a MetaTrader 5 Expert Advisor (MQL5) for live trading that matches the Python logic as closely as possible (no lookahead).
✅ Critical requirement (must accept)
EA must be tick-driven for entries/exits (touch logic).
Bar-close approximation is not acceptable.
Timeframes
-
Strategy runs on a single Setup Timeframe (HTF) (user input, e.g., M30/H1/H4 etc.)
-
Optional LTF for intraday ambiguity exists in Python, but NOT required for this milestone (we will skip ambiguity mode).
Core logic (must replicate)
1) Donchian + state machine
-
Long/short mirror
-
States: 00 → 01 → 02 → 03
-
Setup01 validity: t+3 is last chance; when count reaches 4 → invalidate/reset
2) WAD filter
-
Compute WAD internally + WAD SMA(n)
-
Optional HTF WAD filter + optional WAD source mode (as per Python)
3) ATR risk filter
-
Reject if risk distance > k * ATR(n)
-
ATR must match Python: ATR = SMA(TrueRange, n) (not Wilder)
Entry modes (inputs)
-
Normal (breakout) entry
-
Optional retracement limit entry
-
limit at p% retracement (e.g., 50%)
-
include time window inputs if needed (signal/fill windows)
Required retracement rule:
-
If retracement limit becomes worse than breakout entry:
-
LONG: if limit > breakout_entry → clamp to breakout_entry
-
SHORT: if limit < breakout_entry → clamp to breakout_entry
-
Trade management
-
TP1 closes 50%
-
TP2 manages remaining 50% via trailing (input select):
-
PSAR trailing OR Stochastic trailing
-
-
Trailing is tighten-only
-
Trailing starts after TP1 as per Python rules
PSAR freeze rule (must implement):
-
Maintain last_valid_psar
-
LONG: update only when PSAR below close; else freeze
-
SHORT: update only when PSAR above close; else freeze
-
Use closed bars only (no lookahead).
Execution rules (tick-based)
-
Stop/limit triggers by Bid/Ask touch on ticks
-
Partial close logic must work in live + tester
-
Respect spread (Bid/Ask). No “mid price” assumptions.
Logging
-
Export CSV trade log (minimum):
-
entry time/price, exit(s), SL, TP1/TP2, side, session/tag, reason codes, PnL, R-multiple
-
Deliverables
-
Full .mq5 source, clean + commented
-
Inputs grouped clearly
-
Short README: how to test + any differences vs Python