Indicator · Pine Script v4 · On the chart

Support and Resistance (k)

by mikeyhu70· code credited to kaleboraciy

Detects pivot points and draws horizontal support and resistance lines on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code176
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago15 Apr 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

176 lines of Pine Script v4 from Supply and Demand/Support and Resistance kaleboraciy.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Support and Resistance kaleboraciy.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kaleboraciy

//@version=4
study("Support & Ressistance (k)", overlay = true, max_lines_count = 500, max_labels_count = 500)

mode_auto_TF = input(title="Auto Timeframe to Assess ?", defval='Manual', options=['Auto', 'Manual'])
res = input(title="resolution (if manual)", defval="", type=input.resolution)
//pivot_len = input(20, title = 'Pivot Points Length', type = input.integer)
mode_auto_len = input(title="Auto Pivot Length ?", defval='Auto', options=['Auto', 'Manual'])
_pivot_len = input(20, title = 'Pivot Points Length', type = input.integer)
//inacc = input(0.5, title = 'Inaccuracy', type = input.float, step = 0.1) / 100 * close
mode_auto_inacc= input(title="Auto Inaccuracy ?", defval='Auto', options=['Auto', 'Manual'])
_inacc = input(0.5, title = 'Inaccuracy', type = input.float, step = 0.1) / 100 * close 
width = input(12, title = 'Linewidth')
width2 = input(8, title = 'Linewidth of broken line')
show_broken = input(true, title = 'Сontinue broken lines?')
start = input(timestamp("2021-01-01"), type = input.time, title = 'Start calculations from')

time_cond = time >= start

auto_tf = timeframe.period == 'M' ? 'Y' : timeframe.period == 'W' ? 'M' : 
   timeframe.period == 'D' ? '2D' : timeframe.period == '360' ? 'D' : 
   timeframe.period == '240' ? 'D' : timeframe.period == '195' ? 'D' : 
   timeframe.period == '120' ? '240' : timeframe.period == '78' ? '120' : 
   timeframe.period == '60' ? '120' : timeframe.period == '45' ? '120' : 
   timeframe.period == '39' ? '60' : timeframe.period == '30' ? '60' : 
   timeframe.period == '20' ? '30' : timeframe.period == '15' ? '30' : timeframe.period == '10' ? '30' : 
   timeframe.period == '5' ? '15' : timeframe.period == '3' ? '15' : 
   timeframe.period == '2' ? '15' : timeframe.period == '1' ? '15' : '30'
   
_res = mode_auto_TF == 'Auto' ? auto_tf : res

auto_len= timeframe.period == 'M' ? 2 : timeframe.period == 'W' ? 2 : 
   timeframe.period == 'D' ? 2 : timeframe.period == '360' ? 2 : 
   timeframe.period == '240' ? 5 : timeframe.period == '195' ? 5 : 
   timeframe.period == '120' ? 8 : timeframe.period == '78' ? 10 : 
   timeframe.period == '60' ? 10 : timeframe.period == '45' ? 10 : 
   timeframe.period == '39' ? 10 : timeframe.period == '30' ? 10 : 
   timeframe.period == '20' ? 10 : timeframe.period == '15' ? 10 : timeframe.period == '10' ? 10 : 
   timeframe.period == '5' ? 10  : _pivot_len 
   
pivot_len = mode_auto_len == 'Auto' ? auto_len : _pivot_len

auto_inacc= timeframe.period == 'M' ? 4 : timeframe.period == 'W' ? 4 : 
   timeframe.period == 'D' ? 1 : timeframe.period == '360' ? 1 : 
   timeframe.period == '240' ? 1.0 : timeframe.period == '195' ? 1.0 : 
   timeframe.period == '120' ? 0.5 : timeframe.period == '78' ? 0.5 : 
   timeframe.period == '60' ? 0.5 : timeframe.period == '45' ? 0.5 : 
   timeframe.period == '39' ? 0.5 : timeframe.period == '30' ? 0.5: 
   timeframe.period == '20' ? 0.5: timeframe.period == '15' ? 0.5 : timeframe.period == '10' ? 0.5 : 
   timeframe.period == '5' ? 0.5 : _inacc 
   
inacc = mode_auto_inacc == 'Auto' ? auto_inacc/100*close : _inacc

hi = security(syminfo.tickerid, _res, high)
lo = security(syminfo.tickerid, _res, low)

max_bars_back(hi, 500)
max_bars_back(lo, 500)

//ph = pivothigh(high, pivot_len, pivot_len) 
//pl = pivotlow(low, pivot_len, pivot_len)

ph = pivothigh(hi, pivot_len, pivot_len) 
pl = pivotlow(lo, pivot_len, pivot_len)


f_crossing_level_up(sr, r) =>
    //(r > sr and r < sr[1])
    (r < sr and r > sr[1])
    
f_crossing_level_down(sr, r) =>
    //(r < sr and r > sr[1])
    (r > sr and r < sr[1])


var lines_upper = array.new_line(1)
var lines_lower = array.new_line(1)

if array.size(lines_upper) > 500
    array.shift(lines_upper)
    
if array.size(lines_lower) > 500
    array.shift(lines_lower)

