Indicator · Pine Script v6 · Own pane

SuperTrend

by SiegerTerpstra· code credited to sajjetti

This indicator calculates and plots dynamic SuperTrend volatility bands around median price to identify market trend direction.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code152
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update9 months ago14 Jan 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

152 lines of Pine Script v6 from 4 - STR (v6).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

4 - STR (v6).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sajjetti

//@version=6

//-------------------------------------

// Release:                     2020-08-05
// Update:                      2026-01-04
// Author:                      sajjetti
// Email:                       contact@sajjetti.ai
// Website:                     sajjetti.ai
// Profile:                     https://www.tradingview.com/u/stmd/
// Pineversion:                 6
// Filename:                    4 - STR (v6).pine

//-------------------------------------
// PURPOSE
// SuperTrend indicator - a trend-following overlay that uses ATR to create
// dynamic support/resistance levels. Flips between above and below price
// based on trend direction.

//-------------------------------------
// FEATURES
// - Multi-timeframe support via Indicator Timeframe input
// - ATR-based dynamic support/resistance levels
// - Separate multipliers for positive and negative bands
// - Trend state tracking (above/below)
// - Visual fill between price and trend line
// - Line break style for clean trend changes

//-------------------------------------
// NOTES
// - Green line below price = uptrend (support)
// - Red line above price = downtrend (resistance)
// - Band levels adjust based on ATR volatility
// - Higher multiplier = wider bands, fewer signals
// - Lower multiplier = tighter bands, more signals
// - Trend flips when price crosses opposite band
// - Uses hl2 (high+low)/2 as band center

//-------------------------------------
// INDICATOR PARAMETERS

vVersion                        = "V2.1"
vPineVersion                    = "ps6"
vTitle                          = "SuperTrend"
vShort                          = "STR"
vOverlay                        = true
vPrecision                      = 2

indicator( title = vTitle+" ["+vVersion+"|"+vPineVersion+"]", shorttitle = vShort+" ["+vVersion+"|"+vPineVersion+"]", overlay = vOverlay, precision = vPrecision )

//-------------------------------------
// INPUTS

var groupStr                    = "SuperTrend (Standard: close, 1.1, 1.1, 10)"

vTimeframe                      = input.timeframe( defval = "", title = "Indicator Timeframe" )
vStrSource                      = input.source( defval = close, title = "Source", group = groupStr )
vStrPositiveMultiplier          = input.float( defval = 1.1, minval = 0.1, maxval = 1024, title = "Positive Multiplier", step = 0.1, group = groupStr )
vStrNegativeMultiplier          = input.float( defval = 1.1, minval = 0.1, maxval = 1024, title = "Negative Multiplier", step = 0.1, group = groupStr )
vStrLength                      = input.int( defval = 10, minval = 1, maxval = 1024, title = "Length", group = groupStr )

//-------------------------------------
// COLORS

