Candlestick patterns are among the oldest tools in technical analysis, and they still remain relevant today. With modern algorithmic trading, we can let software identify and trade these patterns systematically. In this article, we’ll walk through an Expert Advisor (MQL4 EA) that automatically trades the Three White Soldiers (bullish reversal) and the Three Black Crows (bearish reversal) patterns.
We’ll also explain its smart money management features, the ATR-based stop loss logic, and how you can tune it to your own preferences.
The Candlestick Patterns
- Three White Soldiers: Three consecutive bullish candles, each closing higher than the last, often signaling a strong bullish reversal after a downtrend.
- Three Black Crows: The bearish counterpart — three consecutive bearish candles, each closing lower than the last, suggesting strong selling pressure.
The EA continuously scans for these patterns on closed bars. When detected:
- Three White Soldiers → Buy trade
- Three Black Crows → Sell trade
Smart Stop Loss and Take Profit (SL/TP)
The EA gives you flexibility in how your stops and targets are set:
-
ATR-Based Stop Loss (default):
By default, the stop loss is calculated using the Average True Range (ATR) indicator. ATR reflects market volatility, so the EA adapts the SL distance dynamically.
- Example: If ATR(14) = 20 pips and ATRMultiplier = 1.5, then SL = 30 pips.
- This means trades in high-volatility conditions will naturally have wider stops, reducing premature stop-outs.
-
Fixed Stop Loss & Take Profit:
If you prefer consistency, you can set fixed pip values for SL and TP. For instance:
- SL = 30 pips
- TP = 60 pips
This dual option allows traders to choose between
volatility-adaptive risk control and
fixed risk/reward planning.
Floating Lot Size (Risk-Based Money Management)
Position sizing is one of the most critical aspects of trading. The EA includes
floating lot size calculation based on a fixed percentage of account balance.
Here’s how it works:
- You set a risk percentage (e.g., RiskPercent = 1.0 → 1% of balance per trade).
- The EA calculates how much money that equals, then adjusts the lot size automatically depending on stop loss size.
- If the stop is wider (due to high ATR), the lot size shrinks. If the stop is tighter, the lot size increases.
Formula in plain words:
“Risk Amount = Balance × Risk% → divide by stop-loss value in money → gives lots.”
This ensures
consistent risk per trade regardless of volatility or pair differences, a professional money management approach.
Additional Features
- Time Filter: Trade only during active market hours (e.g., London/New York session).
- Max Trades Control: Set how many trades the EA can open in total, or per direction (buys vs. sells).
- Spread Protection: Avoids opening trades in high-spread conditions.
- Broker Adaptability: Works on 4-digit, 5-digit, and 3-digit brokers.
Conclusion
This Expert Advisor combines
classic candlestick reversal patterns with
modern risk management principles:
- ATR or fixed SL/TP → adaptive or controlled exits.
- Floating lot size → consistent risk per trade.
- Adjustable MinBodySizePips → fine-tuning pattern quality.
By automating both detection and execution, traders can remove emotional decision-making and test these setups objectively with the
MetaBacktest.
Before going live, always run thorough backtests to adapt the EA to your pair, timeframe, and risk tolerance.
Backtest Results by MetaBacktest
We ran multiple backtests of the
MQL4 Expert Advisor using
MetaBacktest to ensure fair and transparent results.
Test Parameters:
- Instrument : EURUSD
- Timeframe : H1
- Period : Jan 2012 – Aug 2025
- Lot Size : Risk-Based Floating Lot Size
- Stop Loss / Take Profit : ATR-Based Stop Loss / 60 pips fixed TP
- Maximum Allowed Trades : 3
Process time: 0:00:52.406
Key Results:
Test Parameters:
- Instrument : USDJPY
- Timeframe : H1
- Period : Jan 2012 – Aug 2025
- Lot Size : Risk-Based Floating Lot Size
- Stop Loss / Take Profit : ATR-Based Stop Loss / 60 pips fixed TP
- Maximum Allowed Trades : 3
Process time: 0:00:48.953
Key Results:
Test Parameters:
- Instrument : USDCAD
- Timeframe : M15
- Period : Jan 2012 – Aug 2025
- Lot Size : Risk-Based Floating Lot Size
- Stop Loss / Take Profit : ATR-Based Stop Loss / 60 pips fixed TP
- Maximum Allowed Trades : 3
Process time: 0:00:37.203
Key Results:
Comparison by MetaBacktest:
three white soldiers-MetaBacktest.ex4
three white soldiers-MetaBacktest.mq4
Result-EURUSD-H1.zip
Result-USDJPY-H1.zip
Result-USDCAD-M15.zip
Please Login or Signup
to be able to download the files.
Big respect for publishing the actual EA code. So many sites just tease strategies without showing the real thing.
I’ve noticed Black Crows often give false signals in sideways markets. How does the EA handle this?
That’s where the time filter and trade limits help
Do you think combining these candlestick signals with trend filters (like MA or RSI trend bias) would improve accuracy?
The article says max spread safeguard is included — does that mean no trades if spread spikes?
Yes, exactly. Super useful during news events.
Nice, I blew an account once because of ignoring spreads.
Love that you included ATR-based stop loss. Fixed SL always ruins candlestick strategies.
Totally. ATR adapts to volatility, which is critical.