Indicator · Pine Script v6 · On the chart

Best S&R Indicator With Candlestick Patterns

by theonetrade

The Best S&R Indicator With Candlestick Patterns identifies dynamic support and resistance zones directly on the main price chart using swing highs and lows.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code335
Settings11inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

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

335 lines of Pine Script v6 from assets/indicator/bit-exact/best_support_and_resistance_indicator_v1_forexbee_EaDischm.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

best_support_and_resistance_indicator_v1_forexbee_EaDischm.pine
//@version=6
indicator('Best S&R Indicator With Candlestick Patterns', overlay = true, max_lines_count = 500)

// ══════════════════════════════════════════
// INPUTS
// ══════════════════════════════════════════
Bars       = input.int(10,  'Swing Lookback (Bars)',            minval = 5, confirm = true)
NoOfPivots = input.int(2,   'Pivot Tests for Valid Zone',       options = [2, 3, 4], confirm = true)
ZoneExpiry = input.int(200, 'Zone Expiry (candles, 0 = never)', minval = 0)

ResColor    = input.color(color.red,                  'Resistance Color',      group = 'Zone Style')
SupColor    = input.color(color.green,                'Support Color',         group = 'Zone Style')
BrokenColor = input.color(color.new(color.gray, 60), 'Broken Zone Color',     group = 'Zone Style')
ZoneAlpha   = input.int(80, 'Zone Fill Transparency %', minval = 0, maxval = 100, group = 'Zone Style')
ShowBroken  = input.bool(true, 'Show Broken Zones (grayed)',                   group = 'Zone Style')

ShowPatterns = input.bool(true, 'Show Candle Pattern Labels', group = 'Patterns')

ShowProximityBG = false  // bgcolor removed per user request
ProximityPct    = input.float(0.3, 'Proximity % (buffer around zone)', minval = 0.05, step = 0.05, group = 'Proximity & Alerts')

ShowRetest = input.bool(true, 'Show Zone Retest Labels', group = 'Retest')

// ══════════════════════════════════════════
// PIVOTS
// ══════════════════════════════════════════
PivotHigh = ta.pivothigh(Bars, Bars)
PivotLow  = ta.pivotlow(Bars, Bars)

var bool InsideBarAtSupport = false

// ══════════════════════════════════════════
// RESISTANCE ZONE ARRAYS
// ══════════════════════════════════════════
var line[]  rTopLines  = array.new_line()
var line[]  rBotLines  = array.new_line()
var float[] rZoneHArr  = array.new_float()
var float[] rZoneLArr  = array.new_float()
var int[]   rZoneStart = array.new_int()
var bool[]  rWasAway   = array.new_bool()
var float   RZoneH     = na
var float   RZoneL     = na

// ══════════════════════════════════════════
// SUPPORT ZONE ARRAYS
// ══════════════════════════════════════════
var line[]  sTopLines  = array.new_line()
var line[]  sBotLines  = array.new_line()
var float[] sZoneHArr  = array.new_float()
var float[] sZoneLArr  = array.new_float()
var int[]   sZoneStart = array.new_int()
var bool[]  sWasAway   = array.new_bool()
var float   SZoneH     = na
var float   SZoneL     = na

// ══════════════════════════════════════════
// PIVOT HIGH VALUES (last 4)
// ══════════════════════════════════════════
IndexOfPivot  = ta.valuewhen(PivotHigh > 0, bar_index - Bars, 0)
HighAtPivot   = ta.valuewhen(PivotHigh > 0, high[Bars], 0)
UpperAtPivot  = ta.valuewhen(PivotHigh > 0, math.max(close[Bars], open[Bars]), 0)
IndexOfPivot1 = ta.valuewhen(PivotHigh > 0, bar_index - Bars, 1)
HighAtPivot1  = ta.valuewhen(PivotHigh > 0, high[Bars], 1)
UpperAtPivot1 = ta.valuewhen(PivotHigh > 0, math.max(close[Bars], open[Bars]), 1)
IndexOfPivot2 = ta.valuewhen(PivotHigh > 0, bar_index - Bars, 2)
HighAtPivot2  = ta.valuewhen(PivotHigh > 0, high[Bars], 2)
UpperAtPivot2 = ta.valuewhen(PivotHigh > 0, math.max(close[Bars], open[Bars]), 2)
IndexOfPivot3 = ta.valuewhen(PivotHigh > 0, bar_index - Bars, 3)
HighAtPivot3  = ta.valuewhen(PivotHigh > 0, high[Bars], 3)
UpperAtPivot3 = ta.valuewhen(PivotHigh > 0, math.max(close[Bars], open[Bars]), 3)

