Indicator · Pine Script v6 · On the chart

BIN Based Support and Resistance [SS]

by regalouisei· code credited to Steversteves

This indicator divides the lookback range between the highest and lowest close into ten equal price bins and plots each bin’s average close as a support or resistance level on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code143
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 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

143 lines of Pine Script v6 from pinescript/editors_picks/bin-based-support-and-resistance-ss.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

bin-based-support-and-resistance-ss.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Steversteves
//  /$$$$$$   /$$                                                         /$$                                            
// /$$__  $$ | $$                                                        | $$                                            
//| $$  \__//$$$$$$    /$$$$$$  /$$    /$$ /$$$$$$   /$$$$$$   /$$$$$$$ /$$$$$$    /$$$$$$  /$$    /$$ /$$$$$$   /$$$$$$$
//|  $$$$$$|_  $$_/   /$$__  $$|  $$  /$$//$$__  $$ /$$__  $$ /$$_____/|_  $$_/   /$$__  $$|  $$  /$$//$$__  $$ /$$_____/
// \____  $$ | $$    | $$$$$$$$ \  $$/$$/| $$$$$$$$| $$  \__/|  $$$$$$   | $$    | $$$$$$$$ \  $$/$$/| $$$$$$$$|  $$$$$$ 
// /$$  \ $$ | $$ /$$| $$_____/  \  $$$/ | $$_____/| $$       \____  $$  | $$ /$$| $$_____/  \  $$$/ | $$_____/ \____  $$
//|  $$$$$$/ |  $$$$/|  $$$$$$$   \  $/  |  $$$$$$$| $$       /$$$$$$$/  |  $$$$/|  $$$$$$$   \  $/  |  $$$$$$$ /$$$$$$$/
// \______/   \___/   \_______/    \_/    \_______/|__/      |_______/    \___/   \_______/    \_/    \_______/|_______/ 

//@version=6
indicator("BIN Based Support and Resistance [SS]", overlay=true)
lookback = input.int(500, "Lookback Length") 
displaylabel = input.string("On SR lines", "Where would you like the statistics to display?", ["On SR lines", "Table", "OFF"])
offset = input.int(100, "Offset the lines ahead") 
max = ta.highest(close, lookback) 
min = ta.lowest(close, lookback) 

bins = (max - min) / 10 

lbin1 = min + bins 
lbin2 = lbin1 + bins 
lbin3 = lbin2 + bins 
lbin4 = lbin3 + bins 
lbin5 = lbin4 + bins 
ubin10 = max - bins 
ubin9 = ubin10 - bins 
ubin8 = ubin9 - bins 
ubin7 = ubin8 - bins 
ubin6 = ubin7 -bins 

bool bin1 = close >= min and close < lbin1 
bool bin2 = close >= lbin1 and close < lbin2 
bool bin3 = close >= lbin2 and close < lbin3 
bool bin4 = close >= lbin3 and close < lbin4 
bool bin5 = close >= lbin4 and close < lbin5 
bool bin6 = close >= lbin5 and close < ubin6 
bool bin7 = close >= ubin6 and close < ubin7 
bool bin8 = close >= ubin7 and close < ubin8 
bool bin9 = close >= ubin8 and close < ubin9 
bool bin10 = close >= ubin10 


ar() => 
    array.new<float>() 

bin1a = ar(), bin2a = ar(), bin3a = ar(), bin4a = ar(), bin5a = ar(), bin6a = ar(), bin7a = ar(), bin8a = ar(), bin9a = ar(), bin10a = ar() 

for i = 0 to lookback 
    if bin1[i]
        bin1a.push(close[i])
    else if bin2[i]
        bin2a.push(close[i])
    else if bin3[i]
        bin3a.push(close[i])
    else if bin4[i]
        bin4a.push(close[i])
    else if bin5[i]
        bin5a.push(close[i])
    else if bin6[i]
        bin6a.push(close[i])
    else if bin7[i]
        bin7a.push(close[i])
    else if bin8[i]
        bin8a.push(close[i])
    else if bin9[i]
        bin9a.push(close[i])
    else if bin10[i]
        bin10a.push(close[i])
    else 
        na

sr1 = array.avg(bin1a), sr2 = array.avg(bin2a), sr3 = array.avg(bin3a), sr4 = array.avg(bin4a), sr5 = array.avg(bin5a), sr6 = array.avg(bin6a), sr7 = array.avg(bin7a), sr8 = array.avg(bin8a)
sr9 = array.avg(bin9a), sr10 = array.avg(bin10a) 


// statistica 

