Spécifications
1. Project Overview
Name: BB Channel Trading EA
Objective: Execute reversal trades based on price action (engulfing patterns and liquidity sweeps) at the extremes defined by Bollinger Bands. Trades will be taken when price breaks volatility bounds, indicating potential exhaustion and reversal.
2. Functional Components
2.1 Bollinger Bands Channel
-
Purpose: Identify overbought and oversold zones.
-
Indicator: Custom Bollinger Bands (BB.ex5).
-
Parameters:
-
BBPeriod (int; default: 20)
-
BBShift (int; default: 0)
-
BBDeviation (double; default: 2.0)
-
-
Buffers:
-
Upper Band — buffer index 1
-
Lower Band — buffer index 2
-
2.2 Liquidity Sweep Detection
-
Purpose: Confirm break of local high/low, indicating possible stop run.
-
Parameter: LookbackBars (int; default: 5)
-
Logic:
-
Long: current candle’s low < lowest low of prior LookbackBars .
-
Short: current candle’s high > highest high of prior LookbackBars .
-
2.3 Engulfing Pattern Detection
-
Purpose: Confirm strong reversal candle.
-
Rules:
-
Bullish Engulfing:
-
Current candle is bullish ( Close > Open )
-
Its body wicks fully exceed the previous candle’s body & wicks:
-
Open[current] < Close[previous]
-
Close[current] > Open[previous]
-
High[current] > High[previous]
-
Low[current] < Low[previous]
-
-
-
Bearish Engulfing: Reverse logic for a bearish bar.
-
3. Trade Logic
3.1 Entry Conditions
-
Long Trade:
-
Close[lastBar] < LowerBand
-
Liquidity sweep (new local low)
-
Bullish engulfing pattern
-
-
Short Trade:
-
Close[lastBar] > UpperBand
-
Liquidity sweep (new local high)
-
Bearish engulfing pattern
-
3.2 Trade Execution
-
Lot Size: LotSizeMultiplier (double; default: 0.1)
-
Stop Loss (SL):
-
Long: Low of current bar
-
Short: High of current bar
-
-
Take Profit (TP):
-
Long: Close + (Close - SL) * RiskRewardRatio
-
Short: Close - (SL - Close) * RiskRewardRatio
-
4. Input Parameters
Parameter | Type | Default Value | Description |
---|---|---|---|
LookbackBars | int | 5 | Bars to consider for liquidity sweep |
RiskRewardRatio | double | 2.0 | SL–TP distance ratio |
LotSizeMultiplier | double | 0.1 | Trade volume multiplier |
BBPeriod | int | 20 | Bollinger Bands period |
BBShift | int | 0 | Bollinger Bands shift |
BBDeviation | double | 2.0 | Bollinger deviation multiplier |
5. Platform & Trade Environment
-
Platform: MetaTrader 5 (MT5)
-
Dependencies:
-
Bollinger Bands indicator ( BB.ex5 ) in MQL5/Indicators
-
-
Trading Conditions:
-
Auto trading enabled
-
EA Properties → “Allow live trading” enabled
-
Broker’s min lot size must be ≤ LotSizeMultiplier
-
-
Chart Timeframes: M5–H1 recommended
6. Error Handling & Safeguards
-
Price Arrays: Use CopyOpen() , CopyClose() , CopyHigh() , CopyLow() to fill buffers; abort if any fail.
-
Indicator Buffers: Use CopyBuffer() for upper/lower bands; abort if empty or EMPTY_VALUE .
-
Array Bounds: Check bar + 1 < ArraySize(...) before intact comparisons.
-
Valid SL / TP: Ensure TP/SL calculations produce valid, non-zero values.
7. Debugging & Logging
-
Print key values:
-
Close[lastBar] , Upper , Lower
-
Results of liquiditySweep() and isBullishEngulfing()
-
-
Log trade attempts and any rejection (via Expert and Journal tabs).
8. Future Enhancements (Optional)
-
Trailing Stop: Adjustable trailing stop logic based on channel midline.
-
Trade Flip Logic: Exit long and immediately open short (and vice versa) on opposite signal.
-
Multi-Position Mode: Allow multiple simultaneous trades (e.g., hedging).
-
Optimizations: Use Strategy Tester to optimize BBPeriod , BBDeviation , RiskRewardRatio .