Indicator · Pine Script v6 · On the chart

Supertrend

by AkashSasikumar47

This script plots up to three ATR-based Supertrend lines directly on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv6current
Lines of code55
Settings9inputs
LicenceMIT
Last update2 weeks ago10 Oct 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

55 lines of Pine Script v6 from indicators/supertrend.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

supertrend.pine
//@version=6
indicator("Supertrend", "STI", overlay = true)

showLine1 = input.bool(true, "Line 1")
atrLength1 = input.int(10, "ATR Period", minval = 1)
multiplier1 = input.float(1.0, "ATR Multiplier", minval = 0.1)
showLine2 = input.bool(true, "Line 2")
atrLength2 = input.int(11, "ATR Period", minval = 1)
multiplier2 = input.float(2.0, "ATR Multiplier", minval = 0.1)
showLine3 = input.bool(true, "Line 3")
atrLength3 = input.int(12, "ATR Period", minval = 1)
multiplier3 = input.float(3.0, "ATR Multiplier", minval = 0.1)

supertrend(atrLength, multiplier) =>
    atr = ta.atr(atrLength)
    up = hl2 - atr * multiplier
    upPrev = up[1]
    up := close[1] > upPrev ? math.max(up, upPrev) : up
    down = hl2 + atr * multiplier
    downPrev = down[1]
    down := close[1] < downPrev ? math.min(down, downPrev) : down
    crossedUp = ta.crossover(close, downPrev)
    crossedDown = ta.crossunder(close, upPrev)
    var int trend = 0
    if crossedUp
        trend := 1
    if crossedDown
        trend := -1
    [up, down, trend]

middle = plot(hl2, "Middle", display = display.none)

[up1, down1, trend1] = supertrend(atrLength1, multiplier1)
upLine1 = plot(showLine1 and trend1 == 1 ? up1 : na, "Line 1 Up", color.green, 2, plot.style_linebr)
downLine1 = plot(showLine1 and trend1 == -1 ? down1 : na, "Line 1 Down", color.red, 2, plot.style_linebr)
fill(upLine1, middle, color.new(color.green, 90))
fill(downLine1, middle, color.new(color.red, 90))
plotshape(showLine1 and trend1 == 1 and trend1[1] == -1 ? up1 : na, "Line 1 Buy", shape.circle, location.absolute, color.green, size = size.tiny)
plotshape(showLine1 and trend1 == -1 and trend1[1] == 1 ? down1 : na, "Line 1 Sell", shape.circle, location.absolute, color.red, size = size.tiny)

[up2, down2, trend2] = supertrend(atrLength2, multiplier2)
upLine2 = plot(showLine2 and trend2 == 1 ? up2 : na, "Line 2 Up", color.green, 2, plot.style_linebr)
downLine2 = plot(showLine2 and trend2 == -1 ? down2 : na, "Line 2 Down", color.red, 2, plot.style_linebr)
fill(upLine2, middle, color.new(color.green, 90))
fill(downLine2, middle, color.new(color.red, 90))
plotshape(showLine2 and trend2 == 1 and trend2[1] == -1 ? up2 : na, "Line 2 Buy", shape.circle, location.absolute, color.green, size = size.tiny)
plotshape(showLine2 and trend2 == -1 and trend2[1] == 1 ? down2 : na, "Line 2 Sell", shape.circle, location.absolute, color.red, size = size.tiny)

[up3, down3, trend3] = supertrend(atrLength3, multiplier3)
upLine3 = plot(showLine3 and trend3 == 1 ? up3 : na, "Line 3 Up", color.green, 2, plot.style_linebr)
downLine3 = plot(showLine3 and trend3 == -1 ? down3 : na, "Line 3 Down", color.red, 2, plot.style_linebr)
fill(upLine3, middle, color.new(color.green, 90))
fill(downLine3, middle, color.new(color.red, 90))
plotshape(showLine3 and trend3 == 1 and trend3[1] == -1 ? up3 : na, "Line 3 Buy", shape.circle, location.absolute, color.green, size = size.tiny)
plotshape(showLine3 and trend3 == -1 and trend3[1] == 1 ? down3 : na, "Line 3 Sell", shape.circle, location.absolute, color.red, size = size.tiny)

Overview

Each line uses customizable ATR periods and multipliers to establish trailing support or resistance levels based on median price calculations. Green lines below price indicate an uptrend, while red lines above indicate a downtrend. Color fills extend from each active line to the bar median, and circle shapes mark where trends flip. Users can toggle visibility for all three lines and adjust their parameters individually to analyze trends across tight, medium, and wide volatility thresholds.

Details

Published by

AkashSasikumar47 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

pine-scriptpinescript-v6technical-analysistrading-indicatorstradingview

Settings

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

SettingTypeDefaultVariable
Line 1booltrueshowLine1
ATR Periodint10atrLength1
ATR Multiplierfloat1.0multiplier1
Line 2booltrueshowLine2
ATR Periodint11atrLength2
ATR Multiplierfloat2.0multiplier2
Line 3booltrueshowLine3
ATR Periodint12atrLength3
ATR Multiplierfloat3.0multiplier3
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

Chandelier Exit

by everget
947 stars

This indicator plots an ATR-based Chandelier Exit trailing stop on the price chart. It tracks a long stop under recent highs and a short stop above recent lows, then switches direction when price crosses the opposite stop. Buy and sell labels mark those flips.

Indicator v6 Volatility & bandsTrend Repaints
Updated 12 days ago · GPL-3.0 GitHub repository of Chandelier Exit

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
330 stars

Range Filter [Alorse] is a technical indicator overlay for TradingView designed to filter market volatility and identify price trends. It calculates a smoothed range based on historical volatility using a configurable sampling period and multiplier applied to

Indicator v5 TrendVolatility & bands
Updated 2 months ago · None stated GitHub repository of Range Filter [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of NVDA Trend Ribbon

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

More Trend 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