calculate_statistics(bin, lookback) =>
    bool bullish_rejection = high[2] >= bin and close < bin 
    bool bearish_rejection = low[2] <= bin and close > bin 

    int reject_bull = 0 
    int reject_bear = 0 
    for i = 0 to lookback 
        if bullish_rejection[i]
            reject_bull += 1 
        if bearish_rejection[i]
            reject_bear += 1 
    
    support_success = (reject_bear/ (reject_bear + reject_bull)) * 100 
    resistance_success = (reject_bull / (reject_bear + reject_bull)) * 100 
    [support_success, resistance_success]


[sr1_ss, sr1_rs] = calculate_statistics(sr1, lookback)
[sr2_ss, sr2_rs] = calculate_statistics(sr2, lookback)
[sr3_ss, sr3_rs] = calculate_statistics(sr3, lookback)
[sr4_ss, sr4_rs] = calculate_statistics(sr4, lookback)
[sr5_ss, sr5_rs] = calculate_statistics(sr5, lookback)
[sr6_ss, sr6_rs] = calculate_statistics(sr6, lookback)
[sr7_ss, sr7_rs] = calculate_statistics(sr7, lookback)
[sr8_ss, sr8_rs] = calculate_statistics(sr8, lookback)
[sr9_ss, sr9_rs] = calculate_statistics(sr9, lookback)
[sr10_ss, sr10_rs] = calculate_statistics(sr10, lookback)

// Gradient colours 

color[] gradient_array = array.from(#ff00c8, #e100ff, #0d00ff, #007bff, #00ffd5, #00ff15, #00ff15, #ffc400, #ff7700, #ff1500, #ff008c, #e3000b)

// Combine data 
sr_array = array.from(sr1, sr2, sr3, sr4, sr5, sr6, sr7, sr8, sr9, sr10, max, min)
support_success_array = array.from(sr1_ss, sr2_ss, sr3_ss, sr4_ss, sr5_ss, sr6_ss, sr7_ss, sr8_ss, sr9_ss, sr10_ss, 0, 100)
resistance_success_array = array.from(sr1_rs, sr2_rs, sr3_rs, sr4_rs, sr5_rs, sr6_rs, sr7_rs, sr8_rs, sr9_rs, sr10_rs, 100, 0)
num_array = array.from(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)

create_label(idx) => 
    label.new(bar_index + offset, array.get(sr_array, idx), text = "% Success as Support: " + str.tostring(array.get(support_success_array, idx)) + "\n % Success as Resistance: " + str.tostring(array.get(resistance_success_array, idx)), color = na, style = label.style_label_right, size = size.normal)


if barstate.islast 
    for lines in line.all 
        line.delete(lines) 
    for labels in label.all 
        label.delete(labels)

if barstate.islast
    for i = 0 to array.size(sr_array) - 1 
        line.new(bar_index - lookback, array.get(sr_array, i), bar_index + offset, array.get(sr_array, i), color = array.get(gradient_array, i), width = 1)
        line.new(bar_index - lookback, array.get(sr_array, i), bar_index + offset, array.get(sr_array, i), color = color.new(array.get(gradient_array, i), 70), width = 3)
        line.new(bar_index - lookback, array.get(sr_array, i), bar_index + offset, array.get(sr_array, i), color = color.new(array.get(gradient_array, i), 80), width = 6)
        line.new(bar_index - lookback, array.get(sr_array, i), bar_index + offset, array.get(sr_array, i), color = color.new(array.get(gradient_array, i), 95), width = 8)
        if displaylabel == "On SR lines"
            create_label(i) 
        if displaylabel == "Table"
            label.new(bar_index + offset, array.get(sr_array, i), text = str.tostring(array.get(num_array,i)), color = na, textcolor = color.white)
            table data = table.new(position.middle_right, 3, 14, bgcolor = color.new(color.rgb(0, 0, 0), 65))
            for j = 0 to array.size(sr_array) - 1 
                table.cell(data, 1, 1, text = "SR Line", text_color = color.white) 
                table.cell(data, 2, 1, text = "Backtest Results", text_color = color.white) 
                table.cell(data, 1, 2 + j, text = str.tostring(array.get(num_array, j)), bgcolor = array.get(gradient_array, j), text_color = color.black) 
                table.cell(data, 2, 2 + j, text = "% Support Success: " + str.tostring(math.round(array.get(support_success_array, j), 2)) + "\n % Resistance Success: " + str.tostring(math.round(array.get(resistance_success_array, j), 2)), text_color = color.white)

Overview

BIN Based Support and Resistance [SS] counts bullish and bearish rejections of those levels over the same lookback and can show those statistics on the lines, in a table, or not at all. Lookback length and a forward line offset are the main controls. No trade signals or risk rules are defined.

Details

Published by

regalouisei on GitHub

Code credit

Steversteves, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance

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.

Settings

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

SettingTypeDefaultVariable
Lookback Lengthint500lookback
Where would you like the statistics to display?stringOn SR linesdisplaylabel
Offset the lines aheadint100offset
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

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

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