// ══════════════════════════════════════════
// PIVOT LOW VALUES (last 4)
// ══════════════════════════════════════════
IndexOfPivotl1 = ta.valuewhen(PivotLow > 0, bar_index - Bars, 1)
LowAtPivot     = ta.valuewhen(PivotLow > 0, low[Bars], 0)
LowerAtPivotl  = ta.valuewhen(PivotLow > 0, math.min(close[Bars], open[Bars]), 1)
LowAtPivot1    = ta.valuewhen(PivotLow > 0, low[Bars], 1)
IndexOfPivotl2 = ta.valuewhen(PivotLow > 0, bar_index - Bars, 2)
LowAtPivot2    = ta.valuewhen(PivotLow > 0, low[Bars], 2)
LowerAtPivot2  = ta.valuewhen(PivotLow > 0, math.min(close[Bars], open[Bars]), 2)
IndexOfPivotl3 = ta.valuewhen(PivotLow > 0, bar_index - Bars, 3)
LowAtPivot3    = ta.valuewhen(PivotLow > 0, low[Bars], 3)
LowerAtPivot3  = ta.valuewhen(PivotLow > 0, math.min(close[Bars], open[Bars]), 3)

// ══════════════════════════════════════════
// CANDLE PATTERN VARIABLES
// ══════════════════════════════════════════
bool alertcon = false
candle   = math.abs(high - low)
body     = math.abs(open - close)
BodyPerc = body / candle * 100

EvnCan    = body > candle * 0.6 and open > close and body[1] < candle[1] * 0.3 and body[2] > candle[2] * 0.6 and open[2] < close[2]
BInBar    = high < high[1] and low > low[1] and body[1] > candle[1] * 0.4
MorCan    = body > candle * 0.6 and open < close and body[1] < candle[1] * 0.3 and body[2] > candle[2] * 0.6 and open[2] > close[2]
BullInBar = high < high[1] and low > low[1] and body[1] > candle[1] * 0.4
bperc     = (high[1] - low[1]) / 100 * 5
bpercc    = (high[1] - low[1]) / 100 * 60
tbc = low > low[1] - bperc and low < low[1] + bperc and close > low[1] + bpercc and open[1] > close[1] and close[1] - low[1] < bperc and open - low < bperc and BodyPerc > 60 and BodyPerc[1] > 60
ttc = high > high[1] - bperc and high < high[1] + bperc and close < high[1] - bpercc and open[1] < close[1] and high[1] - close[1] < bperc and high - open < bperc and BodyPerc > 60 and BodyPerc[1] > 60

EvnCanHigh   = ta.valuewhen(EvnCan,    high[1], 0)
BInBarHigh   = ta.valuewhen(BInBar,    high[1], 0)
MorCanLow    = ta.valuewhen(MorCan,    low[1],  0)
BullInBarLow = ta.valuewhen(BullInBar, low[1],  0)
TTopH        = ta.valuewhen(ttc, math.max(high, high[1]), 0)
TBotL        = ta.valuewhen(tbc, math.min(low,  low[1]),  0)

// ══════════════════════════════════════════
// HELPERS
// ══════════════════════════════════════════
addResZone(startIdx, zH, zL) =>
    tl = line.new(startIdx, zH, bar_index, zH, color = ResColor, width = 1)
    bl = line.new(startIdx, zL, bar_index, zL, color = ResColor, width = 1)
    linefill.new(tl, bl, color = color.new(ResColor, ZoneAlpha))
    array.push(rTopLines, tl)
    array.push(rBotLines, bl)
    array.push(rZoneHArr, zH)
    array.push(rZoneLArr, zL)
    array.push(rZoneStart, bar_index)
    array.push(rWasAway, true)  // price already below zone at detection

addSupZone(startIdx, zH, zL) =>
    tl = line.new(startIdx, zH, bar_index, zH, color = SupColor, width = 1)
    bl = line.new(startIdx, zL, bar_index, zL, color = SupColor, width = 1)
    linefill.new(tl, bl, color = color.new(SupColor, ZoneAlpha))
    array.push(sTopLines, tl)
    array.push(sBotLines, bl)
    array.push(sZoneHArr, zH)
    array.push(sZoneLArr, zL)
    array.push(sZoneStart, bar_index)
    array.push(sWasAway, true)  // price already above zone at detection

