Indicator · Pine Script v6 · On the chart

Three Bar Reversal Pattern

by MarcosACH· code credited to ActiveQuants

Three Bar Reversal Pattern marks bullish and bearish three-candle reversals.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code85
Settings16inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago8 Jul 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

85 lines of Pine Script v6 from three_bar_reversal_pattern.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

three_bar_reversal_pattern.pinescript
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ActiveQuants
// Created by ActiveQuants
// Last updated: March 6, 2025

//@version=6
indicator(title = "Three Bar Reversal Pattern [ActiveQuants]", shorttitle = "3 Bar Reversal Pattern [ActiveQuants]", overlay = true, max_labels_count = 500)
import MarcosACH/CandleAnalysis/1 as CndlA

//#region ------ USER INPUTS
bool plotBullishPattern = input.bool(defval = true, title = "Bullish Pattern", inline = "bullish pattern")
bool plotBearishPattern = input.bool(defval = true, title = "Bearish Pattern", inline = "bearish pattern")
color bullishPatternColor = input.color(defval = #089981, title = "", inline = "bullish pattern")
color bearishPatternColor = input.color(defval = #ff5252, title = "", inline = "bearish pattern")
string bullishPatternSize = input.string(defval = size.normal, title = "", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], inline = "bullish pattern")
string bearishPatternSize = input.string(defval = size.normal, title = "", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], inline = "bearish pattern")
int showLast = input.int(defval = 500, title = "Show Last", minval = 10, step = 10, tooltip = "Number of bars back the indicator can plot.")

// Filters
bool enableVolumeSmaFilter = input.bool(defval = true, title = "Volume SMA Filter", tooltip = "If enabled, this function will remove patterns where the volume of the last candle is below the volume SMA.", group = "Filters")
int volSmaLength = input.int(defval = 20, title = "Volume SMA Length", minval = 1, group = "Filters")
float shootingStarBodyLimit = input.float(defval = 0.5, title = "Shooting Star Body Limit", minval = 0, maxval = 1, step = 0.01, 
 tooltip = "This parameter defines the percentage of the candle's range used to classify a Shooting Star candle (e.g., if this parameter is set to 0.5, then any candle whose body is entirely located in the lower 50% of its range will be identified as a Shooting Star). If a Shooting Star is identified within a bullish pattern, that pattern will be discarded (set this parameter to 0 if you don't want to apply this filter).", 
 group = "Filters")
float hammerBodyLimit = input.float(defval = 0.5, title = "Hammer Body Limit", minval = 0, maxval = 1, step = 0.01, 
 tooltip = "This parameter defines the percentage of the candle's range used to classify a Hammer candle (e.g., if this parameter is set to 0.5, then any candle whose body is entirely located in the upper 50% of its range will be identified as a Hammer). If a Hammer is identified within a bearish pattern, that pattern will be discarded (set this parameter to 0 if you don't want to apply this filter).", 
 group = "Filters")
bool enableMidCandleFilter = input.bool(defval = false, title = "Middle Candle Filter", 
 tooltip = "If enabled, this function will remove bullish signals where the low of the middle candle is not lower than both the first and last candles' lows, and it will remove bearish signals where the high of the middle candle is not higher than both the first and last candles' highs.", group = "Filters")
bool enableRsiFilter = input.bool(defval = false, title = "RSI Filter", 
 tooltip = "If enabled, this function will remove bullish signals where the RSI is not oversold, and it will remove bearish signals where the RSI is not overbought.", group = "Filters")
int rsiLength = input.int(defval = 14, title = "RSI Length", minval = 1, group = "Filters")
int rsiOverboughtThreshold = input.int(defval = 60, title = "Overbought Threshold", minval = 1, group = "Filters")
int rsiOversoldThreshold = input.int(defval = 40, title = "Oversold Threshold", minval = 1, group = "Filters")
//#endregion

//#region ----- CALCULATIONS
float volSma = ta.sma(volume, volSmaLength)
bool bullish = CndlA.isBearish(2) and CndlA.isBearish(1) and close > open[2] and not CndlA.isShootingStar(fib = shootingStarBodyLimit) and barstate.isconfirmed
bool bearish = CndlA.isBullish(2) and CndlA.isBullish(1) and close < open[2] and not CndlA.isHammer(fib = hammerBodyLimit) and barstate.isconfirmed

if enableVolumeSmaFilter and volume < volSma
    bullish := false
    bearish := false

if enableMidCandleFilter
    if bullish and low[1] > low[2] or low[1] > low
        bullish := false
    if bearish and high[1] < high[2] or high[1] < high
        bearish := false

bool rsiOverbought = ta.rsi(close, rsiLength) > rsiOverboughtThreshold
bool rsiOversold = ta.rsi(close, rsiLength) < rsiOversoldThreshold