cBullish                        = #26A69A
cBearish                        = #EF5350
cBullishFill                    = color.new( #26A69A, 80 )
cBearishFill                    = color.new( #EF5350, 80 )
cMedian                         = color.new( color.white, 100 )

//-------------------------------------
// FUNCTIONS

// @function    Calculate upper trend level (support in uptrend)
// @param       n (int) Offset for lookback
// @param       s (series float) Source data for trend detection
// @param       l (int) ATR length
// @param       m (float) ATR multiplier
// @returns     (float) Dynamic support level
fTrendLevelAbove( n, s, l, m ) =>
    base = ( hl2[ n ] - ( m * ta.atr( l ) ) )
    var float r = na
    prev = nz( r[ 1 ], base )
    r := ( s[ n + 1 ] > prev ) ? math.max( base, prev ) : base
    r

// @function    Calculate lower trend level (resistance in downtrend)
// @param       n (int) Offset for lookback
// @param       s (series float) Source data for trend detection
// @param       l (int) ATR length
// @param       m (float) ATR multiplier
// @returns     (float) Dynamic resistance level
fTrendLevelBelow( n, s, l, m ) =>
    base = ( hl2[ n ] + ( m * ta.atr( l ) ) )
    var float r = na
    prev = nz( r[ 1 ], base )
    r := ( s[ n + 1 ] < prev ) ? math.min( base, prev ) : base
    r

// @function    Determine if price is above or below trend
// @param       n (int) Offset for lookback
// @param       s (series float) Source data
// @param       a (series float) Above level (support)
// @param       b (series float) Below level (resistance)
// @returns     (bool) True if uptrend, false if downtrend
fAboveOrBelow( n, s, a, b ) =>
    var bool r = false
    r := s[ n ] > b[ n ] ? true : s[ n ] < a[ n ] ? false : r[ 1 ]
    r

// @function    Calculate SuperTrend components for MTF support
// @returns     (tuple) Above level, below level, trend direction, ohlc4
fCalcStr() =>
    levelAbove   = fTrendLevelAbove( 0, vStrSource, vStrLength, vStrPositiveMultiplier )
    levelBelow   = fTrendLevelBelow( 0, vStrSource, vStrLength, vStrNegativeMultiplier )
    aboveOrBelow = fAboveOrBelow( 0, vStrSource, levelAbove, levelBelow )
    [ levelAbove, levelBelow, aboveOrBelow, ohlc4 ]

//-------------------------------------
// CALCULATIONS

[ vStrLevelAbove, vStrLevelBelow, vStrAboveOrBelow, vOhlc4 ] = if vTimeframe == ""
    fCalcStr()
else
    request.security( syminfo.tickerid, vTimeframe, fCalcStr() )

// Combined Supertrend value (for export/validation)
vStrValue = vStrAboveOrBelow ? vStrLevelAbove : vStrLevelBelow

//-------------------------------------
// PLOT

vStrAbove                       = vStrAboveOrBelow ? vStrLevelAbove : na
vPlotStrAbove                   = plot( vStrAbove, style = plot.style_linebr, linewidth = 1, color = cBullish, title = "STR Above - ST" )

vStrBelow                       = not vStrAboveOrBelow ? vStrLevelBelow : na
vPlotStrBelow                   = plot( vStrBelow, style = plot.style_linebr, linewidth = 1, color = cBearish, title = "STR Below - ST" )

// Single combined value for validation export
vPlotStrValue                   = plot( vStrValue, style = plot.style_circles, linewidth = 1, color = color.new(color.white, 100), title = "STR - ST" )

//-------------------------------------
// FILL

vStrLevelMedian                 = plot( vOhlc4, style = plot.style_line, linewidth = 1, color = cMedian, title = "Median", editable = false )
fill( vStrLevelMedian, vPlotStrAbove, color = cBullishFill, title = "Background Above" )
fill( vStrLevelMedian, vPlotStrBelow, color = cBearishFill, title = "Background Below" )

//-------------------------------------

Overview

SuperTrend signals bullish conditions when price stays above the green support line and bearish conditions when price falls below the red resistance line. Users can customize the calculation timeframe, price source, ATR length, and independent positive and negative multipliers. It draws on the price chart as an overlay, although metadata flags a separate pane. Notable limitations include the absence of built-in execution rules or trade alerts.

Details

Published by

SiegerTerpstra on GitHub

Code credit

sajjetti, as written in the script's header

Draws

Separate pane below the 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

tradingviewindicatorindicators

Settings

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

SettingTypeDefaultVariable
Indicator TimeframetimeframevTimeframe
SourcesourceclosevStrSource
Positive Multiplierfloat1.1vStrPositiveMultiplier
Negative Multiplierfloat1.1vStrNegativeMultiplier
Lengthint10vStrLength
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

4 stars

This indicator is a live strategy scanner for cryptocurrency pairs. It runs six strategies on the current chart, tracks their wins and losses, and rates them to show the best one for this pair and timeframe. It uses ATR for adaptive TP/SL, auto-scales based on

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 days ago · None stated GitHub repository of Crypto Pair Selector v2 STEPFUN
2 stars

This indicator tracks market direction by combining Bollinger Bands breakouts with ATR-adjusted pivot point channels. It establishes a primary trend line based on price breaking outer Bollinger Bands filtered by ATR, then validates the movement with a secondar

Indicator v4 TrendVolatility & bands
Updated 5 years ago · None stated GitHub repository of DeFi Follow Line Trend Signal

The Grid Bot Direction Plugin Supertrend Pivot indicator calculates dynamic market trend direction for automated grid trading. It computes a smoothed center level derived from pivot highs and lows, combining it with ATR-based bands to generate a trailing stop

Indicator v5 TrendSupport & resistance Repaints
Updated 8 months ago · MIT GitHub repository of Grid Bot Direction Plugin Supertrend Pivot psyll

The Keltner Center Of Gravity Channel Mutations Indicator calculates adaptive channel metrics based on Donchian range Fibonacci levels (38.2% and 61.8%) and Average True Range (ATR) offsets. The lookback period automatically adjusts according to the active tim

Indicator v5 Volatility & bandsVolume
Updated 8 months ago · None stated GitHub repository of Keltner Center Of Gravity Channel Mutations Indicator

[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