OPEN-SOURCE SCRIPT
업데이트됨 Candlestick Patterns

Title: Candlestick Patterns
Description:
Detects and labels 15 classic Japanese candlestick patterns in real time, with a multi-timeframe trend filter that highlights which signals align with the prevailing trend direction.
Patterns detected
Single-candle patterns: Doji, Hammer, Hanging Man, Inverted Hammer, Shooting Star.
Two-candle patterns: Bullish Engulfing, Bearish Engulfing, Bullish Harami, Bearish Harami, Piercing Line, Dark Cloud Cover.
Three-candle patterns: Morning Star, Evening Star, Three White Soldiers, Three Black Crows.
Pattern logic
Candle anatomy is computed from body, upper wick, lower wick, and full range on each bar. The wick-to-body ratio threshold is configurable — default 2.0x means the shadow must be at least twice the body size for hammer and shooting star shapes. The Doji threshold is expressed as body size as a percentage of the full range, defaulting to 10%.
Engulfing patterns require the current candle to fully contain the prior candle's body. Harami requires the current body to fit inside the prior range and be less than 60% of the prior body size. Piercing Line requires the close to cross above the midpoint of the prior bearish candle; Dark Cloud Cover requires the close to cross below the midpoint of the prior bullish candle.
Morning and Evening Star use a three-bar setup: a strong directional candle, followed by a small-body indecision candle (body less than 30% of its range), followed by a confirmation candle that closes past the midpoint of the first candle.
Three White Soldiers and Three Black Crows require three consecutive same-direction closes, each higher/lower than the last, with the opens gapping slightly into the prior body.
Trend filter
An EMA crossover (default 20/50) determines trend direction on the current timeframe and three configurable higher timeframes via request.security(). With-trend signals are displayed at full opacity; counter-trend signals are shown at reduced opacity. An optional filter hides counter-trend patterns entirely.
MTF Trend Panel
A compact table in the bottom-right corner shows the current trend direction (▲ Bull / ▼ Bear) across the current timeframe plus the three configured higher timeframes, with the EMA pair displayed as a label. Each cell is color-coded green or red.
Display
Each detected pattern places a label above (bearish) or below (bullish) the candle with the pattern name. A subtle background color fill highlights the bar. Both label colors and background highlights are independently configurable.
Works on any instrument and timeframe.
Description:
Detects and labels 15 classic Japanese candlestick patterns in real time, with a multi-timeframe trend filter that highlights which signals align with the prevailing trend direction.
Patterns detected
Single-candle patterns: Doji, Hammer, Hanging Man, Inverted Hammer, Shooting Star.
Two-candle patterns: Bullish Engulfing, Bearish Engulfing, Bullish Harami, Bearish Harami, Piercing Line, Dark Cloud Cover.
Three-candle patterns: Morning Star, Evening Star, Three White Soldiers, Three Black Crows.
Pattern logic
Candle anatomy is computed from body, upper wick, lower wick, and full range on each bar. The wick-to-body ratio threshold is configurable — default 2.0x means the shadow must be at least twice the body size for hammer and shooting star shapes. The Doji threshold is expressed as body size as a percentage of the full range, defaulting to 10%.
Engulfing patterns require the current candle to fully contain the prior candle's body. Harami requires the current body to fit inside the prior range and be less than 60% of the prior body size. Piercing Line requires the close to cross above the midpoint of the prior bearish candle; Dark Cloud Cover requires the close to cross below the midpoint of the prior bullish candle.
Morning and Evening Star use a three-bar setup: a strong directional candle, followed by a small-body indecision candle (body less than 30% of its range), followed by a confirmation candle that closes past the midpoint of the first candle.
Three White Soldiers and Three Black Crows require three consecutive same-direction closes, each higher/lower than the last, with the opens gapping slightly into the prior body.
Trend filter
An EMA crossover (default 20/50) determines trend direction on the current timeframe and three configurable higher timeframes via request.security(). With-trend signals are displayed at full opacity; counter-trend signals are shown at reduced opacity. An optional filter hides counter-trend patterns entirely.
MTF Trend Panel
A compact table in the bottom-right corner shows the current trend direction (▲ Bull / ▼ Bear) across the current timeframe plus the three configured higher timeframes, with the EMA pair displayed as a label. Each cell is color-coded green or red.
Display
Each detected pattern places a label above (bearish) or below (bullish) the candle with the pattern name. A subtle background color fill highlights the bar. Both label colors and background highlights are independently configurable.
Works on any instrument and timeframe.
릴리즈 노트
Title: Candlestick PatternsDescription:
Detects and labels 15 classic Japanese candlestick patterns in real time, with a multi-timeframe trend filter that highlights which signals align with the prevailing trend direction. Labels appear only on the first bar of each consecutive pattern run — no stacked duplicates when the same pattern repeats across multiple candles.
Patterns detected
Single-candle: Doji, Hammer, Hanging Man, Inverted Hammer, Shooting Star.
Two-candle: Bullish Engulfing, Bearish Engulfing, Bullish Harami, Bearish Harami, Piercing Line, Dark Cloud Cover.
Three-candle: Morning Star, Evening Star, Three White Soldiers, Three Black Crows.
Pattern logic
Candle anatomy is computed from body size, upper wick, lower wick, and full range on each bar. The wick-to-body ratio is configurable — default 2.0x means the shadow must be at least twice the body for hammer and shooting star shapes. The Doji threshold is expressed as body size as a percentage of the full range, defaulting to 10%.
Engulfing patterns require the current candle to fully contain the prior candle's body. Harami requires the current body to fit inside the prior range and be smaller than 60% of the prior body. Piercing Line requires the close to cross above the midpoint of the prior bearish candle; Dark Cloud Cover requires the close to cross below the midpoint of the prior bullish candle.
Morning and Evening Star use a three-bar setup: a strong directional candle, a small-body indecision candle (body less than 30% of its range), and a confirmation candle that closes past the midpoint of the first bar.
Three White Soldiers and Three Black Crows require three consecutive same-direction closes, each higher/lower than the last, with the opens gapping slightly into the prior body.
Deduplication
Each pattern only labels the first bar of a consecutive run. If Hammer conditions hold for five bars in a row, a single label appears on bar one. The background highlight and alert conditions remain active for the full duration of the pattern, so alerts still fire correctly on every qualifying bar.
Trend filter
An EMA crossover (default 20/50) determines trend direction on the current timeframe and three configurable higher timeframes via request.security(). With-trend signals display at full opacity; counter-trend signals display at reduced opacity. An optional toggle hides counter-trend patterns entirely.
MTF Trend Panel
A compact table in the bottom-right corner shows the current trend direction (▲ Bull / ▼ Bear) across the current timeframe plus three configurable higher timeframes. Each cell is color-coded green or red, with the active EMA pair shown as a label.
Settings
Toggle each pattern group independently
Wick/body ratio threshold and Doji body % threshold
Background highlight on/off
Bullish, bearish, and neutral label colors
EMA fast/slow periods
Three MTF timeframes
With-trend only filter
Works on any instrument and timeframe.
릴리즈 노트
WHAT THIS ISFourteen classic candlestick patterns, classified the way the literature actually defines them, filtered by volatility so that only patterns worth looking at reach the chart, and cross-checked against a multi-timeframe EMA trend.
Most pattern scripts fail in the same two places. This one fixes both, and then adds the filter that decides whether the chart is readable at all.
1. HAMMER AND HANGING MAN ARE THE SAME CANDLE
They are not distinguished by colour. They are distinguished by where they appear.
A hammer is a small body with a long lower wick that forms at the end of a decline. A hanging man is the identical shape at the end of an advance. A red hammer is still a hammer, and a green hanging man is still a hanging man. The same is true of the Inverted Hammer and the Shooting Star.
Scripts that split them on candle colour mislabel a large share of what they mark. This one classifies them against the current EMA trend, which is what the context actually is.
2. THE GAP RULE IS A SETTING, NOT AN ASSUMPTION
Nison defines Piercing Line and Dark Cloud Cover as opening beyond the prior candle's extreme. That is correct for stocks, which gap at the open.
Forex, crypto and 24h indices do not gap: price opens where it closed. Under the strict definition both patterns essentially never fire, and they disappear from the chart without any indication that they have been switched off.
Both readings ship, selectable:
Strict — beyond the prior high/low. Textbook. Use it on equities.
Relaxed — beyond the prior close. The reading in common use on continuous markets.
The penetration depth into the prior body is also configurable, from the textbook 50% upward.
3. THE SIGNIFICANCE FILTER — the part that matters most
Candlestick patterns are extremely common. On any intraday chart there is an "engulfing" every few bars. An indicator that marks all of them is marking noise, and that is why most pattern scripts are unusable after five minutes.
Four filters, all adjustable:
Minimum candle size (× ATR) — a pattern on a candle a third the size of the average one is not the pattern, it is noise wearing its name. This is the single setting that decides whether the chart is readable.
Engulfing must exceed the prior body by — on continuous markets, "engulfing by one tick" happens constantly. Requiring the body to be a multiple of the prior body is what makes the word mean something. Default 1.5×.
Piercing / Dark Cloud penetration % — how deep into the prior body the close must reach.
Minimum bars between labels — patterns overlap constantly. Three labels in four bars tell you nothing the first one did not.
Doji and Harami ship off by default. They are the two noisiest members of the set and add the least. Turn them on if you want them.
4. MULTI-TIMEFRAME TREND
A panel shows the EMA-fast vs EMA-slow trend on the chart timeframe plus three timeframes of your choosing, so you can see at a glance whether a bullish pattern is appearing into a bearish higher timeframe.
"Show only with-trend patterns" is on by default. It hides counter-trend patterns entirely and roughly halves what reaches the chart. Turn it off if you trade reversals.
Both the fast and slow EMA lengths and all three timeframes are configurable.
DETAILS THAT USUALLY GO WRONG
One label per bar. A hammer that is also a bullish engulfing produces one label listing both, not two labels stacked on the same anchor with one hidden underneath.
Labels, background highlight and alerts all use the same trigger. They fire on the bar the pattern completed, not on every bar the condition happens to remain true. A three-bar run gives one label, one highlighted bar and one alert — not one label and three alerts.
A Doji is only labelled when nothing else fired. It anchors where the bearish label goes and it is the least informative of the set; it should not cover a Shooting Star to announce that the body was small.
The trend panel is built once and its cells updated, rather than the whole table being destroyed and rebuilt on every tick.
PATTERNS INCLUDED
Hammer · Hanging Man · Inverted Hammer · Shooting Star · Bullish and Bearish Engulfing · Bullish and Bearish Harami · Piercing Line · Dark Cloud Cover · Morning Star · Evening Star · Three White Soldiers · Three Black Crows · Doji
Each can be switched off individually.
ALERTS
Six conditions: bullish pattern, bearish pattern, bullish with trend, bearish with trend, Doji, and Morning/Evening Star. All fire on pattern completion, once per occurrence.
WHAT THIS DOES NOT DO
It does not tell you to buy or sell, and it makes no claim about how often any pattern works. Filtering the noise makes a chart readable; it does not make a pattern profitable. Whether these setups survive real spread and commission on your instrument is a question this tool does not answer and does not pretend to.
Everything is toggleable. Turn off what you do not use.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.