Atualizado

Candlestick Patterns

1 661
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.
Notas de Lançamento
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. 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.
Notas de Lançamento
WHAT THIS IS
Fourteen 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.
Notas de Lançamento
CANDLESTICK PATTERNS — GEOMETRY, CHART TREND AND ACCEPTED EVENTS

This overlay checks fourteen directional candlestick classifications plus an optional neutral Doji. It applies family-specific geometry and significance tests, identifies the first bar of each condition run, then applies an optional chart-timeframe EMA filter and a shared directional cooldown. Accepted same-side names are combined in one label.

The refresh adds compact teal/rose labels with an adjustable ATR distance from price. Background highlighting is initially off and uses lighter fills when enabled. A theme-aware EMA context table now renders the existing chart and requested-timeframe calculations, with a footer explicitly identifying the CHART EMA as the directional filter. Pattern formulas, first-event logic and cooldown rules are unchanged.

snapshot

01 / START WITH THE ACTUAL FILTER

The chart trend is bullish only when EMA Fast is strictly above EMA Slow, initially 20 and 50. Every other result uses the bearish branch, including equality. This is EMA order, not a price-above-EMA test, slope requirement or neutral regime classifier.

The directional filter is initially ON. It accepts bullish classifications only in chart bullish context and bearish classifications only in chart bearish context. The 60-minute, 240-minute and daily values are displayed for context; agreement across them is NOT required for any pattern. Hiding the panel does not disable trend calculation or filtering.

The hammer family's names themselves depend on chart trend. A lower-wick shape in bearish chart context is Hammer; in bullish context it is Hanging Man. Upper-wick geometry is Inverted Hammer in bearish context and Shooting Star in bullish context. Candle body color does not select those names.

Consequently, with the directional filter on, those four countertrend classifications are suppressed: the bullish Hammer/Inverted Hammer classifications occur in bearish context, and the bearish Hanging Man/Shooting Star classifications occur in bullish context. Turn the directional filter off to inspect those candidates. This refresh preserves that existing behavior rather than silently changing signal selection.

02 / BODY, RANGE AND SIGNIFICANCE

Body is |close − open|, range is high − low, and wicks are measured outside the body. Current close equal to open is treated as bullish for the general candle-color tests; bearish requires close strictly below open.

Minimum Candle Size initially equals 0.6 × ATR(14). Body-driven checks use current BODY against that threshold. Hammer-family geometry uses current RANGE instead, because its body is small by construction. Harami checks the prior candle's RANGE against the current ATR threshold. Doji has its own body/range threshold and does not use the ATR significance gate.

03 / THE PATTERN TESTS

  • Hammer family: nonzero body, qualifying range, dominant wick at least Wick/Body Ratio × body, initially 2.0, and the opposite wick at most half the body. Chart trend assigns the four names described above.
  • Engulfing: opposite prior/current candle colors, qualifying current body, current body boundaries encompass the prior body, and size at least Engulfing Ratio × prior body, initially 1.5.
  • Harami: opposite colors, significant prior range, current HIGH strictly inside prior high and current LOW strictly inside prior low, with current body strictly below 60% of prior body.
  • Morning/Evening Star: the first and middle candles use the specified bearish/bullish setup, the middle body/range ratio is strictly below 0.3, and a significant opposite-colored current candle closes beyond the first candle's body midpoint.
  • Three Soldiers/Crows: three same-direction bodies and progressively higher/lower closes, with the CURRENT open strictly inside the prior candle body and a significant current body.
  • Piercing/Dark Cloud: opposite prior/current colors, a significant current body, an open beyond the selected reference and a close beyond the configured penetration into the prior body.


Doji, initially off, requires a positive range and body/range × 100 strictly BELOW Doji Max Body %, initially 10. Equality fails. Harami is also initially off; the other directional family switches are initially on. A family switch gates its underlying detections.

04 / PIERCING AND DARK CLOUD GAP SETTINGS

Relaxed, initially selected, compares bullish opens strictly below prior close and bearish opens strictly above prior close. An exactly unchanged open does NOT pass.

Strict compares bullish opens below prior LOW and bearish opens above prior HIGH. Penetration initially equals 50% of the prior body, with a configurable 50–100% range.

snapshot

05 / FIRST EVENTS, COOLDOWN AND DOJI

Each raw pattern creates a fresh event only when true now and false on the previous bar. A continuous multi-bar run therefore produces one fresh event, even though its geometry remains true. If that first event is rejected by the trend filter or cooldown, a later bar in the same uninterrupted run does not automatically become a new accepted event.

Minimum Bars Between Labels initially equals five. The directional gate accepts bar age at least that value, using one shared last-label timestamp for both sides. Both side checks use the same pre-update cooldown value, so simultaneous accepted sides can both label the same bar.

Same-side names are stacked within one badge. The highlight, when enabled, follows accepted directional events after these filters.

A fresh Doji label is drawn only when neither directional side passes. Doji is not gated by the directional trend filter or cooldown and does not update the shared cooldown timestamp. It also has no separate background highlight.

06 / PANEL, LIVE BARS AND LIMITS

The added panel displays the existing chart and three requested EMA-order series. Requested bars can develop; there is no one-bar confirmed-value offset. Lower-than-chart requests do not expose every intrabar event. These columns remain context rather than additional acceptance votes.

Detection has no explicit confirmed-close gate, so a developing candle can gain or lose a classification before it closes. Historical labels are not orders, confirmed reversal outcomes or trade results. The original source contains no alertcondition declarations, and this visual refresh does not add any. There is no strategy execution, stop/target tracking, win-rate calculation or profitability validation.

Read each label as an accepted rule-based classification: inspect its candle anatomy, the chart EMA setting and the cooldown context. Use the family switches and significance inputs to choose the detail you want to study, while allowing for symbol, timeframe and data-feed differences.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.