// deleting bad levels

k = 0

for i = 0 to array.size(lines_upper) - 1
    line_price = line.get_y2(array.get(lines_upper, i - k))
    if high - inacc > line_price
        x1 = line.get_x1(array.get(lines_upper, i - k))
        x2 = line.get_x2(array.get(lines_upper, i - k))
        
        
        y1 = line.get_y1(array.get(lines_upper, i - k))
        
        if x1 != x2
            line.new(x1, y1, bar_index, y1, extend = extend.none, color = color.new(color.green, 60), width = width)
            line.set_x2(array.get(lines_upper, i - k), bar_index)
            //alert("Green level at "+ tostring(y1) + " has broken!", freq = alert.freq_once_per_bar)
            if f_crossing_level_up(close, y1)
                alert("SR (kaleboraciy): " + syminfo.ticker + " Green level at "+ tostring(y1) + " has crossed up! " + timeframe.period, freq = alert.freq_once_per_bar)
            else
                if f_crossing_level_down(close, y1)
                    alert("SR (kaleboraciy): " + syminfo.ticker + " Green level at "+ tostring(y1) + " has crossed down! " + timeframe.period, freq = alert.freq_once_per_bar)
            if show_broken
                line.new(time_close[1], y1, time_close + 1, y1, extend = extend.right, color = color.new(color.aqua, 85), width = width2, xloc = xloc.bar_time)
            
        line.delete(array.get(lines_upper, i - k))
        array.remove(lines_upper, i - k)
        
        k := k + 1
        
k := 0
        
for i = 0 to array.size(lines_lower) - 1
    line_price = line.get_y2(array.get(lines_lower, i - k))
    if low + inacc < line_price
        x1 = line.get_x1(array.get(lines_lower, i - k))
        x2 = line.get_x2(array.get(lines_lower, i - k))
        
        
        y1 = line.get_y1(array.get(lines_lower, i - k))
        
        if x1 != x2
            line.new(x1, y1, bar_index, y1, extend = extend.none, color = color.new(color.red, 60), width = width)
            line.set_x2(array.get(lines_lower, i - k), bar_index)
            //alert("Red level at "+ tostring(y1) + " has broken!", freq = alert.freq_once_per_bar)
            if f_crossing_level_up(close, y1)
                alert("SR (kaleboraciy): " + syminfo.ticker + " Red level at "+ tostring(y1) + " has crossed up! " + timeframe.period, freq = alert.freq_once_per_bar)
            else
                if f_crossing_level_down(close, y1)
                    alert("SR (kaleboraciy): " + syminfo.ticker + " Red level at "+ tostring(y1) + " has crossed down! " + timeframe.period, freq = alert.freq_once_per_bar)
            if show_broken
                line.new(time_close[1], y1, time_close + 1, y1, extend = extend.right, color = color.new(color.orange, 85), width = width2, xloc = xloc.bar_time)
            
        line.delete(array.get(lines_lower, i - k))
        array.remove(lines_lower, i - k)
        
        k := k + 1
        

    
if ph and time_cond
    bool flag = false
    for i = 0 to array.size(lines_upper) - 1
        line_price = line.get_y2(array.get(lines_upper, i))
        if ph >= line_price - inacc and ph <= line_price + inacc
            flag := true
            line.set_color(array.get(lines_upper, i), color.new(color.green, 60))
            line.set_x2(array.get(lines_upper, i), bar_index)
    if not flag
        array.push(lines_upper, line.new(bar_index[pivot_len], ph, bar_index[pivot_len], ph, color = na, extend = extend.right, width = width))
    
if pl and time_cond
    bool flag = false
    for i = 0 to array.size(lines_lower) - 1
        line_price = line.get_y2(array.get(lines_lower, i))
        if pl >= line_price - inacc and pl <= line_price + inacc
            flag := true
            line.set_color(array.get(lines_lower, i), color.new(color.red, 60))
            line.set_x2(array.get(lines_lower, i), bar_index)
    if not flag
        array.push(lines_lower, line.new(bar_index[pivot_len], pl, bar_index[pivot_len], pl, color = na, extend = extend.right, width = width))




            
// plot(array.size(lines_upper))

// plot(ph)
// plot(pl)

Overview

The pivot length, the accuracy tolerance and the timeframe used for assessment can each be automatic or manual. Line widths for active and broken lines can be set, broken lines can continue to be drawn, and a start date limits how far back calculation begins. It marks levels only and has no entries, exits or stops.

Details

Published by

mikeyhu70 on GitHub

Code credit

kaleboraciy, as written in the script's header

Type

Indicator, Pine Script v4

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
Auto Timeframe to Assess ?stringManualmode_auto_TF
resolution (if manual)timeframeres
Auto Pivot Length ?stringAutomode_auto_len
Pivot Points Lengthint20_pivot_len
Auto Inaccuracy ?stringAutomode_auto_inacc
Inaccuracyfloat0.5_inacc
Linewidthint12width
Linewidth of broken lineint8width2
Сontinue broken lines?booltrueshow_broken
Start calculations fromtimetimestamp("2021-01-01")start
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

947 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 11 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