if enableRsiFilter
    if bullish and not rsiOversold
        bullish := false
    if bearish and not rsiOverbought
        bearish := false
//#endregion

//#region ------ VARIABLES
var array<label> labels = array.new_label()
//#endregion

//#region ----- PLOTTING
if bullish and plotBullishPattern
    label pattern = label.new(bar_index, close, "▲", yloc = yloc.belowbar, color = na, style = label.style_triangleup, textcolor = bullishPatternColor, size = bullishPatternSize)
    array.push(labels, pattern)
else if bearish and plotBearishPattern
    label pattern = label.new(bar_index, close, "▼", yloc = yloc.abovebar, color = na, style = label.style_triangledown, textcolor = bearishPatternColor, size = bearishPatternSize)
    array.push(labels, pattern)

if array.size(labels) > 0
    for i = array.size(labels) - 1 to 0
        label currentLabel = array.get(labels, i)
        if label.get_x(currentLabel) < bar_index - showLast
            label.delete(currentLabel)
            array.remove(labels, i)
//#endregion

//#region ----- ALERTS
alertcondition(bullish, title = "Bullish Reversal Pattern", message = "Bullish Reversal Pattern detected")
alertcondition(bearish, title = "Bearish Reversal Pattern", message = "Bearish Reversal Pattern detected")
//#endregion

Overview

A bullish pattern is two down candles followed by an up candle closing above the first candle's open; the bearish pattern is the mirror image. Optional filters require volume above its moving average, reject shooting star or hammer final candles, check the middle candle's extreme and require an RSI condition. Separate bullish and bearish alerts are included. Labels draw on the price chart.

Details

Published by

MarcosACH on GitHub

Code credit

ActiveQuants, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Candlestick patterns, Volume

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptpinescript-algorithmspinescript-indicatorstechnical-analysistechnical-analysis-indicatorstrading-algorithmstrading-indicatorstradingvewtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Bullish PatternbooltrueplotBullishPattern
Bearish PatternbooltrueplotBearishPattern
bullishPatternColorcolor#089981bullishPatternColor
bearishPatternColorcolor#ff5252bearishPatternColor
bullishPatternSizestringsize.normalbullishPatternSize
bearishPatternSizestringsize.normalbearishPatternSize
Show Lastint500showLast
Volume SMA FilterbooltrueenableVolumeSmaFilter
Volume SMA Lengthint20volSmaLength
Shooting Star Body Limitfloat0.5shootingStarBodyLimit
Hammer Body Limitfloat0.5hammerBodyLimit
Middle Candle FilterboolfalseenableMidCandleFilter
Show all 16 settings
SettingTypeDefaultVariable
RSI FilterboolfalseenableRsiFilter
RSI Lengthint14rsiLength
Overbought Thresholdint60rsiOverboughtThreshold
Oversold Thresholdint40rsiOversoldThreshold
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Vector Candles

by benso87
24 stars

Vector Candles is an overlay indicator that recolors price candles using PVSRA volume rules taken from the Traders Reality concept. It compares each bar's volume with the average of the previous ten bars and also checks the product of spread and volume against

Indicator v5 VolumeCandlestick patterns
Updated 4 years ago · MPL-2.0 GitHub repository of Vector Candles
23 stars

Point-Clip Unified Indicator plots breakout and directional labels on the price chart. It scores volume spikes against a volume average, range or opening-range breaks, optional VWAP or session-anchored VWAP, fast and slow EMA trend, and a higher-timeframe EMA

Indicator v6 BreakoutVolume Repaints
Updated 3 weeks ago · Custom licence GitHub repository of Point-Clip Unified Indicator
4 stars

This indicator recolors price candles from recent volume and range. It marks climax bars when current volume times range exceeds the prior ten-bar peak or volume is at least twice a ten-bar average, and rising bars at one and a half times that average. Bullish

Indicator v5 VolumeCandlestick patterns
Updated 9 months ago · None stated GitHub repository of Price-Volume Analysis

This overlay indicator draws rounded psychological price levels and optional PVSRA vector candle colors on the price chart. It plots quarter, half, and whole levels from a user-set rounding value, with separate color, line style, and width for each. Vector col

Indicator v5 Support & resistanceVolume
Updated 5 months ago · None stated GitHub repository of Level Theory + Vector Candles

Stella's Smart Money Proxy

by stella-entry
3 stars

This indicator detects institutional or large-scale market activity using candle body size and trading volume. It compares current candle bodies against a 20-period simple moving average and checks for volume spikes above an adjustable moving average filter. I

Indicator v6 VolumeCandlestick patterns
Updated 8 months ago · MIT GitHub repository of Stella's Smart Money Proxy

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers