指定
1. Goal
I want a MetaTrader 5 Expert Advisor that trades a simple Supertrend trend‑following idea, but with professional‑grade risk management and filters. It should be robust enough for real money on instruments like XAUUSD and GBP pairs, using small, consistent risk per trade rather than martingale or grid.
2. Strategy Logic
Indicators (I will supply the .mq5 files if needed):
-
Supertrend (ATR‑based), with adjustable:
-
ATR period
-
ATR multiplier
-
-
Optional DEMA (trend filter), with adjustable period.
Signal and trend rules:
-
Use closed candles only (no intra‑bar decisions).
-
On each new bar:
-
Read Supertrend direction on bar 1 (just closed) and bar 2 (previous).
-
Direction = +1 (uptrend) or −1 (downtrend).
-
-
Entry:
-
If direction flips from −1 to +1 and trend filter allows longs → open buy.
-
If direction flips from +1 to −1 and trend filter allows shorts → open sell.
-
-
Trend filter:
-
Input Use_DEMA_Filter (true/false).
-
If true:
-
Only buy if price is above DEMA (and optionally DEMA is flat or rising).
-
Only sell if price is below DEMA (and optionally DEMA is flat or falling).
-
-
If false:
-
Ignore DEMA and trade purely on Supertrend.
-
-
Position logic:
-
Only one position per symbol per magic number.
-
Input Reverse_On_Signal :
-
If true: on opposite signal, close existing trade and immediately open in the new direction.
-
If false: on opposite signal, close trade only (no immediate reverse).
-
3. Risk Management (non‑negotiable)
3.1 Lot sizing
-
Use_Risk_Percent (true/false).
-
If false → use fixed lot Lots .
-
If true → calculate lot size from Risk_Percent_Per_Trade (e.g. 0.5–2%) based on distance from entry to initial SL, using standard percentage‑risk money management.
3.2 Stop loss / take profit
-
The EA must always be able to run with a real stop‑loss. No martingale, no grid, no averaging down or “recovery” systems.
-
SL modes (selectable input SL_Mode ):
-
1 = fixed SL in points.
-
2 = SL at or just beyond the Supertrend line at entry.
-
3 = ATR‑based SL (multiple of ATR).
-
-
TP modes ( TP_Mode ):
-
0 = no hard TP (exit via opposite signal or trailing).
-
1 = fixed TP in points.
-
2 = RR multiple (e.g. 2R, 3R) based on initial SL.
-
3.3 Breakeven rule (10‑pip to entry)
Implement a breakeven mechanism:
-
Inputs:
-
Use_Breakeven (true/false)
-
Breakeven_Trigger_Points (default value 100 points on 5‑digit quotes = 10 pips; I can adjust later)
-
Behaviour:
-
When Use_Breakeven = true , once the trade is in profit by at least Breakeven_Trigger_Points , move the stop loss to exact entry price (no extra buffer).
-
This should happen once per trade; after SL is moved to breakeven, do not move it back even if price retraces.
3.4 Trailing stop
-
Option Use_ST_Trailing :
-
If enabled, trail SL on each new bar using the current Supertrend value in favour of the trade, never loosening it.
-
-
Optional standard trailing stop:
-
Inputs like Use_Classic_Trailing , Classic_Trail_Start , Classic_Trail_Step .
-
-
Trailing should co‑exist logically with the breakeven rule (i.e. breakeven first, then trailing can continue to move SL further into profit).
3.5 Session & filter controls
-
Use_Session_Filter (true/false).
-
Inputs for at least one session window:
-
Session_Start_Hour , Session_End_Hour (server time).
-
Optional second window: Session2_Start_Hour , Session2_End_Hour .
-
-
Rules:
-
No new trades outside permitted hours.
-
EA should still manage existing trades (breakeven, trailing, exits) outside session unless an input Close_Outside_Session is set true.
-
-
Day‑of‑week switches (Mon–Fri on/off).
3.6 Spread / slippage / safety
-
Max_Spread_Points – block new trades if current spread exceeds this.
-
Slippage – maximum allowed slippage for market orders.
-
Optional equity protection:
-
Daily_Max_Loss_Percent and/or Overall_Max_Loss_Percent .
-
When hit, EA must stop opening new trades for that day (or until reset), with a clear comment/log message.
-
4. Inputs Summary (minimum)
-
General:
-
Lots , Use_Risk_Percent , Risk_Percent_Per_Trade , Magic_Number , Trade_Comment .
-
-
Supertrend:
-
ST_ATR_Period , ST_ATR_Multiplier .
-
-
DEMA:
-
Use_DEMA_Filter , DEMA_Period .
-
-
Risk:
-
SL_Mode , SL_Fixed_Points , SL_ATR_Multiplier .
-
TP_Mode , TP_Fixed_Points , TP_R_Multiple .
-
Use_ST_Trailing , Use_Classic_Trailing , Classic_Trail_Start , Classic_Trail_Step .
-
Use_Breakeven , Breakeven_Trigger_Points (default 100 points ≈ 10 pips).
-
Max_Spread_Points , Slippage .
-
Optional: Daily_Max_Loss_Percent , Overall_Max_Loss_Percent .
-
-
Session:
-
Use_Session_Filter , Session_Start_Hour , Session_End_Hour , optional second session, weekday on/off.
-
-
Behaviour:
-
Reverse_On_Signal , Close_Outside_Session .
-
5. Technical Requirements
-
Platform: MetaTrader 5, language MQL5.
-
Delivery: full source code ( .mq5 ).
-
No external DLLs or paid libraries.
-
No martingale / grid / hedging‑recovery logic. Straight single‑position trend‑following only.
-
Code must:
-
Compile with no errors and no serious warnings.
-
Be clearly structured with functions for:
-
Reading indicators
-
Generating signals
-
Position sizing
-
Opening/closing trades
-
Breakeven and trailing logic
-
-
-
Include light comments, especially around:
-
Supertrend / DEMA buffer mapping
-
Entry/exit logic
-
Breakeven and trailing implementation.
-
6. Testing & Deliverables
-
Please test the EA in Strategy Tester on at least:
-
One FX pair
-
One volatile instrument (e.g. XAUUSD)
-
I don’t need optimisation; I just need confirmation that:
-
Entries occur only after a confirmed Supertrend flip on candle close.
-
DEMA filter, session filter, spread filter work as described.
-
SL/TP modes, breakeven at 10 pips, and trailing all behave correctly.
Deliverables:
-
Final .mq5 EA source file.
-
Short note describing:
-
Which indicator buffers are used.
-
How risk (SL/TP, breakeven, trailing) is implemented.
-
Any assumptions about account type (hedging vs netting).
-