OPEN-SOURCE SCRIPT
Long-Leg Doji Breakout Strategy

The Long-Leg Doji Breakout Strategy is a sophisticated technical analysis approach that capitalizes on market psychology and price action patterns.
Core Concept: The strategy identifies Long-Leg Doji candlestick patterns, which represent periods of extreme market indecision where buyers and sellers are in equilibrium. These patterns often precede significant price movements as the market resolves this indecision.
Pattern Recognition: The algorithm uses strict mathematical criteria to identify authentic Long-Leg Doji patterns. It requires the candle body to be extremely small (≤0.1% of the total range) while having long wicks on both sides (at least 2x the body size). An ATR filter ensures the pattern is significant relative to recent volatility.
Trading Logic: Once a Long-Leg Doji is identified, the strategy enters a "waiting mode," monitoring for a breakout above the doji's high (long signal) or below its low (short signal). This confirmation approach reduces false signals by ensuring the market has chosen a direction.
Risk Management: The strategy allocates 10% of equity per trade and uses a simple moving average crossover for exits. Visual indicators help traders understand the pattern identification and trade execution process.
Psychological Foundation: The strategy exploits the natural market cycle where uncertainty (represented by the doji) gives way to conviction (the breakout), creating high-probability trading opportunities.
The strength of this approach lies in its ability to identify moments when market sentiment shifts from confusion to clarity, providing traders with well-defined entry and exit points while maintaining proper risk management protocols.
How It Works
The strategy operates on a simple yet powerful principle: identify periods of market indecision, then trade the subsequent breakout when the market chooses direction.
Step 1: Pattern Detection
The algorithm scans for Long-Leg Doji candles, which have three key characteristics:
Tiny body (open and close prices nearly equal)
Long upper wick (significant rejection of higher prices)
Long lower wick (significant rejection of lower prices)
Step 2: Confirmation Wait
Once a doji is detected, the strategy doesn't immediately trade. Instead, it marks the high and low of that candle and waits for a definitive breakout.
Step 3: Trade Execution
Long Entry: When price closes above the doji's high
Short Entry: When price closes below the doji's low
Step 4: Exit Strategy
Positions are closed when price crosses back through a 20-period moving average, indicating potential trend reversal.
Market Psychology Behind It
A Long-Leg Doji represents a battlefield between bulls and bears that ends in a stalemate. The long wicks show that both sides tried to push price in their favor but failed. This creates a coiled spring effect - when one side finally gains control, the move can be explosive as trapped traders rush to exit and momentum traders jump aboard.
Key Parameters
Doji Body Threshold (0.1%): Ensures the body is truly small relative to the candle's range
Wick Ratio (2.0): Both wicks must be at least twice the body size
ATR Filter: Uses Average True Range to ensure the pattern is significant in current market conditions
Position Size: 10% of equity per trade for balanced risk management
Pros:
High Probability Setups: Doji patterns at key levels often lead to significant moves as they represent genuine shifts in market sentiment.
Clear Rules: Objective criteria for entry and exit eliminate emotional decision-making and provide consistent execution.
Risk Management: Built-in position sizing and exit rules help protect capital during losing trades.
Market Neutral: Works equally well for long and short positions, adapting to market direction rather than fighting it.
Visual Confirmation: The strategy provides clear visual cues, making it easy to understand when patterns are forming and trades are triggered.
Cons:
False Breakouts: In choppy or ranging markets, price may break the doji levels only to quickly reverse, creating whipsaws.
Patience Required: Traders must wait for both pattern formation and breakout confirmation, which can test discipline during active market periods.
Simple Exit Logic: The moving average exit may be too simplistic, potentially cutting profits short during strong trends or holding losers too long during reversals.
Volatility Dependent: The strategy relies on sufficient volatility to create meaningful doji patterns - it may underperform in extremely quiet markets.
Lagging Entries: Waiting for breakout confirmation means missing the very beginning of moves, reducing potential profit margins.
Best Market Conditions
The strategy performs optimally during periods of moderate volatility when markets are making genuine directional decisions rather than just random noise. It works particularly well around key support/resistance levels where the market's indecision is most meaningful.
Optimization Considerations
Consider combining with additional confluence factors like volume analysis, support/resistance levels, or other technical indicators to improve signal quality. The exit strategy could also be enhanced with trailing stops or multiple profit targets to better capture extended moves while protecting gains.
Best for Index option,
Enjoy !!
Core Concept: The strategy identifies Long-Leg Doji candlestick patterns, which represent periods of extreme market indecision where buyers and sellers are in equilibrium. These patterns often precede significant price movements as the market resolves this indecision.
Pattern Recognition: The algorithm uses strict mathematical criteria to identify authentic Long-Leg Doji patterns. It requires the candle body to be extremely small (≤0.1% of the total range) while having long wicks on both sides (at least 2x the body size). An ATR filter ensures the pattern is significant relative to recent volatility.
Trading Logic: Once a Long-Leg Doji is identified, the strategy enters a "waiting mode," monitoring for a breakout above the doji's high (long signal) or below its low (short signal). This confirmation approach reduces false signals by ensuring the market has chosen a direction.
Risk Management: The strategy allocates 10% of equity per trade and uses a simple moving average crossover for exits. Visual indicators help traders understand the pattern identification and trade execution process.
Psychological Foundation: The strategy exploits the natural market cycle where uncertainty (represented by the doji) gives way to conviction (the breakout), creating high-probability trading opportunities.
The strength of this approach lies in its ability to identify moments when market sentiment shifts from confusion to clarity, providing traders with well-defined entry and exit points while maintaining proper risk management protocols.
How It Works
The strategy operates on a simple yet powerful principle: identify periods of market indecision, then trade the subsequent breakout when the market chooses direction.
Step 1: Pattern Detection
The algorithm scans for Long-Leg Doji candles, which have three key characteristics:
Tiny body (open and close prices nearly equal)
Long upper wick (significant rejection of higher prices)
Long lower wick (significant rejection of lower prices)
Step 2: Confirmation Wait
Once a doji is detected, the strategy doesn't immediately trade. Instead, it marks the high and low of that candle and waits for a definitive breakout.
Step 3: Trade Execution
Long Entry: When price closes above the doji's high
Short Entry: When price closes below the doji's low
Step 4: Exit Strategy
Positions are closed when price crosses back through a 20-period moving average, indicating potential trend reversal.
Market Psychology Behind It
A Long-Leg Doji represents a battlefield between bulls and bears that ends in a stalemate. The long wicks show that both sides tried to push price in their favor but failed. This creates a coiled spring effect - when one side finally gains control, the move can be explosive as trapped traders rush to exit and momentum traders jump aboard.
Key Parameters
Doji Body Threshold (0.1%): Ensures the body is truly small relative to the candle's range
Wick Ratio (2.0): Both wicks must be at least twice the body size
ATR Filter: Uses Average True Range to ensure the pattern is significant in current market conditions
Position Size: 10% of equity per trade for balanced risk management
Pros:
High Probability Setups: Doji patterns at key levels often lead to significant moves as they represent genuine shifts in market sentiment.
Clear Rules: Objective criteria for entry and exit eliminate emotional decision-making and provide consistent execution.
Risk Management: Built-in position sizing and exit rules help protect capital during losing trades.
Market Neutral: Works equally well for long and short positions, adapting to market direction rather than fighting it.
Visual Confirmation: The strategy provides clear visual cues, making it easy to understand when patterns are forming and trades are triggered.
Cons:
False Breakouts: In choppy or ranging markets, price may break the doji levels only to quickly reverse, creating whipsaws.
Patience Required: Traders must wait for both pattern formation and breakout confirmation, which can test discipline during active market periods.
Simple Exit Logic: The moving average exit may be too simplistic, potentially cutting profits short during strong trends or holding losers too long during reversals.
Volatility Dependent: The strategy relies on sufficient volatility to create meaningful doji patterns - it may underperform in extremely quiet markets.
Lagging Entries: Waiting for breakout confirmation means missing the very beginning of moves, reducing potential profit margins.
Best Market Conditions
The strategy performs optimally during periods of moderate volatility when markets are making genuine directional decisions rather than just random noise. It works particularly well around key support/resistance levels where the market's indecision is most meaningful.
Optimization Considerations
Consider combining with additional confluence factors like volume analysis, support/resistance levels, or other technical indicators to improve signal quality. The exit strategy could also be enhanced with trailing stops or multiple profit targets to better capture extended moves while protecting gains.
Best for Index option,
Enjoy !!
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.