Indicator · Pine Script v4 · On the chart

Auto Support + Resistance Levels

by krosenfeld7

This indicator automatically identifies and plots horizontal support and resistance levels directly on the price chart using pivot detection logic.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code185
Settings13inputs
LicenceApache-2.0
Last update3 years ago12 May 2023

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

185 lines of Pine Script v4 from Auto_Support+Resistance_Levels.txt, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

Auto_Support+Resistance_Levels.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © krosenfeld7

//@version=4
study(title="Auto Support + Resistance Levels", shorttitle="Auto Support/Resistance Tool", overlay=true)

barsback          = input(title = "Price Pivot Lookback", type = input.integer, defval = 6, minval = 1)
lookback          = input(title = "RSI Pivot Lookback",   type = input.integer, defval = 15, minval = 1)
lineExtensionStr  = input(title = "Level Extension",      type = input.string,  defval = "None", options = ["None", "Left", "Right", "Both"])
lineWidth         = input(title = "Line Width",           type = input.integer, defval = 3, minval = 1)

lineExtension = extend.none

if lineExtensionStr == "Left"
    lineExtension := extend.left
else if lineExtensionStr == "Right"
    lineExtension := extend.right
else if lineExtensionStr == "Both"
    lineExtension := extend.both

len1 = input(14, minval = 1, title = "RSI Length")
src1 = input(close, "RSI Source", type = input.source)

rsiOver      = input(title = "RSI Highline",   type = input.integer, defval = 70, minval = 70, maxval = 90)
rsiMid       = input(title = "RSI Midline",    type = input.integer, defval = 50, minval = 30, maxval = 70)
rsiUnder     = input(title = "RSI Lowline",    type = input.integer, defval=  30, maxval = 30, minval = 10)
rsiMode      = input(title = "RSI Mode",       type = input.bool,    defval = false)

displayDiag       = input(title = "High/Low Diag Line",        type = input.bool, defval = true)
displaySupport    = input(title = "Display Support Levels",    type = input.bool, defval = true)
displayResistance = input(title = "Display Resistance Levels", type = input.bool, defval = true)

barsback := rsiMode ? lookback : barsback

up   = rma(max(change(src1), 0), len1)
down = rma(-min(change(src1), 0), len1)
rsi  = ((down == 0) ? 100 : ((up == 0) ? 0 : (100 - (100 / (1 + up / down)))))

whiteLight    = color.new(color.white,  transp = 95)
whiteMed      = color.new(color.white,  transp = 85)
whiteDark     = color.new(color.white,  transp = 75)
rsiModeWhite  = color.new(color.white,  transp = 0)
rsiModeBlue   = color.new(color.blue,   transp = 0)
rsiModeOrange = color.new(color.orange, transp = 0)

plot(rsi, "RSI", color=rsiMode ? rsiModeOrange : na, linewidth=2)

band80 = hline(rsiOver + 10,  "Upper Band",  color = rsiMode ? rsiModeWhite : na, linewidth = 1, linestyle = hline.style_dashed)
band50 = hline(rsiMid,        "Middle Band", color = rsiMode ? rsiModeBlue  : na, linewidth = 1, linestyle = hline.style_solid)
band20 = hline(rsiUnder - 10, "Lower Band",  color = rsiMode ? rsiModeWhite : na, linewidth = 1, linestyle = hline.style_dashed)
band70 = hline(rsiOver,       "Upper Band",  color = rsiMode ? rsiModeWhite : na, linewidth = 1, linestyle = hline.style_dashed)
band30 = hline(rsiUnder,      "Lower Band",  color = rsiMode ? rsiModeWhite : na, linewidth = 1, linestyle = hline.style_dashed)
fill(band50, band70, color = rsiMode ? whiteLight : na, title = "Background")
fill(band30, band50, color = rsiMode ? whiteLight : na, title = "Background")
fill(band70, band80, color = rsiMode ? whiteMed : na,   title = "Background")
fill(band20, band30, color = rsiMode ? whiteMed : na,   title = "Background")

fill(band80, hline(100, color = rsiMode ? rsiModeWhite : na, linestyle = hline.style_solid, linewidth = 2), color = rsiMode ? whiteDark : na, title = "Background")
fill(hline(0, color = rsiMode ? rsiModeWhite : na, linestyle = hline.style_solid, linewidth = 2), band20, color = rsiMode ? whiteDark : na, title = "Background")

