OPEN-SOURCE SCRIPT
CandleStick Detector - Advisor

MARKET ADVISOR — Candlestick Pattern Detection + Plain English Analysis
════════════════════════════════════════
WHAT THIS DOES
════════════════════════════════════════
Market Advisor reads price action in real time and explains what it sees in plain English — like having a trading friend beside you. Instead of showing 10 indicators and leaving you to figure it out, this script detects key candlestick formations, marks them on the chart, identifies the current trend structure, and tells you exactly what the pattern means in context.
No signals. No buy/sell arrows. No false promises.
Just honest pattern recognition and plain language analysis.
════════════════════════════════════════
HOW IT WORKS — THE LOGIC
════════════════════════════════════════
The script runs three engines simultaneously:
1. CANDLE MATH ENGINE
Every bar, the script calculates:
- Body size: math.abs(close - open)
- Full range: high - low
- Upper wick: high - max(close, open)
- Lower wick: min(close, open) - low
- Body percentage: bodySize / fullRange
These ratios are used to classify candle formations without ambiguity.
2. PATTERN DETECTION ENGINE
Eight patterns are detected using strict mathematical conditions:
- Bullish Engulfing: Current bar is bullish, previous was bearish, current body fully covers previous body, current body is larger.
- Bearish Engulfing: Opposite of above. Current bar is bearish, fully covers previous bullish body.
- Hammer: Lower wick is at least 2x the body size. Upper wick is less than 0.5x body. Body percentage under 45%. Shows price was pushed down then rejected.
- Shooting Star: Upper wick is at least 2x body. Lower wick under 0.5x body. Body percentage under 45%. Shows price was pushed up then rejected.
- Doji: Body percentage under 8% of the full range. Buyers and sellers ended equal.
- Inside Bar: Current high is below previous high AND current low is above previous low. Price is compressing inside the prior candle.
- Morning Star: 3-bar pattern. Bar 2 ago is bearish. Middle bar (1 ago) has a tiny body (under 25% of range). Current bar is bullish and closes above the midpoint of bar 2.
- Evening Star: 3-bar pattern. Bar 2 ago is bullish. Middle bar has tiny body. Current bar is bearish and closes below midpoint of bar 2.
3. MARKET STRUCTURE ENGINE
Uses pivot highs and lows (ta.pivothigh / ta.pivotlow) to identify:
- Uptrend: Current pivot high > previous pivot high AND current pivot low > previous pivot low (Higher Highs, Higher Lows)
- Downtrend: Current pivot high < previous pivot high AND current pivot low < previous pivot low (Lower Highs, Lower Lows)
- Ranging: Neither condition met
The structure context changes the advisor text. A Hammer in an uptrend gets different advice than a Hammer in a downtrend. Same pattern, different meaning.
════════════════════════════════════════
WHAT APPEARS ON CHART
════════════════════════════════════════
- Engulfing patterns → shaded box spanning both candles
- Hammers / Shooting Stars → small label above or below the candle
- Inside Bars → golden shaded box covering both candles
- Doji → small label
- Morning / Evening Star → label on the third candle
- Swing levels → dotted horizontal lines at pivot highs and lows
════════════════════════════════════════
THE ADVISOR PANEL
════════════════════════════════════════
A panel in the corner shows:
- Current market structure (Uptrend / Downtrend / Ranging)
- Most recent pattern detected
- Line 1: What happened (factual description)
- Line 2: What it means in context of the trend
- Line 3: What to watch for next
The panel retains the last detected pattern until a new one forms. On bars with no pattern it reads "Watching market..." so you always know the script is active.
════════════════════════════════════════
SETTINGS
════════════════════════════════════════
Toggle each pattern type on or off independently. Swing Sensitivity controls how many bars left and right are used to validate a pivot — higher values find stronger, less frequent swings. Panel position can be moved to any corner.
════════════════════════════════════════
ALERTS
════════════════════════════════════════
8 alert conditions available:
Bullish Engulfing, Bearish Engulfing, Hammer, Shooting Star, Morning Star, Evening Star, Inside Bar, Doji.
Set alerts via the TradingView alert menu after adding to chart.
════════════════════════════════════════
IMPORTANT DISCLAIMER
════════════════════════════════════════
This script is an educational tool. It identifies and labels candlestick patterns based on mathematical price relationships. It does not predict future price movement. Candlestick patterns are observations of past price behaviour — they show what buyers and sellers did, not what they will do.
No pattern has a 100% success rate. Always use proper risk management. This is not financial advice.
Past performance of any pattern does not guarantee future results.
════════════════════════════════════════
CREDITS
════════════════════════════════════════
Built entirely in Pine Script v6.
Pattern logic based on standard candlestick theory (Japanese candlestick charting techniques).
No external libraries used.
════════════════════════════════════════
WHAT THIS DOES
════════════════════════════════════════
Market Advisor reads price action in real time and explains what it sees in plain English — like having a trading friend beside you. Instead of showing 10 indicators and leaving you to figure it out, this script detects key candlestick formations, marks them on the chart, identifies the current trend structure, and tells you exactly what the pattern means in context.
No signals. No buy/sell arrows. No false promises.
Just honest pattern recognition and plain language analysis.
════════════════════════════════════════
HOW IT WORKS — THE LOGIC
════════════════════════════════════════
The script runs three engines simultaneously:
1. CANDLE MATH ENGINE
Every bar, the script calculates:
- Body size: math.abs(close - open)
- Full range: high - low
- Upper wick: high - max(close, open)
- Lower wick: min(close, open) - low
- Body percentage: bodySize / fullRange
These ratios are used to classify candle formations without ambiguity.
2. PATTERN DETECTION ENGINE
Eight patterns are detected using strict mathematical conditions:
- Bullish Engulfing: Current bar is bullish, previous was bearish, current body fully covers previous body, current body is larger.
- Bearish Engulfing: Opposite of above. Current bar is bearish, fully covers previous bullish body.
- Hammer: Lower wick is at least 2x the body size. Upper wick is less than 0.5x body. Body percentage under 45%. Shows price was pushed down then rejected.
- Shooting Star: Upper wick is at least 2x body. Lower wick under 0.5x body. Body percentage under 45%. Shows price was pushed up then rejected.
- Doji: Body percentage under 8% of the full range. Buyers and sellers ended equal.
- Inside Bar: Current high is below previous high AND current low is above previous low. Price is compressing inside the prior candle.
- Morning Star: 3-bar pattern. Bar 2 ago is bearish. Middle bar (1 ago) has a tiny body (under 25% of range). Current bar is bullish and closes above the midpoint of bar 2.
- Evening Star: 3-bar pattern. Bar 2 ago is bullish. Middle bar has tiny body. Current bar is bearish and closes below midpoint of bar 2.
3. MARKET STRUCTURE ENGINE
Uses pivot highs and lows (ta.pivothigh / ta.pivotlow) to identify:
- Uptrend: Current pivot high > previous pivot high AND current pivot low > previous pivot low (Higher Highs, Higher Lows)
- Downtrend: Current pivot high < previous pivot high AND current pivot low < previous pivot low (Lower Highs, Lower Lows)
- Ranging: Neither condition met
The structure context changes the advisor text. A Hammer in an uptrend gets different advice than a Hammer in a downtrend. Same pattern, different meaning.
════════════════════════════════════════
WHAT APPEARS ON CHART
════════════════════════════════════════
- Engulfing patterns → shaded box spanning both candles
- Hammers / Shooting Stars → small label above or below the candle
- Inside Bars → golden shaded box covering both candles
- Doji → small label
- Morning / Evening Star → label on the third candle
- Swing levels → dotted horizontal lines at pivot highs and lows
════════════════════════════════════════
THE ADVISOR PANEL
════════════════════════════════════════
A panel in the corner shows:
- Current market structure (Uptrend / Downtrend / Ranging)
- Most recent pattern detected
- Line 1: What happened (factual description)
- Line 2: What it means in context of the trend
- Line 3: What to watch for next
The panel retains the last detected pattern until a new one forms. On bars with no pattern it reads "Watching market..." so you always know the script is active.
════════════════════════════════════════
SETTINGS
════════════════════════════════════════
Toggle each pattern type on or off independently. Swing Sensitivity controls how many bars left and right are used to validate a pivot — higher values find stronger, less frequent swings. Panel position can be moved to any corner.
════════════════════════════════════════
ALERTS
════════════════════════════════════════
8 alert conditions available:
Bullish Engulfing, Bearish Engulfing, Hammer, Shooting Star, Morning Star, Evening Star, Inside Bar, Doji.
Set alerts via the TradingView alert menu after adding to chart.
════════════════════════════════════════
IMPORTANT DISCLAIMER
════════════════════════════════════════
This script is an educational tool. It identifies and labels candlestick patterns based on mathematical price relationships. It does not predict future price movement. Candlestick patterns are observations of past price behaviour — they show what buyers and sellers did, not what they will do.
No pattern has a 100% success rate. Always use proper risk management. This is not financial advice.
Past performance of any pattern does not guarantee future results.
════════════════════════════════════════
CREDITS
════════════════════════════════════════
Built entirely in Pine Script v6.
Pattern logic based on standard candlestick theory (Japanese candlestick charting techniques).
No external libraries used.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.