Indicator · Pine Script v6 · On the chart

Support and Resistance

by theonetrade· code credited to RicardoSantos

This indicator identifies and plots short-term and long-term support and resistance levels directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code104
Settings6inputs
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

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

rs_support_and_resistance_v0_JWdq2Bni.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=6
string  TITLE = 'Support and Resistance'
string STITLE = 'SR'
indicator(TITLE, STITLE, true)

//#region   inputs and preloading:

string tt_altsrc = 'Use a alternative series source as the input.'

bool use_alt_series = input.bool(false, 'Alternative source:', inline='SRC')
float alt_src = input.source(close, '', inline='SRC', tooltip=tt_altsrc)

float h = use_alt_series ? alt_src : high
float l = use_alt_series ? alt_src : low

int window1 = input.int( 8, 'lookback window 1:')
int window2 = input.int(21, 'lookback window 2:')
float percent_of_range_for_trade_zone = 0.01 * input.float(25.0, 'Percent of the diff to use for trade zone:')

bool use_alerts = input.bool(false, 'Use Alert Signals?')

//#endregion
//#region   ...

// Retrieve the last high/low values:
float short_term_top = ta.valuewhen(h >= ta.highest(h, window1), h, 0)
float short_term_bot = ta.valuewhen(l <= ta.lowest( l, window1), l, 0)
float long_term_top  = ta.valuewhen(h >= ta.highest(h, window2), h, 0)
float long_term_bot  = ta.valuewhen(l <= ta.lowest( l, window2), l, 0)

bool is_new_short_term_resist = not (ta.change(short_term_top) != 0) and short_term_top != long_term_top
bool is_new_short_term_suport = not (ta.change(short_term_bot) != 0) and short_term_bot != long_term_bot
float short_term_resist = is_new_short_term_resist ? short_term_top : na
float short_term_suport = is_new_short_term_suport ? short_term_bot : na

float long_term_resist = ta.change(long_term_top) != 0 ? na : long_term_top
float long_term_suport = ta.change(long_term_bot) != 0 ? na : long_term_bot

bool is_new_long_term_resist = ta.change(fixnan(long_term_resist)) != 0 
bool is_new_long_term_suport = ta.change(fixnan(long_term_suport)) != 0
float long_term_resist_marker = is_new_long_term_resist ? long_term_resist : na
float long_term_suport_marker = is_new_long_term_suport ? long_term_suport : na

//#endregion
//#region   Output:

color col_shrt_term = color.navy
color col_long_term = color.rgb(33, 150, 243, 70)
color col_long_mark = color.blue
color col_bg_resist = color.rgb(255, 152, 0, 80)
color col_bg_suport = color.rgb(128, 128, 0, 80)

short_term_resist_plot       = plot(short_term_resist      , 'STR', col_shrt_term, 1, plot.style_linebr)
short_term_suport_plot       = plot(short_term_suport      , 'STS', col_shrt_term, 1, plot.style_linebr)
long_term_resist_plot        = plot(long_term_resist       , 'LTR', col_long_term, 4, plot.style_linebr)
long_term_suport_plot        = plot(long_term_suport       , 'LTS', col_long_term, 4, plot.style_linebr)
long_term_resist_marker_plot = plot(long_term_resist_marker, '.R' , col_long_mark, 4, plot.style_circles)
long_term_suport_marker_plot = plot(long_term_suport_marker, '.S' , col_long_mark, 4, plot.style_circles)

fill(short_term_resist_plot, long_term_resist_plot, col_bg_resist, "Resistance")
fill(short_term_suport_plot, long_term_suport_plot, col_bg_suport, "Support")

//  Calculate entry zone:
float short_term_resist_trade_limit = na
float short_term_suport_trade_limit = na

float diff = fixnan(short_term_resist) - fixnan(short_term_suport)

if not na(short_term_resist)
    if not na(short_term_resist_trade_limit[1])
        short_term_resist_trade_limit := short_term_resist_trade_limit[1]
    else
        short_term_resist_trade_limit := short_term_resist - diff * percent_of_range_for_trade_zone

if not na(short_term_suport)
    if not na(short_term_suport_trade_limit[1])
        short_term_suport_trade_limit := short_term_suport_trade_limit[1]
    else
        short_term_suport_trade_limit := short_term_suport + diff * percent_of_range_for_trade_zone

short_term_resist_trade_limit_plot = plot(short_term_resist_trade_limit, 'L', color.red, 1, plot.style_linebr)
short_term_suport_trade_limit_plot = plot(short_term_suport_trade_limit, 'L', color.lime, 1, plot.style_linebr)

//#endregion
//#region   Alerts:

if barstate.isconfirmed
    if is_new_short_term_resist and na(short_term_resist[1])
        //log.info('SR')
        alert('New short term resistance formed!', alert.freq_once_per_bar_close)
    if is_new_short_term_suport and na(short_term_suport[1])
        //log.info('SS')
        alert('New short term support formed!', alert.freq_once_per_bar_close)
    if is_new_long_term_resist
        //log.info('LR')
        alert("New long term resistance formed!", alert.freq_once_per_bar_close)
    if is_new_long_term_suport
        //log.info('LS')
        alert("New long term support formed!", alert.freq_once_per_bar_close)

//#endregion

Overview

Support and Resistance tracks the highest highs and lowest lows across two configurable lookback windows, shading the zones between short-term and long-term levels and marking new long-term level shifts with circles. It also calculates entry trade zones based on a percentage of the range between short-term levels. Users can customize both lookback lengths, switch from high and low prices to an alternative source series, adjust the trade zone percentage, and enable optional alert signals. Because levels rely on rolling highs and lows, active levels shift when new extremes form.

Details

Published by

theonetrade on GitHub

Code credit

RicardoSantos, as written in the script's header

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
Alternative source:boolfalseuse_alt_series
alt_srcsourceclosealt_src
lookback window 1:int8window1
lookback window 2:int21window2
Percent of the diff to use for trade zone:float25.0Percent of the diff to use for trade zone:
Use Alert Signals?boolfalseuse_alerts
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 5 weeks 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
368 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 3 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 8 days ago · MIT GitHub repository of Volume Profile and Indicator by DGT

Swing labels

by tradoor-terminal
320 stars

Calculates swing highs and swing lows on the price chart using pivot high and pivot low detection over a specified length. It places labels above pivot highs and below pivot lows to highlight key structural swing points. The indicator measures and displays the

Indicator v6 Support & resistanceTrend
Updated 3 days ago · AGPL-3.0 GitHub repository of Swing labels

BZ-tracker

by Allen1212
302 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 3 years ago · None stated GitHub repository of BZ-tracker

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