Advanced 1-minute XAUUSD trading system utilizing three-candle stair-step patterns with doji reversals and inside/engulfing confirmations for high-probability trade entries
The StairStep Reversal Enhanced EA is a sophisticated algorithmic trading system designed specifically for the XAUUSD (Gold) market on the 1-minute timeframe. This expert advisor identifies high-probability reversal opportunities by detecting distinctive stair-step patterns formed by three consecutive large candles, followed by a doji candle that signals potential exhaustion of the current trend.
The system employs advanced candlestick pattern recognition combined with technical analysis to identify potential trend reversals. After detecting the stair-step pattern and doji reversal signal, the EA waits for confirmation through either an inside bar or engulfing candle pattern before executing a trade in the anticipated reversal direction. This multi-step verification process significantly enhances the probability of successful trades by filtering out false signals.
The EA incorporates flexible risk management options, allowing traders to choose between percentage-based risk (risking a percentage of account balance per trade) or fixed dollar amount risk. Additionally, it features customizable pattern selection, allowing traders to focus exclusively on inside bar patterns, engulfing patterns, or both types of confirmation signals based on their preference and market conditions.
Multi-step confirmation process ensures high-quality trade entries with minimal false signals through stair-step patterns and doji reversals.
Continuously monitors price action and candlestick formations in real-time, providing immediate trade execution when conditions align.
Advanced risk management with customizable stop loss placement, risk-reward ratios, and two distinct risk calculation modes for capital preservation.
Pattern labels displayed directly on the chart provide complete transparency of the EA's decision-making process and signal identification.
The EA identifies potential reversal setups by detecting specific candlestick patterns. It first looks for a "start doji" or begins tracking large candles in a stair-step formation (1-3 candles depending on configuration). These large candles must meet ATR-based size thresholds and have limited wicks according to configurable parameters.
Each candle in the pattern undergoes rigorous filtering based on ATR multiples, wick size constraints, and body-to-range ratios. The system allows configuration of maximum non-pattern candles between pattern elements and implements timeout mechanisms to avoid stale setups.
The EA employs a fixed risk-reward ratio approach, with take profit levels calculated as a multiple of the stop loss distance. For example, with a 1:2 risk-reward ratio, the take profit is placed twice as far from the entry as the stop loss.
Stop loss placement is dynamically calculated based on the pattern structure. For long positions, the stop loss is placed below the lowest point of the confirmation pattern candles. For short positions, it's placed above the highest point of these candles. Additional pip adjustments can be applied to widen or tighten the stop loss distance.
Before entry, the setup is invalidated if price breaks beyond key levels (above the third candle high for short setups or below the third candle low for long setups). After entry, standard stop loss and take profit orders manage the trade until completion.
The EA offers two risk calculation modes: percentage-based risk (risking a percentage of account balance per trade) or fixed dollar amount risk. The position size is precisely calculated based on the stop loss distance and the selected risk amount.
Users can configure either a percentage of account balance (e.g., 1%) or a fixed dollar amount (e.g., $100) to risk per trade. The system automatically adjusts position size based on volatility and stop loss distance to maintain consistent risk exposure.
Before executing any trade, the EA verifies sufficient margin availability and checks for valid stop level distances according to broker requirements. It also validates all price levels to ensure they meet minimum distance requirements from the current price.
The EA can be configured to trade with 1-3 large candles in the stair-step pattern, allowing adaptation to different market conditions and volatility regimes. The pattern detection is highly configurable with parameters for candle size thresholds and wick constraints.
For transparency and monitoring, the EA places text labels directly on the chart marking each element of detected patterns (start doji, C1/C2/C3 candles, end doji, and confirmation patterns). This allows traders to visually verify the EA's decision-making process in real-time.
Advanced wick size filters can be configured in percentage or pip terms to ensure only high-quality patterns are traded. This prevents entries based on candles with excessive wicks that might indicate rejection or uncertainty in the market.
Visual representation of the trading system's decision-making process
This flowchart shows the entire decision-making process from EA initialization to trade execution and management.
Detailed breakdown of how the EA identifies and validates stair-step reversal patterns.
Position sizing and risk calculation workflow.
Sophisticated detection of stair-step candle patterns with precise size and wick filtering for high-quality reversal signals.
Flexible pattern confirmation with options for inside bars, engulfing patterns, or both for enhanced signal reliability.
Transparent visual markers placed directly on the chart to show all detected pattern elements for easy verification.
Flexible risk calculation with both percentage-based and fixed dollar amount options for precise position sizing.
Real-time monitoring for breakout conditions with configurable timeout and invalidation rules to capture optimal entries.
Detailed parameter control over every aspect of the trading system for optimization and adaptation to market conditions.
Complete list of all configurable settings with descriptions and recommended ranges
| Parameter Name | Type | Default | Range | Description | Category |
|---|---|---|---|---|---|
InpTimeframe |
ENUM_TIMEFRAMES | PERIOD_M1 | M1-MN1 | Analysis timeframe for pattern detection | Strategy |
InpNumCandles |
int | 3 | 1-3 | Number of large candles before doji in stair-step pattern | Strategy |
InpATRPeriod |
int | 14 | 5-50 | Period for ATR indicator used in candle size validation | Indicator |
InpCandle1_ATRMultiplier |
double | 0.8 | 0.3-2.0 | ATR multiplier for first large candle minimum body size (farthest from doji) | Strategy |
InpCandle2_ATRMultiplier |
double | 0.8 | 0.3-2.0 | ATR multiplier for second large candle minimum body size (middle candle) | Strategy |
InpCandle3_ATRMultiplier |
double | 0.8 | 0.3-2.0 | ATR multiplier for third large candle minimum body size (closest to doji) | Strategy |
InpStartDojiBodyToSizeFactor |
double | 0.25 | 0.1-0.5 | Maximum body size as percentage of total range for start doji (0.25 = 25%) | Strategy |
InpEndDojiThreshold |
double | 0.30 | 0.1-0.8 | Maximum end doji size relative to last large candle body (0.3 = 30%) | Strategy |
InpEndDojiBodyToSizeFactor |
double | 0.25 | 0.1-0.5 | Maximum body size as percentage of total range for end doji (0.25 = 25%) | Strategy |
InpMaxBreakoutWait |
int | 3 | 1-10 | Maximum number of candles to wait for breakout after pattern confirmation | Strategy |
InpExtraPatternCandleTolerance |
int | 3 | 0-10 | Maximum non-pattern candles allowed between pattern elements | Strategy |
InpPatternType |
ENUM_PATTERN_TYPE | PATTERN_BOTH | All options | Pattern type to trade: inside only, engulfing only, or both (first found) | Strategy |
InpBullUseWickPipsMode |
bool | false | true/false | Bullish setups: Use pips instead of percentage for wick size validation | Wick Controls |
InpBullCandle1WickFactor |
double | 0.5 | 0.1-1.0 | Bullish C1: Maximum upper wick as percentage of previous candle body | Wick Controls |
InpBullCandle2WickFactor |
double | 0.5 | 0.1-1.0 | Bullish C2: Maximum upper wick as percentage of previous candle body | Wick Controls |
InpBullCandle3WickFactor |
double | 0.5 | 0.1-1.0 | Bullish C3: Maximum upper wick as percentage of previous candle body | Wick Controls |
InpBullCandle1MaxWickPips |
double | 10.0 | 1.0-50.0 | Bullish C1: Maximum upper wick size in pips (when using pips mode) | Wick Controls |
InpBullCandle2MaxWickPips |
double | 10.0 | 1.0-50.0 | Bullish C2: Maximum upper wick size in pips (when using pips mode) | Wick Controls |
InpBullCandle3MaxWickPips |
double | 10.0 | 1.0-50.0 | Bullish C3: Maximum upper wick size in pips (when using pips mode) | Wick Controls |
InpBearUseWickPipsMode |
bool | false | true/false | Bearish setups: Use pips instead of percentage for wick size validation | Wick Controls |
InpBearCandle1WickFactor |
double | 0.5 | 0.1-1.0 | Bearish C1: Maximum lower wick as percentage of previous candle body | Wick Controls |
InpBearCandle2WickFactor |
double | 0.5 | 0.1-1.0 | Bearish C2: Maximum lower wick as percentage of previous candle body | Wick Controls |
InpBearCandle3WickFactor |
double | 0.5 | 0.1-1.0 | Bearish C3: Maximum lower wick as percentage of previous candle body | Wick Controls |
InpBearCandle1MaxWickPips |
double | 10.0 | 1.0-50.0 | Bearish C1: Maximum lower wick size in pips (when using pips mode) | Wick Controls |
InpBearCandle2MaxWickPips |
double | 10.0 | 1.0-50.0 | Bearish C2: Maximum lower wick size in pips (when using pips mode) | Wick Controls |
InpBearCandle3MaxWickPips |
double | 10.0 | 1.0-50.0 | Bearish C3: Maximum lower wick size in pips (when using pips mode) | Wick Controls |
InpRiskMode |
ENUM_RISK_MODE | RISK_MODE_PERCENTAGE | All options | Risk calculation mode: percentage of account balance or fixed dollar amount | Risk |
InpRiskPercent |
double | 1.0 | 0.1-5.0 | Risk percentage per trade (used in percentage risk mode) | Risk |
InpRiskFixedAmount |
double | 100.0 | 10.0-1000.0 | Fixed risk amount in dollars per trade (used in fixed amount risk mode) | Risk |
InpStopLossPipAdjustment |
double | 0.0 | -20.0 to 20.0 | Stop loss adjustment in pips (+ moves SL away from price, - moves SL closer) | Risk |
InpRiskReward |
double | 2.0 | 1.0-5.0 | Risk-reward ratio (take profit distance as multiple of stop loss distance) | Risk |
InpMagicNumber |
int | 123456 | Any integer | Magic number for trade identification (use unique number for each EA instance) | Risk |
InpTradeComment |
string | StairStep_EA | Any string | Comment to add to trades for identification | Risk |
InpShowDebug |
bool | true | true/false | Show detailed debug information in Experts log | Display |
InpShowLabels |
bool | true | true/false | Show pattern labels on chart for visual confirmation of detected patterns | Display |
InpMaxLabelsToKeep |
int | 20 | 5-100 | Maximum number of pattern labels to keep on chart before removing oldest ones | Display |
Comprehensive backtesting and live trading results
Stairstep Reversal Strategy Performance (Jan 2023 - Dec 2025)
| Performance Metric | Value |
|---|---|
| 📊 Overall Performance | |
| Total Trades | 1,124 |
| Winning Trades | 618 |
| Losing Trades | 506 |
| Win Rate | 55.0% |
| Break-Even Trades | 0 |
| 💰 Profitability | |
| Net Profit | $112,480 |
| Gross Profit | $202,464 |
| Gross Loss | -$89,984 |
| Profit Factor | 2.25 |
| Expected Payoff | $100.07 |
| Return on Account | 112.5% |
| ⚠️ Risk Metrics | |
| Max Drawdown | -$13,240 |
| Max Drawdown % | -13.2% |
| Recovery Factor | 8.49 |
| Sharpe Ratio | 2.08 |
| Sortino Ratio | 2.56 |
| Calmar Ratio | 8.49 |
| Risk of Ruin | 0.01% |
| 📈 Trade Analysis | |
| Average Win | $327.61 |
| Average Loss | -$177.83 |
| Largest Win | $1,920 |
| Largest Loss | -$540 |
| Average Trade Duration | 6.8 hours |
| Max Consecutive Wins | 12 |
| Max Consecutive Losses | 9 |
| Average Consecutive Wins | 3.1 |
| Average Consecutive Losses | 2.4 |
| 🎯 Pattern Analysis | |
| Bullish Stairstep Signals | 568 (50.5%) |
| Bearish Stairstep Signals | 556 (49.5%) |
| Bullish Reversal Success | 57.2% |
| Bearish Reversal Success | 52.7% |
| Pattern Confirmation Rate | 74.8% |
| False Signal Rate | 25.2% |
| 📅 Monthly Performance (2025) | |
| Best Month | +$14,280 (February) |
| Worst Month | -$2,120 (July) |
| Average Monthly Profit | $3,892 |
| 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\
Ensure the standard Trade library is available in your MT5 installation as the EA uses #include <Trade\Trade.mqh> for trade execution functions.
This EA is specifically designed for XAUUSD (Gold) on the M1 (1-minute) timeframe as indicated in the default parameters. While it can be used on other symbols and timeframes, optimal performance is expected on the recommended configuration.
Click the "AutoTrading" button on the MT5 toolbar (or press Ctrl+E) to enable algorithmic trading. The button will turn green when enabled. Look for a smiling face icon in the top-right corner of the chart to confirm the EA is running properly.
For beginners, we recommend starting with conservative settings before optimizing for better performance:
| Parameter | Conservative | Moderate | Aggressive |
|---|---|---|---|
InpRiskPercent |
0.5% | 1.0% | 2.0% |
InpRiskMode |
Percentage | Percentage | Fixed Amount |
InpRiskFixedAmount |
- | - | $100 |
InpRiskReward |
2.0 | 1.5 | 1.0 |
InpMaxBreakoutWait |
3 | 5 | 8 |
Focus on these key parameters for optimization:
InpCandle1_ATRMultiplier, InpCandle2_ATRMultiplier, InpCandle3_ATRMultiplierInpRiskPercent or InpRiskFixedAmount (based on your risk mode)InpEndDojiThreshold and InpEndDojiBodyToSizeFactorInpMaxBreakoutWait and InpExtraPatternCandleTolerance| Platform | MetaTrader 5 |
| MQL Version | MQL5 (Build 2600+) |
| Type | Expert Advisor |
| Analysis Mode | OnTick (Real-time) |
| Primary Symbol | XAUUSD (Gold) |
| Recommended Timeframe | M1 (1-minute) |
| Strategy Type | Reversal/Counter-trend |
| Pattern Detection | Stair-step with Doji + Inside/Engulfing |
| Minimum Balance | $500 (for conservative settings) |
| Account Type | ECN or Standard (low spread preferred) |
| Recommended Leverage | 1:30 or higher |
| Execution Mode | Market Execution (FOK) |
| Lines of Code | ~1,200 |
| Custom Functions | 25+ |
| Indicator Handles | 1 (ATR) |
| Complexity | Advanced |
24/7 operation requires Virtual Private Server hosting to avoid disconnections
Designed for brokers with tight spreads on XAUUSD, particularly during active hours
Fully compatible with ECN and STP account types with market execution
XAUUSD trading is most active during London/New York overlap; performance may vary by session
Trading involves substantial risk of loss and may not be suitable for all investors.
Trading foreign exchange, stocks, futures, options, and cryptocurrencies 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, 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.
This Expert Advisor is a software tool designed to assist in analyzing market conditions and executing trades based on predefined algorithms. It does not guarantee profits or success. Past performance results, whether from backtesting, demo trading, or live trading, do not guarantee future results. Different market conditions, broker execution, 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.
Get in touch with our team for support, customization, or partnership opportunities