// ══════════════════════════════════════════
// DETECT NEW RESISTANCE ZONES
// ══════════════════════════════════════════
if PivotHigh > 0
    if NoOfPivots == 2 and HighAtPivot < HighAtPivot1 and HighAtPivot > UpperAtPivot1
        RZoneH := HighAtPivot1
        RZoneL := UpperAtPivot1
        alertcon := true
        addResZone(IndexOfPivot1, HighAtPivot1, UpperAtPivot1)
    if NoOfPivots == 3 and HighAtPivot < HighAtPivot2 and HighAtPivot > UpperAtPivot2 and HighAtPivot1 < HighAtPivot2 and HighAtPivot1 > UpperAtPivot2
        RZoneH := HighAtPivot2
        RZoneL := UpperAtPivot2
        alertcon := true
        addResZone(IndexOfPivot2, HighAtPivot2, UpperAtPivot2)
    if NoOfPivots == 4 and HighAtPivot < HighAtPivot3 and HighAtPivot > UpperAtPivot3 and HighAtPivot1 < HighAtPivot3 and HighAtPivot1 > UpperAtPivot3 and HighAtPivot2 < HighAtPivot3 and HighAtPivot2 > UpperAtPivot3
        RZoneH := HighAtPivot3
        RZoneL := UpperAtPivot3
        alertcon := true
        addResZone(IndexOfPivot3, HighAtPivot3, UpperAtPivot3)

// ══════════════════════════════════════════
// DETECT NEW SUPPORT ZONES
// ══════════════════════════════════════════
if PivotLow > 0
    if NoOfPivots == 2 and LowAtPivot > LowAtPivot1 and LowAtPivot < LowerAtPivotl
        SZoneH := LowerAtPivotl
        SZoneL := LowAtPivot1
        alertcon := true
        addSupZone(IndexOfPivotl1, LowerAtPivotl, LowAtPivot1)
    if NoOfPivots == 3 and LowAtPivot > LowAtPivot2 and LowAtPivot < LowerAtPivot2 and LowAtPivot1 > LowAtPivot2 and LowAtPivot1 < LowerAtPivot2
        SZoneH := LowerAtPivot2
        SZoneL := LowAtPivot2
        alertcon := true
        addSupZone(IndexOfPivotl2, LowerAtPivot2, LowAtPivot2)
    if NoOfPivots == 4 and LowAtPivot > LowAtPivot3 and LowAtPivot < LowerAtPivot3 and LowAtPivot1 > LowAtPivot3 and LowAtPivot1 < LowerAtPivot3 and LowAtPivot2 > LowAtPivot3 and LowAtPivot2 < LowerAtPivot3
        SZoneH := LowerAtPivot3
        SZoneL := LowAtPivot3
        alertcon := true
        addSupZone(IndexOfPivotl3, LowerAtPivot3, LowAtPivot3)

// ══════════════════════════════════════════
// UPDATE RESISTANCE ZONES (extend / break / expire / proximity / retest)
// ══════════════════════════════════════════
bool nearResistance = false
bool proxAlertRes   = false

if array.size(rTopLines) > 0
    i = array.size(rTopLines) - 1
    while i >= 0
        zH       = array.get(rZoneHArr,  i)
        zL       = array.get(rZoneLArr,  i)
        startBar = array.get(rZoneStart, i)
        tl       = array.get(rTopLines,  i)
        bl       = array.get(rBotLines,  i)
        wasAway  = array.get(rWasAway,   i)
        isBroken  = close > zH
        isExpired = ZoneExpiry > 0 and (bar_index - startBar) > ZoneExpiry

        if isBroken or isExpired
            if ShowBroken and isBroken
                line.set_color(tl, BrokenColor)
                line.set_color(bl, BrokenColor)
            array.remove(rTopLines, i)
            array.remove(rBotLines, i)
            array.remove(rZoneHArr, i)
            array.remove(rZoneLArr, i)
            array.remove(rZoneStart, i)
            array.remove(rWasAway,  i)
        else
            line.set_x2(tl, bar_index)
            line.set_x2(bl, bar_index)

            // — Proximity (within ProximityPct% buffer around zone)
            buf = zH * ProximityPct / 100
            if close > zL - buf and close < zH + buf
                nearResistance := true
                proxAlertRes   := true

            // — Retest: price was below zone, now re-enters it
            if close < zL
                array.set(rWasAway, i, true)
            if wasAway and close >= zL and close <= zH and (bar_index - startBar) > 2
                if ShowRetest
                    label.new(bar_index, high, '⟳ R Retest', color = ResColor, textcolor = color.white, style = label.style_label_down, size = size.small)
                array.set(rWasAway, i, false)
        i -= 1

