Skip to main content

Candlestick Pattern Libraries & Filters

Using community pattern libraries, building volume and trend filters for candlestick signals, and combining patterns with technical indicators for higher accuracy.

From Thrive on YouTube

Watch the matching Thrive video

Watch the series
Swing Failure Pattern (SFP) Explained: Trade the Fake Breakout

Swing Failure Pattern (SFP) Explained: Trade the Fake Breakout

Part of Charting and Market Structure. Education only. Not financial advice.

Why Raw Candlestick Patterns Produce Too Many False Signals

If you run any of the pattern detectors from the previous lessons on a BTC daily chart, you will see dozens of signals per month. Most of them lead nowhere: the pattern fires, price moves a little in the expected direction, then reverses. The problem is not the pattern itself. It is the lack of context. A bullish engulfing candle on below-average volume during a strong downtrend is just noise. That same engulfing candle on 2x average volume at a major support level with RSI in oversold territory is a high-probability setup.

Filters transform raw pattern detection into a tradeable system. Each filter eliminates a category of false signals. Combining multiple filters creates a confluence-based approach where only the highest-quality patterns survive.

Volume Filter: Above-Average Volume Confirmation

Volume is the single most important confirmation for any candle pattern. A bullish engulfing on high volume means real capital is behind the move. The same pattern on low volume is just random noise with no institutional participation. The standard approach is to require volume to be above its 20-period simple moving average, but you can set a multiplier for stricter filtering.

pine-Volume filter implementation
1//@version=5
2indicator("Volume Filter", overlay=true)
3
4volLen = input.int(20, "Volume SMA Length", minval=5)
5volMult = input.float(1.0, "Volume Multiplier", step=0.1,
6 tooltip="1.0 = above average, 1.5 = 50% above average")
7
8avgVol = ta.sma(volume, volLen)
9aboveAvgVol = volume >= avgVol * volMult
10
11// Example: engulfing + volume filter
12body = math.abs(close - open)
13bodyHigh = math.max(close, open)
14bodyLow = math.min(close, open)
15prevBodyHigh = math.max(close[1], open[1])
16prevBodyLow = math.min(close[1], open[1])
17
18bullEngulf = close[1] < open[1] and close > open and
19 bodyLow <= prevBodyLow and bodyHigh >= prevBodyHigh
20
21// Unfiltered vs filtered
22unfilteredSignal = bullEngulf
23filteredSignal = bullEngulf and aboveAvgVol
24
25plotshape(unfilteredSignal and not filteredSignal, "Unfiltered",
26 shape.cross, location.belowbar,
27 color.new(color.gray, 50), size=size.tiny)
28plotshape(filteredSignal, "Vol Confirmed",
29 shape.triangleup, location.belowbar,
30 color.green, size=size.small)
31
32// Volume bars in separate pane
33plot(volume, "Volume", aboveAvgVol ? color.green : color.gray,
34 style=plot.style_histogram, display=display.pane)
35plot(avgVol * volMult, "Vol Threshold", color.orange,
36 display=display.pane)

Volume multiplier tuning

A multiplier of 1.0 (above average) is the baseline. For BTC on the daily chart, 1.5x average volume already filters out roughly 60% of signals. On SOL, which has higher volume variance, 1.2x is often sufficient. Test different multipliers by counting how many signals pass and checking their follow-through rate.

Trend Filter: Only Take Patterns in the Right Direction

One of the most effective filters is directional alignment. Only take bullish candle patterns when the broader trend is bullish, and only take bearish patterns when the trend is bearish. Trading counter-trend patterns is possible but requires much higher confluence. For most traders, trend-aligned patterns have significantly better win rates.