var bool priceHighSet = na
var bool priceLowSet  = na
var bool rsiHighSet   = na
var bool rsiLowSet    = na

highIndex = 0
highPrice = 0.0
lowIndex  = 0
lowPrice  = 0.0

lowRSIIndex  = 0
lowRSI       = 0.0
highRSIIndex = 0
highRSI      = 0.0

currPriceHigh = pivothigh(high, barsback, barsback)
currPriceLow  = pivotlow(low,   barsback, barsback)

extension   = barssince(not na(currPriceHigh)) < barssince(not na(currPriceLow))
retracement = barssince(not na(currPriceHigh)) > barssince(not na(currPriceLow))

lastPriceLowIndex  = barssince(not na(priceLowSet))
lastPriceHighIndex = barssince(not na(priceHighSet))

priceHighSet := not na(currPriceHigh) ? true : na
priceLowSet  := not na(currPriceLow)  ? true : na

currHigh = pivothigh(rsi, barsback, barsback)
currLow  = pivotlow(rsi,  barsback, barsback)

extensionRSI   = barssince(not na(currHigh)) < barssince(not na(currLow))
retracementRSI = barssince(not na(currHigh)) > barssince(not na(currLow))

lastRSILowIndex  = barssince(not na(rsiLowSet))
lastRSIHighIndex = barssince(not na(rsiHighSet))

rsiHighSet := not na(currHigh) ? true : na
rsiLowSet  := not na(currLow)  ? true : na

// Note locally scoped lines sometimes do not plot
var line diagLine = na
var line highLine = na
var line lowLine  = na

highColor = color.new(color.red,   transp=0)
lowColor  = color.new(color.green, transp=0)
diagColor = color.new(color.white, transp=0)

set_coord_line(_line, _x1, _x2, _y1, _y2) =>
    line.set_x1(_line, _x1)
    line.set_x2(_line, _x2)
    line.set_y1(_line, _y1)
    line.set_y2(_line, _y2)
    _line

update_line(_line, _style, _width, _color, _extend) =>
    line.set_style(_line, _style)
    line.set_width(_line, _width)
    line.set_color(_line, _color)
    line.set_extend(_line, _extend)
    _line

if extension and not extension[1] and not rsiMode and not na(currPriceHigh)
    highIndex := bar_index - barsback
    highPrice := currPriceHigh
    lowIndex  := bar_index - barsback - lastPriceLowIndex - 1
    lowPrice  := low[lastPriceLowIndex + barsback + 1]
    
    if displayDiag
        diagLine := set_coord_line(line.new(0,0,0,0), lowIndex, highIndex, lowPrice, highPrice)
        diagLine := update_line(diagLine, line.style_dashed, 2, diagColor, extend.none)
    if displayResistance
        highLine := set_coord_line(line.new(0,0,0,0), lowIndex, highIndex, highPrice, highPrice)
        highLine := update_line(highLine, line.style_solid, lineWidth, highColor, lineExtension)
    if displaySupport
        lowLine  := set_coord_line(line.new(0,0,0,0), lowIndex, highIndex, lowPrice, lowPrice)
        lowLine  := update_line(lowLine, line.style_solid, lineWidth, lowColor, lineExtension)
        
if extensionRSI and not extensionRSI[1] and rsiMode and not na(currHigh)
    lowIndex  := bar_index - barsback - lastRSILowIndex - 1
    lowRSI    := rsi[barsback + lastRSILowIndex + 1]
    highIndex := bar_index - barsback
    highRSI   := rsi[barsback]
    
    if displayDiag
        diagLine := set_coord_line(line.new(0,0,0,0), lowIndex, highIndex, lowRSI, highRSI)
        diagLine := update_line(diagLine, line.style_dashed, 2, diagColor, extend.none)
    if displayResistance
        highLine := set_coord_line(line.new(0,0,0,0), lowIndex, highIndex, highRSI, highRSI)
        highLine := update_line(highLine, line.style_solid, lineWidth, highColor, lineExtension)
    if displaySupport
        lowLine  := set_coord_line(line.new(0,0,0,0), lowIndex, highIndex, lowRSI, lowRSI)
        lowLine  := update_line(lowLine, line.style_solid, lineWidth, lowColor, lineExtension)
        
