指定
Platform: MetaQuotes MetaTrader 5
Language: MQL5
Timeframe: H1 (hard-coded default, but parameterized)
Default Symbol: EURUSD (must support any symbol)
Execution Mode: Market Execution
2️⃣ CORE PHILOSOPHY
System optimized for:
-
Capturing expansion after pullback
-
Maximizing R multiple
-
Allowing volatility-based scaling
-
Accepting moderate-to-high drawdown
No:
-
Martingale
-
Grid
-
Hedging
3️⃣ INPUT PARAMETERS
🔹 Trend
-
EMA_Trend_Period = 200
-
EMA_Pullback_Period = 20
🔹 Risk
-
Risk_Percent = 0.5
-
Max_Open_Trades = 2
-
Max_Trades_Per_Candle = 1
🔹 Stop Loss Mode
Enum:
-
SL_FRACTAL
-
SL_LOOKBACK
Parameters:
-
Lookback_Candles = 5
🔹 Take Profit Mode
Enum:
-
TP_FIXED_RR
-
TP_TRAILING_R
Parameters:
-
RR_Ratio = 2.0
-
Trailing_Activation_R = 1.5
🔹 Volatility Filter (NEW – Required for Return Maximization)
-
ATR_Period = 14
-
Min_ATR_Value = dynamic or fixed
-
ATR_Multiplier_SL = 1.0 (optional override)
🔹 Spread Filter
-
Max_Spread_Points
🔹 Session Filter
-
Session_Start = 08:00
-
Session_End = 17:00
-
Session_Timezone = CET
-
Must auto-adjust DST
🔹 Slippage
-
Max_Slippage_Points
🔹 Magic Number
-
Magic_Number
4️⃣ TREND FILTER LOGIC
BUY allowed if:
Close[1] > EMA200
SELL allowed if:
Close[1] < EMA200
EMA calculated on close price.
No intra-candle calculation.
Signal evaluated only on new bar.
5️⃣ ENTRY LOGIC
BUY CONDITIONS:
-
Trend bullish
-
Candle[1] touches or closes below EMA20
(Low[1] <= EMA20 OR Close[1] <= EMA20) -
Candle[0] closes above High[1]
-
Trade executed at open of next candle
SELL = mirror logic.
6️⃣ NEW BAR DETECTION (MANDATORY)
Trade logic must execute only once per candle:
Use static datetime:
static datetime lastBarTime; if(Time[0] != lastBarTime) { lastBarTime = Time[0]; // Execute logic }No tick-based signal execution.
Mode A – FRACTAL
Use last confirmed fractal only.
Confirmed fractal:
Index >= 2 (no repaint)
BUY:
Last confirmed down fractal
SELL:
Last confirmed up fractal
Mode B – LOOKBACK
BUY:
Lowest Low of last N candles excluding current
SELL:
Highest High of last N candles excluding current
SL must include:
-
Spread buffer
-
StopLevel check
No fixed pip stops allowed.
8️⃣ POSITION SIZING (CRITICAL)
Lot calculation:
RiskMoney = AccountBalance * (Risk_Percent / 100)
SL_Distance_Points = |EntryPrice - StopLoss|
LotSize = RiskMoney / (SL_Distance_Points * TickValuePerPoint)
Must normalize to:
-
MinLot
-
LotStep
-
MaxLot
If SL distance too small → trade rejected.
9️⃣ TAKE PROFIT LOGIC
Mode 1 – Fixed RR
TP = Entry ± (SL_Distance × RR_Ratio)
Mode 2 – Trailing R Expansion
No fixed TP.
When price reaches:
Entry + (SL_Distance × Trailing_Activation_R)
Then:
SL moves to:
Entry + (0.5R)
After activation:
Trailing every new candle using:
Max(
Previous SL,
Low[1] (for BUY)
)
This ensures volatility capture.
🔟 VOLATILITY FILTER (RETURN ENHANCEMENT)
Trade allowed only if:
ATR(14) > ATR_Moving_Average(50)
This ensures expansion regime.
Alternative:
ATR > X% of 6-month average.
This prevents range death.
1️⃣1️⃣ TRADE LIMITATION RULES
-
Maximum 2 open positions total
-
No duplicate direction entries on same candle
-
If position closed within candle → no re-entry
1️⃣2️⃣ SESSION FILTER
Time must be converted:
ServerTime → CET
Must handle DST automatically.
If time outside window → no new trades.
Management of open trades continues.
1️⃣3️⃣ SPREAD FILTER
CurrentSpread <= Max_Spread_Points
Else skip trade.
1️⃣4️⃣ ERROR HANDLING
Must check:
-
TRADE_RETCODE_DONE
-
TRADE_RETCODE_REQUOTE
-
TRADE_RETCODE_REJECT
Retry logic allowed once.
All errors logged.
1️⃣5️⃣ PERFORMANCE VALIDATION REQUIREMENTS
Backtest Requirements:
-
Data: 2015–2025
-
Modeling: Every Tick
-
Symbols:
-
EURUSD
-
GBPUSD
-
XAUUSD
-
Minimum metrics required:
-
Profit Factor > 1.4
-
Max DD < 35%
-
Expectancy positive
-
R multiple average > 1.2
Monte Carlo simulation recommended.
1️⃣6️⃣ CODE STRUCTURE REQUIREMENT
Must include:
-
Separate functions
-
OOP preferred
-
CTrade usage
-
Clear comments
-
No hard-coded broker values
File Deliverables:
-
.mq5
-
.ex5
-
Backtest report (.html)
-
Input parameter guide (.pdf or .doc)