pine-Trend filter using moving average slope
1//@version=5
2indicator("Trend Filter", overlay=true)
3
4trendMA = input.int(50, "Trend MA Length", minval=10)
5slopeLen = input.int(5, "Slope Lookback", minval=1)
6
7ema = ta.ema(close, trendMA)
8slope = ema - ema[slopeLen]
9upTrend = slope > 0 and close > ema
10dnTrend = slope < 0 and close < ema
11
12// Filter function: returns true if pattern direction matches trend
13bullFilter = upTrend
14bearFilter = dnTrend
15
16// Example application
17body = math.abs(close - open)
18bodyHigh = math.max(close, open)
19bodyLow = math.min(close, open)
20prevBodyHigh = math.max(close[1], open[1])
21prevBodyLow = math.min(close[1], open[1])
22
23bullEngulf = close[1] < open[1] and close > open and
24 bodyLow <= prevBodyLow and bodyHigh >= prevBodyHigh
25bearEngulf = close[1] > open[1] and close < open and
26 bodyLow <= prevBodyLow and bodyHigh >= prevBodyHigh
27
28trendBull = bullEngulf and bullFilter
29trendBear = bearEngulf and bearFilter
30
31plot(ema, "Trend EMA", upTrend ? color.green : dnTrend ? color.red : color.gray, 2)
32plotshape(trendBull, "Trend Bull", shape.triangleup,
33 location.belowbar, color.green, size=size.small)
34plotshape(trendBear, "Trend Bear", shape.triangledown,
35 location.abovebar, color.red, size=size.small)
36
37bgcolor(upTrend ? color.new(color.green, 95) :
38 dnTrend ? color.new(color.red, 95) : na)

ATR-Based Filter: Minimum Candle Size

Small candles produce weak signals. If an engulfing pattern forms with a range smaller than 0.5x the 14-period ATR, it lacks the volatility to be meaningful. ATR-based filters ensure that patterns only fire on candles that represent genuine price movement relative to recent volatility. This is especially important on ETH during low-volume weekend sessions.

pine-ATR-based minimum candle size filter
1//@version=5
2indicator("ATR Filter", overlay=true)
3
4atrLen = input.int(14, "ATR Length")
5atrMult = input.float(0.5, "Min Candle Size (ATR mult)", step=0.1,
6 tooltip="Minimum candle range as a multiple of ATR")
7
8atr = ta.atr(atrLen)
9range_ = high - low
10minRange = atr * atrMult
11
12// The candle must be at least atrMult * ATR in size
13sizeFilter = range_ >= minRange
14
15// Also useful: body must be a minimum % of ATR
16bodyAtrFilter = math.abs(close - open) >= atr * 0.3
17
18// Combined size filter
19validCandle = sizeFilter and bodyAtrFilter
20
21// Visual: mark candles that pass the size filter
22bgcolor(not validCandle ? color.new(color.gray, 95) : na,
23 title="Weak Candle Fade")

Moving Average Slope as a Directional Filter

Rather than just checking if price is above or below a moving average, measuring the slope of the MA tells you whether the trend is accelerating, decelerating, or flat. A bullish candle pattern during an accelerating uptrend (steepening slope) is far more powerful than one during a flattening trend. The slope is calculated as the difference between the current MA value and its value N bars ago.

pine-MA slope directional filter
1//@version=5
2indicator("MA Slope Filter", overlay=false)
3
4maLen = input.int(21, "MA Length")
5slopeLen = input.int(5, "Slope Period")
6slopeThr = input.float(0.0, "Min Slope Threshold",
7 tooltip="Absolute minimum slope value")
8
9ema = ta.ema(close, maLen)
10slope = (ema - ema[slopeLen]) / ema[slopeLen] * 100
11absSlope = math.abs(slope)
12
13strongUp = slope > slopeThr
14strongDown = slope < -slopeThr
15flat = absSlope <= slopeThr
16
17slopeColor = strongUp ? color.green :
18 strongDown ? color.red : color.gray
19
20plot(slope, "EMA Slope %", slopeColor, 2, plot.style_histogram)
21hline(slopeThr, "Threshold", color.new(color.green, 70), hline.style_dashed)
22hline(-slopeThr, "-Threshold", color.new(color.red, 70), hline.style_dashed)
23hline(0, "Zero", color.new(color.gray, 80))

Combining Patterns with RSI Zones

RSI zone filtering adds a momentum dimension. A bullish engulfing with RSI below 40 means the reversal is occurring from a momentum extreme: sellers are exhausted. A bullish engulfing with RSI at 70 means the "reversal" is actually a continuation in overbought territory: much less reliable. By requiring RSI to be in the appropriate zone for the pattern direction, you eliminate a large class of low-probability signals.