if retracement and not retracement[1] and not rsiMode and not na(currPriceLow)
    lowIndex  := bar_index - barsback
    lowPrice  := currPriceLow
    highIndex := bar_index - barsback - lastPriceHighIndex - 1
    highPrice := high[lastPriceHighIndex + barsback + 1]
    
    if displayDiag
        diagLine := set_coord_line(line.new(0,0,0,0), highIndex, lowIndex, highPrice, lowPrice)
        diagLine := update_line(diagLine, line.style_dashed, 2, diagColor, extend.none)
    if displayResistance
        highLine := set_coord_line(line.new(0,0,0,0), highIndex, lowIndex, highPrice, highPrice)
        highLine := update_line(highLine, line.style_solid, lineWidth, highColor, lineExtension)
    if displaySupport
        lowLine  := set_coord_line(line.new(0,0,0,0), highIndex, lowIndex, lowPrice, lowPrice)
        lowLine  := update_line(lowLine, line.style_solid, lineWidth, lowColor, lineExtension)
        
if retracementRSI and not retracementRSI[1] and rsiMode and not na(currLow)
    lowIndex  := bar_index - barsback
    lowRSI    := rsi[barsback]
    highIndex := bar_index - barsback - lastRSIHighIndex - 1
    highRSI   := rsi[barsback + lastRSIHighIndex + 1]
    
    if displayDiag
        diagLine := set_coord_line(line.new(0,0,0,0), highIndex, lowIndex, highRSI, lowRSI)
        diagLine := update_line(diagLine, line.style_dashed, 2, diagColor, extend.none)
    if displayResistance
        highLine := set_coord_line(line.new(0,0,0,0), highIndex, lowIndex, highRSI, highRSI)
        highLine := update_line(highLine, line.style_solid, lineWidth, highColor, lineExtension)
    if displaySupport
        lowLine  := set_coord_line(line.new(0,0,0,0), highIndex, lowIndex, lowRSI, lowRSI)
        lowLine  := update_line(lowLine, line.style_solid, lineWidth, lowColor, lineExtension)

Overview

Users can base pivots on either price action lookback or RSI oscillator lookback when RSI mode is enabled. The script offers visual customization options, including customizable line widths, extension directions (left, right, or both), diagonal high/low lines, and toggles to display support or resistance levels independently. It also includes an integrated RSI overlay option with customizable overbought, oversold, and midline threshold levels.

Details

Published by

krosenfeld7 on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Oscillators & momentum

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
Price Pivot Lookbackint6barsback
RSI Pivot Lookbackint15lookback
Level ExtensionstringNonelineExtensionStr
Line Widthint3lineWidth
RSI Lengthint14len1
RSI Sourcesourceclosesrc1
RSI Highlineint70rsiOver
RSI Midlineint50rsiMid
RSI Lowlineint30rsiUnder
RSI ModeboolfalsersiMode
High/Low Diag LinebooltruedisplayDiag
Display Support LevelsbooltruedisplaySupport
Show all 13 settings
SettingTypeDefaultVariable
Display Resistance LevelsbooltruedisplayResistance
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

PivotHighLow

by Alorse
330 stars

This indicator calculates pivot high and pivot low points on the price chart based on configurable left and right bar counts. Confirmed pivot highs and lows are plotted with negative bar offsets directly on the price chart using line and cross styles. Addition

Indicator v4 Support & resistanceOscillators & momentum Repaints
Updated 2 months ago · None stated GitHub repository of PivotHighLow
114 stars

This indicator calculates key support and resistance levels by analyzing the first and second momentum derivatives of a Double Exponential Moving Average (DEMA). When the second derivative (momentum of momentum) crosses zero, it identifies local turning points

Indicator v4 Support & resistanceOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Support and Resistance Levels

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Lunar Sniper
23 stars

This indicator collection calculates and plots previous daily high and low price levels on the chart to identify potential supply and demand zones. It includes real-time intraday high and low calculations, RSI divergence detection across a customizable period

Indicator v4 Support & resistanceDivergence
Updated 3 years ago · None stated GitHub repository of Daily High and Low Strategy
14 stars

Self-Aware Trend System calculates volatility-adaptive ATR trailing bands using a Trend Quality Index engine that evaluates market efficiency, momentum persistence, and structural pivots. It plots adaptive trend bands and character-flip trend signals directly

Indicator v6 TrendVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of Self-Aware Trend System [WillyAlgoTrader]

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