// ══════════════════════════════════════════
// UPDATE SUPPORT ZONES (extend / break / expire / proximity / retest)
// ══════════════════════════════════════════
bool nearSupport  = false
bool proxAlertSup = false

if array.size(sTopLines) > 0
    i = array.size(sTopLines) - 1
    while i >= 0
        zH       = array.get(sZoneHArr,  i)
        zL       = array.get(sZoneLArr,  i)
        startBar = array.get(sZoneStart, i)
        tl       = array.get(sTopLines,  i)
        bl       = array.get(sBotLines,  i)
        wasAway  = array.get(sWasAway,   i)
        isBroken  = close < zL
        isExpired = ZoneExpiry > 0 and (bar_index - startBar) > ZoneExpiry

        if isBroken or isExpired
            if ShowBroken and isBroken
                line.set_color(tl, BrokenColor)
                line.set_color(bl, BrokenColor)
            array.remove(sTopLines, i)
            array.remove(sBotLines, i)
            array.remove(sZoneHArr, i)
            array.remove(sZoneLArr, i)
            array.remove(sZoneStart, i)
            array.remove(sWasAway,  i)
        else
            line.set_x2(tl, bar_index)
            line.set_x2(bl, bar_index)

            // — Proximity
            buf = zH * ProximityPct / 100
            if close > zL - buf and close < zH + buf
                nearSupport  := true
                proxAlertSup := true

            // — Retest: price was above zone, now re-enters it
            if close > zH
                array.set(sWasAway, i, true)
            if wasAway and close <= zH and close >= zL and (bar_index - startBar) > 2
                if ShowRetest
                    label.new(bar_index, low, '⟳ S Retest', color = SupColor, textcolor = color.white, style = label.style_label_up, size = size.small)
                array.set(sWasAway, i, false)
        i -= 1



// ══════════════════════════════════════════
// PATTERNS — checked against ALL active zones
// ══════════════════════════════════════════
if ShowPatterns
    rSize = array.size(rZoneHArr)
    sSize = array.size(sZoneHArr)

    // Evening Star → any resistance zone
    if EvnCan and rSize > 0
        patOffset1 = (high[1] - low[1]) * 0.6
        for j = 0 to rSize - 1
            if EvnCanHigh < array.get(rZoneHArr, j) and EvnCanHigh > array.get(rZoneLArr, j)
                label.new(bar_index[1], high[1] + patOffset1, 'Evening Star', color = color.orange, textcolor = color.white, style = label.style_label_down)
                break

    // Inside Bar at Resistance → any resistance zone
    if BInBar and rSize > 0
        patOffset2 = (high[1] - low[1]) * 0.6
        for j = 0 to rSize - 1
            if BInBarHigh < array.get(rZoneHArr, j) and BInBarHigh > array.get(rZoneLArr, j)
                label.new(bar_index[1], high[1] + patOffset2, 'Inside Bar', color = color.rgb(224, 67, 5), textcolor = color.white, style = label.style_label_down)
                break

    // Tweezer Top → any resistance zone
    if ttc and rSize > 0
        patOffset3 = (high[1] - low[1]) * 0.6
        for j = 0 to rSize - 1
            if TTopH < array.get(rZoneHArr, j) and TTopH > array.get(rZoneLArr, j)
                label.new(bar_index[1], high[1] + patOffset3, 'Tweezer Top', color = color.rgb(255, 0, 208), textcolor = color.white, style = label.style_label_down)
                break

    // Morning Star → any support zone
    if MorCan and sSize > 0
        patOffset4 = (high[1] - low[1]) * 0.6
        for j = 0 to sSize - 1
            if MorCanLow < array.get(sZoneHArr, j) and MorCanLow > array.get(sZoneLArr, j)
                label.new(bar_index[1], low[1] - patOffset4, 'Morning Star', color = color.orange, textcolor = color.white, style = label.style_label_up)
                break

    // Inside Bar at Support → any support zone
    if BullInBar and sSize > 0
        patOffset5 = (high[1] - low[1]) * 0.6
        for j = 0 to sSize - 1
            if BullInBarLow < array.get(sZoneHArr, j) and BullInBarLow > array.get(sZoneLArr, j)
                label.new(bar_index[1], low[1] - patOffset5, 'Inside Bar', color = color.rgb(255, 72, 0), textcolor = color.white, style = label.style_label_up)
                InsideBarAtSupport := true
                break

    // Tweezer Bottom → any support zone
    if tbc and sSize > 0
        patOffset6 = (high[1] - low[1]) * 0.6
        for j = 0 to sSize - 1
            if TBotL < array.get(sZoneHArr, j) and TBotL > array.get(sZoneLArr, j)
                label.new(bar_index[1], low[1] - patOffset6, 'Tweezer Bottom', color = color.rgb(255, 0, 208), textcolor = color.white, style = label.style_label_up)
                break