pine-RSI zone filter for candle patterns
1//@version=5
2indicator("RSI Zone Filter", overlay=true)
3
4rsiLen = input.int(14, "RSI Length")
5bullZone = input.int(45, "Bull RSI Max", tooltip="Bullish patterns only below this RSI")
6bearZone = input.int(55, "Bear RSI Min", tooltip="Bearish patterns only above this RSI")
7
8rsi = ta.rsi(close, rsiLen)
9
10// RSI zone filters
11rsiBullFilter = rsi <= bullZone
12rsiBearFilter = rsi >= bearZone
13
14// Example: engulfing + RSI filter
15body = math.abs(close - open)
16bodyHigh = math.max(close, open)
17bodyLow = math.min(close, open)
18prevBodyHigh = math.max(close[1], open[1])
19prevBodyLow = math.min(close[1], open[1])
20
21bullEngulf = close[1] < open[1] and close > open and
22 bodyLow <= prevBodyLow and bodyHigh >= prevBodyHigh
23bearEngulf = close[1] > open[1] and close < open and
24 bodyLow <= prevBodyLow and bodyHigh >= prevBodyHigh
25
26rsiBull = bullEngulf and rsiBullFilter
27rsiBear = bearEngulf and rsiBearFilter
28
29plotshape(rsiBull, "RSI Bull", shape.labelup,
30 location.belowbar, color.new(color.green, 10),
31 text="RSI", textcolor=color.white, size=size.small)
32plotshape(rsiBear, "RSI Bear", shape.labeldown,
33 location.abovebar, color.new(color.red, 10),
34 text="RSI", textcolor=color.white, size=size.small)

Using Community Pattern Libraries

TradingView's community publishes PineScript libraries that contain pre-built pattern detection functions. Instead of writing every pattern from scratch, you can import a library and call its functions directly. This saves development time and lets you leverage battle-tested code written by experienced PineScript developers.

1

Find a library

Go to TradingView's script library and search for "candlestick patterns library." Look for libraries with high usage counts and positive reviews. Check the source code to verify the pattern logic matches standard definitions.
2

Import the library

Use the import statement at the top of your script: import Username/LibraryName/1 as candles. The /1 is the version number.
3

Call library functions

Library functions are called with the alias prefix: candles.isBullishEngulfing(). Each function returns a boolean that you can use in your own filter chain.
4

Apply your own filters on top

The library handles pattern detection; you add the context filters (volume, trend, RSI, ATR). This separation of concerns keeps your code clean and modular.

Creating Your Own Reusable Pattern Library

Once you have refined your pattern and filter functions, package them into a library so you can reuse them across all your indicators and strategies without copy-pasting code.

pine-Reusable candle pattern library structure
1//@version=5
2// @description Candle pattern detection with built-in filters
3library("CandlePatterns", overlay=false)
4
5export isEngulfing(bool bullish) =>
6 body = math.abs(close - open)
7 bodyHigh = math.max(close, open)
8 bodyLow = math.min(close, open)
9 pBodyHigh = math.max(close[1], open[1])
10 pBodyLow = math.min(close[1], open[1])
11 engulf = bodyLow <= pBodyLow and bodyHigh >= pBodyHigh and body > math.abs(close[1] - open[1])
12 if bullish
13 close[1] < open[1] and close > open and engulf
14 else
15 close[1] > open[1] and close < open and engulf
16
17export isHammer(float wickRatio) =>
18 body = math.abs(close - open)
19 lowerWick = math.min(close, open) - low
20 upperWick = high - math.max(close, open)
21 body > 0 and lowerWick >= body * wickRatio and upperWick <= body * 0.5
22
23export isDoji(float threshold) =>
24 range_ = high - low
25 range_ > 0 and math.abs(close - open) / range_ * 100 <= threshold
26
27export volumeFilter(int length, float mult) =>
28 volume >= ta.sma(volume, length) * mult
29
30export atrFilter(int length, float mult) =>
31 (high - low) >= ta.atr(length) * mult

Comprehensive Filtered Pattern System

Here is a complete indicator that applies all filter types to engulfing patterns. Toggle each filter independently to see how it affects signal count and quality.

pine-Multi-filter candle pattern system
1//@version=5
2indicator("Filtered Patterns", overlay=true)
3
4// Filter toggles
5useVolFilter = input.bool(true, "Volume Filter")
6useTrendFilter = input.bool(true, "Trend Filter")
7useAtrFilter = input.bool(true, "ATR Size Filter")
8useRsiFilter = input.bool(false, "RSI Zone Filter")
9
10// Filter parameters
11volLen = input.int(20, "Volume SMA Length")
12volMult = input.float(1.0, "Volume Multiplier", step=0.1)
13trendLen = input.int(50, "Trend EMA Length")
14atrLen = input.int(14, "ATR Length")
15atrMult = input.float(0.5, "Min Range (ATR mult)", step=0.1)
16rsiLen = input.int(14, "RSI Length")
17rsiBull = input.int(45, "Bull RSI Max")
18rsiBear = input.int(55, "Bear RSI Min")
19
20// Calculations
21avgVol = ta.sma(volume, volLen)
22ema = ta.ema(close, trendLen)
23slope = ema - ema[5]
24atr = ta.atr(atrLen)
25rsi = ta.rsi(close, rsiLen)
26
27// Pattern detection
28body = math.abs(close - open)
29bodyHigh = math.max(close, open)
30bodyLow = math.min(close, open)
31pBodyHigh = math.max(close[1], open[1])
32pBodyLow = math.min(close[1], open[1])
33engulf = bodyLow <= pBodyLow and bodyHigh >= pBodyHigh and body > math.abs(close[1] - open[1])
34
35rawBull = close[1] < open[1] and close > open and engulf
36rawBear = close[1] > open[1] and close < open and engulf
37
38// Apply filters
39volPass = not useVolFilter or volume >= avgVol * volMult
40trendBull = not useTrendFilter or (slope > 0 and close > ema)
41trendBear = not useTrendFilter or (slope < 0 and close < ema)
42atrPass = not useAtrFilter or (high - low) >= atr * atrMult
43rsiBullOk = not useRsiFilter or rsi <= rsiBull
44rsiBearOk = not useRsiFilter or rsi >= rsiBear
45
46filteredBull = rawBull and volPass and trendBull and atrPass and rsiBullOk
47filteredBear = rawBear and volPass and trendBear and atrPass and rsiBearOk
48
49// Count filters passed (for label)
50bullFilters = (volPass ? 1 : 0) + (trendBull ? 1 : 0) + (atrPass ? 1 : 0) + (rsiBullOk ? 1 : 0)
51bearFilters = (volPass ? 1 : 0) + (trendBear ? 1 : 0) + (atrPass ? 1 : 0) + (rsiBearOk ? 1 : 0)
52
53plotshape(filteredBull, "Filtered Bull", shape.labelup,
54 location.belowbar, color.new(color.green, 0),
55 text="BUY", textcolor=color.white, size=size.small)
56plotshape(filteredBear, "Filtered Bear", shape.labeldown,
57 location.abovebar, color.new(color.red, 0),
58 text="SELL", textcolor=color.white, size=size.small)
59
60// Show rejected patterns in gray for comparison
61plotshape(rawBull and not filteredBull, "Rejected Bull",
62 shape.cross, location.belowbar,
63 color.new(color.gray, 60), size=size.tiny)
64plotshape(rawBear and not filteredBear, "Rejected Bear",
65 shape.cross, location.abovebar,
66 color.new(color.gray, 60), size=size.tiny)
67
68plot(ema, "Trend EMA", slope > 0 ? color.green : color.red, 2)
69
70alertcondition(filteredBull, "Filtered Bullish",
71 "High-quality bullish engulfing detected")
72alertcondition(filteredBear, "Filtered Bearish",
73 "High-quality bearish engulfing detected")

Backtesting filter combinations

The rejected-pattern gray crosses let you visually compare what the filters removed. Count how many filtered signals followed through vs. how many rejected signals would have been losers. On BTC daily, adding just the volume filter typically eliminates 40–50% of signals while keeping most winners. Adding the trend filter on top removes another 30% of the remaining signals: the ones that were counter-trend.

Put this lesson to work

Free on Thrive, no account needed.