Specification
Purpose
-
Develop an Expert Advisor (EA) for MetaTrader 5.
-
Strategy: Breakout from the pre-London session range with strict risk management and no grid/martingale.
-
Goal: Scalp intraday momentum after London open using pending orders.
-
Broker: Pepperstone (ECN / RAW spreads).
-
Instruments: default EURUSD and XAUUSD (configurable).
Trading Logic
1. Pre-Range Session
-
Time based on server time (TimeTradeServer).
-
Define range between PreRangeStart and PreRangeEnd .
-
Default: 05:00 – 07:15 server time.
-
-
Record PreHigh (highest price) and PreLow (lowest price) of this window.
-
Range filters:
-
If (PreHigh – PreLow) < MinRangeATR * ATR(14, M5) → skip trading.
-
If (PreHigh – PreLow) > MaxRangePips → skip trading.
-
2. Entry Window
-
Default: 07:15 – 11:30 (London) and optionally 13:30 – 16:30 (New York).
-
Place pending orders at breakout levels:
-
BUY STOP = PreHigh + BufferPips .
-
SELL STOP = PreLow – BufferPips .
-
-
Only if all filters are met:
-
Spread ≤ MaxSpreadPoints.
-
ATR(14, M5) within MinATR–MaxATR.
-
Optional: Trend filter → Only Buy if price > EMA200 (M15), only Sell if price < EMA200.
-
3. Pending Order Management
-
Place both orders (or only one if EMA trend filter applies).
-
Cancel the opposite order once one is triggered.
-
Cancel all untriggered orders when:
-
EntryWindow ends, or
-
Filters fail (spread too wide, volatility too low).
-
4. Stop Loss / Take Profit
-
SL options:
-
Default: kATR * ATR(14, M5) .
-
Or: opposite side of the pre-range ± buffer (choose the smaller distance).
-
-
TP = RR * SL (default RR = 1.5 for FX, RR = 2.0 for XAUUSD).
-
Break-even:
-
Move SL to entry after price moves in profit by BE_Trigger * SL (default 1.0).
-
Add offset ( BE_Offset ) if configured.
-
-
Trailing:
-
Start after TrailTrigger * SL .
-
Trail distance = TrailATR * ATR(14, M5) .
-
5. Risk Management
-
RiskPerTrade% (default 1%). Lot size calculated dynamically based on SL distance.
-
Use symbol properties ( SYMBOL_TRADE_TICK_VALUE , etc.) to compute correct lot size.
-
Daily loss limit: If equity drops by MaxDailyLoss% (default 3%), no new trades until next day.
-
Max trades per day: e.g., 2.
Inputs (parameters)
-
Session times:
-
PreRangeStart="05:00" , PreRangeEnd="07:15" .
-
EntryWindowStart="07:15" , EntryWindowEnd="11:30" .
-
UseNYWindow=true , NYWindowStart="13:30" , NYWindowEnd="16:30" .
-
-
Filters:
-
BufferPips=5 (EURUSD), BufferGoldPoints=50 (XAUUSD).
-
MinATR=0.0008 , MaxATR=0.0040 (for EURUSD).
-
MinRangeATR=0.6 , MaxRangePips=25 .
-
MaxSpreadPoints=12 .
-
UseEMATrend=true , EMAPeriod=200 , EMATF=PERIOD_M15 .
-
-
Stops & Targets:
-
UseATRStop=true , kATR=1.0 .
-
RR=1.5 (EURUSD), RR_XAU=2.0 .
-
UseBreakEven=true , BE_Trigger=1.0 , BE_Offset=2 .
-
UseTrailing=true , TrailTrigger=1.2 , TrailATR=1.0 .
-
-
Risk settings:
-
RiskPerTrade=1.0 .
-
MaxDailyLoss=3.0 .
-
MaxTradesPerDay=2 .
-
-
Execution:
-
MaxSlippagePoints=10 .
-
DeleteOppositePendingOnFill=true .
-
-
Symbols & Magic:
-
Symbols="EURUSD,XAUUSD" .
-
Magic=17092025 .
-
Comment="PreLondonBreakout_Pepperstone" .
-
EA Architecture
-
OnInit() → load symbols, initialize states.
-
OnTick():
-
Track PreRange highs/lows.
-
Place pending orders only in EntryWindow.
-
Cancel pending orders at window end or after opposite is triggered.
-
Manage active positions (BE, trailing, SL/TP).
-
-
OnTradeTransaction() → handle fills, update daily P&L, enforce limits.
-
OnDeinit() → clean pending orders.
Additional Requirements
-
Work with multiple symbols (EURUSD, XAUUSD by default).
-
One active trade per symbol.
-
Proper logging: reasons for order placement or cancellation.
-
Draw lines on chart: PreHigh/PreLow, pending orders, SL/TP.
-
Optimizable inputs for backtesting (range times, buffer, ATR multiplier, RR).