// ══════════════════════════════════════════
// PLOTS & ALERTS
// ══════════════════════════════════════════
plot(PivotHigh, style = plot.style_cross, linewidth = 3, color = color.red,             offset = -Bars)
plot(PivotLow,  style = plot.style_cross, linewidth = 3, color = color.rgb(0, 208, 52), offset = -Bars)

alertcondition(alertcon,    title = 'New S/R Zone Detected',    message = 'A new Support or Resistance zone has formed')
alertcondition(proxAlertRes, title = 'Price Near Resistance',   message = 'Price is approaching a Resistance zone')
alertcondition(proxAlertSup, title = 'Price Near Support',      message = 'Price is approaching a Support zone')

Overview

Best S&R Indicator With Candlestick Patterns validates zones based on a user-defined number of pivot touches and tracks expiration or breakage over time. The indicator can display candlestick pattern labels, zone retest indicators, and visual styling for broken levels. Settings allow customization of swing lookback length, pivot threshold rules, buffer proximity percentages, and color schemes.

Details

Published by

theonetrade on GitHub

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Swing Lookback (Bars)int10Bars
Pivot Tests for Valid Zoneint2NoOfPivots
Zone Expiry (candles, 0 = never)int200ZoneExpiry
Resistance Colorcolorcolor.redResColor
Support Colorcolorcolor.greenSupColor
Broken Zone Colorcolorcolor.new(color.gray, 60)BrokenColor
Zone Fill Transparency %int80ZoneAlpha
Show Broken Zones (grayed)booltrueShowBroken
Show Candle Pattern LabelsbooltrueShowPatterns
Proximity % (buffer around zone)float0.3ProximityPct
Show Zone Retest LabelsbooltrueShowRetest
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

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 5 years ago · None stated GitHub repository of [RS]MTF Candle Sticks

Candlestick Patterns

by harryguiacorn
220 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Strat Assistant

by rickyzcarroll
90 stars

The Strat Assistant indicator identifies candlestick patterns from the STRAT methodology on the price chart. It detects inside bars, 2-candle directional bars, 3-candle outside bars, and sequences like 212 and 222 for continuations and reversals. Shapes such a

Indicator v4 Candlestick patternsSupport & resistance
Updated 5 years ago · None stated GitHub repository of Strat Assistant
56 stars

This overlay indicator highlights candles with a body smaller than 50% of their total range by coloring them white on the price chart. Simultaneously, it calculates and plots horizontal lines for open prices across multiple higher timeframes, such as daily, we

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 3 months ago · None stated GitHub repository of Daily Weekly Monthly Yearly Opens

This Pine Script indicator identifies liquidity sweeps and confirms signals using a close-back candle pattern directly on the price chart. It tracks recent swing highs and lows over a customizable lookback period. A bullish signal forms when a prior bar sweeps

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 3 months ago · MPL-2.0 GitHub repository of Liquidity Sweep + Close-Back Confirmation

8020 System Indicator

by TamaraKGreen
47 stars

This overlay indicator draws 80/20 price levels and optional 40-point zone bands on the price chart. It marks repairs, cross sections, and forks with optional letter labels, and can highlight confluence when those marks sit near a level. Separate options shade

Indicator v6 Support & resistanceCandlestick patterns
Updated 2 months ago · None stated GitHub repository of 8020 System Indicator

More Support & resistance scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers