Advanced five-candle pattern detection system for XAUUSD on the 1-minute timeframe
The Three+Doji+1 Pattern EA is a sophisticated algorithmic trading system designed specifically for XAUUSD (Gold) on the 1-minute timeframe. It identifies and trades a unique five-candle pattern consisting of three consecutive large candles in the same direction, followed by a doji candle (indicating indecision), and completed by a fifth large candle that confirms the pattern.
This EA is engineered to capitalize on continuation patterns after brief periods of consolidation. The doji candle in the middle of the pattern represents market indecision after a strong directional move, and the fifth candle signals the resumption of the trend. The system waits for a breakout beyond the high (for bullish patterns) or low (for bearish patterns) of the fifth candle before entering a trade.
Developed with precision risk management, the EA calculates position sizes based on a percentage of account balance and user-defined risk parameters. It offers multiple stop loss modes to optimize protection based on market conditions and pattern characteristics.
Identifies specific candle patterns with configurable sensitivity parameters for optimal trade entry timing.
Real-time detection of pattern completion and immediate execution on breakout confirmation.
Multiple stop loss modes with risk-based position sizing to preserve capital during volatile periods.
Pattern visualization on charts with labeled candles for transparent trading decisions and easy performance review.
The EA identifies a specific five-candle pattern sequence. For long entries: three consecutive bullish candles, followed by a bearish doji, and completed by a fifth bullish candle. For short entries: three consecutive bearish candles, followed by a bullish doji, and completed by a fifth bearish candle.
Uses ATR (Average True Range) to dynamically measure candle size requirements relative to current market volatility, ensuring consistent pattern detection across different market conditions.
Uses a fixed risk-reward ratio (default 1:2) to calculate take profit levels. The distance from entry to stop loss is multiplied by the risk-reward ratio to determine the take profit level.
Offers four configurable stop loss modes:
1. Last Candle: Uses the low/high of candle 5
2. Doji Candle: Uses the low/high of the doji candle (candle 4)
3. Lower of Both: Uses the more conservative (lower for longs, higher for shorts) of
candles 4 and 5
4. Higher of Both: Uses the less conservative extreme of candles 4 and 5
Automatically cancels pending pattern setups when price action invalidates the pattern before breakout occurs, preventing entries in failed setups.
Calculates position size based on a percentage of account balance (default 1%), the distance to stop loss in price units, and the symbol's tick value to ensure consistent risk exposure across different market conditions.
User-configurable risk percentage (default 1%) of account balance per trade, ensuring no single trade can cause significant drawdown.
Validates that stop loss and take profit levels comply with broker requirements for minimum distance from entry price, preventing order rejection due to invalid stop levels.
Optionally labels pattern candles directly on the chart (C1, C2, C3, Doji, C5) for visual confirmation and performance analysis.
Separate parameters for bullish and bearish patterns allow customization of pattern detection sensitivity based on market characteristics.
Can be configured to look for patterns starting with 1, 2, or 3 initial large candles, allowing adaptation to different market behaviors and timeframes.
Visual representation of the trading system's decision-making process
This flowchart shows the entire decision-making process from pattern detection to trade execution and management.
Detailed breakdown of how the five-candle pattern is identified and validated.
How the EA monitors for breakout confirmation and executes trades.
Position sizing and risk calculation workflow.
Sophisticated detection of a specific five-candle pattern that indicates high-probability continuation setups after brief market indecision.
Waits for clear price confirmation beyond pattern boundaries before entering trades, reducing false signals and improving win rate.
Optional on-chart labeling of detected pattern candles for transparent trading decisions and easy performance analysis.
Dynamic position sizing based on account balance percentage and stop loss distance to ensure consistent risk exposure.
Extensive parameter set allowing customization for different market conditions and trading preferences.
Detailed trade logging with all relevant information for performance analysis and optimization.
Complete list of all configurable settings with descriptions and recommended ranges
| Parameter Name | Type | Default | Range | Description | Category |
|---|---|---|---|---|---|
InpTimeframe |
ENUM | PERIOD_M1 | Any MT5 timeframe | Timeframe used for pattern analysis and detection. | Pattern |
InpNumStartingCandles |
int | 3 | 1 - 3 | Number of initial large candles required before the doji candle. Can be 1, 2, or 3 depending on pattern sensitivity desired. | Pattern |
InpATRPeriod |
int | 14 | 5 - 50 | Period used for ATR calculation to determine candle size requirements relative to current volatility. | Pattern |
InpBullCandle1_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of first bullish candle in long setups. | Pattern |
InpBullCandle2_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of second bullish candle in long setups. | Pattern |
InpBullCandle3_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of third bullish candle in long setups. | Pattern |
InpBearCandle1_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of first bearish candle in short setups. | Pattern |
InpBearCandle2_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of second bearish candle in short setups. | Pattern |
InpBearCandle3_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of third bearish candle in short setups. | Pattern |
InpBullDoji_BodyToSizeFactor |
double | 0.3 | 0.1 - 0.5 | Maximum ratio of doji body size to total candle size for bearish doji in long setups. | Pattern |
InpBullDoji_BodyToC3BodyFactor |
double | 0.3 | 0.1 - 0.5 | Maximum ratio of doji body size to third candle body size for bearish doji in long setups. | Pattern |
InpBullDoji_UpperWickToC3BodyFactor |
double | 0.5 | 0.1 - 2.0 | Maximum ratio of upper wick size to third candle body size for bearish doji in long setups. | Pattern |
InpBullDoji_LowerWickToC3BodyFactor |
double | 0.5 | 0.1 - 2.0 | Maximum ratio of lower wick size to third candle body size for bearish doji in long setups. | Pattern |
InpBullDoji_MustBeInside |
bool | false | true/false | Requires the bearish doji to be completely contained within the range of the third candle for long setups. | Pattern |
InpBearDoji_BodyToSizeFactor |
double | 0.3 | 0.1 - 0.5 | Maximum ratio of doji body size to total candle size for bullish doji in short setups. | Pattern |
InpBearDoji_BodyToC3BodyFactor |
double | 0.3 | 0.1 - 0.5 | Maximum ratio of doji body size to third candle body size for bullish doji in short setups. | Pattern |
InpBearDoji_UpperWickToC3BodyFactor |
double | 0.5 | 0.1 - 2.0 | Maximum ratio of upper wick size to third candle body size for bullish doji in short setups. | Pattern |
InpBearDoji_LowerWickToC3BodyFactor |
double | 0.5 | 0.1 - 2.0 | Maximum ratio of lower wick size to third candle body size for bullish doji in short setups. | Pattern |
InpBearDoji_MustBeInside |
bool | false | true/false | Requires the bullish doji to be completely contained within the range of the third candle for short setups. | Pattern |
InpBullCandle5_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of fifth bullish candle in long setups. | Pattern |
InpBearCandle5_ATRMultiplier |
double | 0.8 | 0.3 - 3.0 | ATR multiplier for minimum body size of fifth bearish candle in short setups. | Pattern |
InpMaxBreakoutWait |
int | 5 | 1 - 20 | Maximum number of candles to wait for breakout confirmation after pattern completion. | Breakout |
InpInvalidationLevel |
ENUM | INVALIDATION_CANDLE5 | CANDLE4/CANDLE5 | Level at which pattern is invalidated if price breaks before breakout: Candle 5 (default) or Candle 4 (doji). | Breakout |
InpStopLossMode |
ENUM | SL_MODE_LOWER_OF_BOTH | 4 modes available | Stop loss placement strategy: C5 extreme, doji extreme, lower of both, or higher of both extremes. | Risk |
InpStopLossPipAdjustment |
double | 0.0 | -10.0 - 10.0 | Pip adjustment to stop loss placement: positive values move SL away from price, negative values move SL closer to price. | Risk |
InpRiskReward |
double | 2.0 | 1.0 - 5.0 | Risk-reward ratio for take profit calculation (1:2 means TP distance is twice SL distance). | Risk |
InpRiskPercent |
double | 1.0 | 0.1 - 5.0 | Percentage of account balance to risk per trade. | Risk |
InpMagicNumber |
int | 345678 | Any integer | Unique identifier for trades placed by this EA (allows multiple EAs to run simultaneously). | Risk |
InpTradeComment |
string | 3+Doji+1_EA | Any string | Comment added to all trades for identification purposes. | Risk |
InpShowDebug |
bool | true | true/false | Enables detailed logging of pattern detection process and trade execution to Experts tab. | Display |
InpShowLabels |
bool | true | true/false | Enables visual labeling of pattern candles on the chart (C1, C2, C3, Doji, C5). | Display |
InpMaxLabelsToKeep |
int | 20 | 5 - 100 | Maximum number of pattern labels to maintain on the chart to prevent visual clutter. | Display |
Core pattern detection parameters including candle size requirements, doji characteristics, and ATR settings.
Risk management parameters including stop loss placement, position sizing, and trade identification settings.
Breakout confirmation parameters including wait periods and invalidation levels.
Visual display parameters for chart labeling and debugging information.
Comprehensive backtesting and live trading results
Three Plus Doji Pattern Strategy Performance (Jan 2023 - Dec 2025)
| Performance Metric | Value |
|---|---|
| 📊 Overall Performance | |
| Total Trades | 342 |
| Winning Trades | 197 |
| Losing Trades | 145 |
| Win Rate | 57.6% |
| Break-Even Trades | 0 |
| 💰 Profitability | |
| Net Profit | $68,420 |
| Gross Profit | $118,200 |
| Gross Loss | -$49,780 |
| Profit Factor | 2.37 |
| Expected Payoff | $200.06 |
| Return on Account | 68.4% |
| ⚠️ Risk Metrics | |
| Max Drawdown | -$8,240 |
| Max Drawdown % | -8.2% |
| Recovery Factor | 8.30 |
| Sharpe Ratio | 2.21 |
| Sortino Ratio | 2.74 |
| Calmar Ratio | 8.30 |
| Risk of Ruin | 0.00% |
| 📈 Trade Analysis | |
| Average Win | $599.49 |
| Average Loss | -$343.31 |
| Largest Win | $2,480 |
| Largest Loss | -$720 |
| Average Trade Duration | 14.6 hours |
| Max Consecutive Wins | 8 |
| Max Consecutive Losses | 5 |
| Average Consecutive Wins | 2.9 |
| Average Consecutive Losses | 2.0 |
| 🎯 Pattern Analysis | |
| Total Doji Patterns Detected | 486 |
| Three-Plus-Doji Formations | 342 (70.4%) |
| Pattern Recognition Rate | 100% |
| Bullish Formation Success | 61.2% |
| Bearish Formation Success | 53.8% |
| Trend Reversal Confirmation | 67.4% |
| 📅 Monthly Performance (2025) | |
| Best Month | +$9,840 (March) |
| Worst Month | -$1,240 (September) |
| Average Monthly Profit | $2,456 |
| Profitable Months | 10 / 12 |
| Month Win Rate | 83.3% |
⚠️ Backtesting Disclaimer: Past performance is not indicative of future results. These results are based on historical backtesting and may not reflect actual trading outcomes. Live trading involves real market conditions, slippage, and execution delays that cannot be fully simulated in backtests. Always use proper risk management and demo trade before using real capital.
Copy the EA file to your MetaTrader 5 installation directory:
C:\Users\[YourUsername]\AppData\Roaming\MetaQuotes\Terminal\[BrokerID]\MQL5\Experts\
Right-click in the Navigator window of MT5 and select "Refresh" to see the EA appear in the Expert Advisors list. Alternatively, restart the MT5 platform.
Click the "Algo Trading" button in the MT5 toolbar (or press Ctrl+E) to enable automated trading. The button should turn green when enabled.
A smiley face icon 😊 in the top-right corner of the chart indicates the EA is properly attached and running. If you see a sad face ☹️, check the Experts tab for error messages.
Double-click the EA name (Three_Plus_Doji_Plus_One) in the top-left corner of the chart to open the properties dialog.
| Parameter | Conservative | Moderate | Aggressive |
|---|---|---|---|
InpRiskPercent |
0.5% | 1.0% | 2.0% |
InpRiskReward |
2.5 | 2.0 | 1.5 |
InpMaxBreakoutWait |
3 | 5 | 8 |
InpStopLossMode |
SL_MODE_LOWER_OF_BOTH | SL_MODE_LOWER_OF_BOTH | SL_MODE_LAST_CANDLE |
| Platform | MetaTrader 5 |
| MQL Version | MQL5 (Build 2600+) |
| Type | Expert Advisor |
| License | Custom EA (KeyAlgos) |
| Primary Symbol | XAUUSD (Gold) |
| Timeframe | M1 (1-minute) |
| Trade Direction | Long and Short |
| Execution Mode | OnTick (with bar completion checks) |
| Min Balance | $500 (recommended) |
| Account Type | Standard, ECN compatible |
| Leverage | 1:100 or higher recommended |
| Margin Currency | USD |
| Lines of Code | ~1,200 |
| Custom Functions | 15+ |
| External Indicators | iATR (built-in) |
| Complexity | Advanced |
Fully compatible with standard MetaTrader 5 accounts with Gold trading permission
Works with ECN and STP account types, but may require spread filters
Auto-adapts to 4 or 5 digit broker quotes for XAUUSD
For 24/7 operation on XAUUSD, VPS hosting is highly recommended
Trading involves substantial risk of loss and may not be suitable for all investors.
Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange, you should carefully consider your investment objectives, level of experience, and risk appetite. There is a possibility that you could sustain a loss of some or all of your initial investment. Therefore, you should not invest money that you cannot afford to lose.
The Three+Doji+1 Pattern EA is an algorithmic trading tool designed to identify specific candlestick patterns and execute trades based on predefined criteria. It does not guarantee profits or success. Past performance results, whether from backtesting or live trading, do not guarantee future results. Different market conditions, broker execution speeds, slippage, and other factors can significantly affect performance.
You are fully responsible for all trading decisions made using this EA, including:
KeyAlgos provides this Expert Advisor "as is" without any warranties, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or non-infringement. We do not guarantee that the EA will be error-free, uninterrupted, or that it will meet your requirements.
Ready to enhance your trading? Contact us for support and inquiries.