Indicator · Pine Script v5 · On the chart

SuperTrend

by trsdn

The SuperTrend indicator computes upper and lower bands from ATR values using a multiplier on a selected source such as HL2.

View on GitHub

GitHub stars6on the repository
Pine versionv5runs as is
Lines of code33
Settings3inputs
LicenceMIT
Last update7 days ago23 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

33 lines of Pine Script v5 from strategies/ai-supertrend.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

ai-supertrend.pine
// Source: TradingView Built-in Indicator (SuperTrend)
// Attribution: Standard SuperTrend implementation matching TradingView's built-in indicator
// Used as input for AI-powered strategy conversion

//@version=5
indicator("SuperTrend", overlay=true)

atrPeriod = input.int(10, "ATR Period")
factor = input.float(3.0, "Multiplier")
src = input(hl2, "Source")

atr2 = ta.atr(atrPeriod)

upperBand = src + factor * atr2
lowerBand = src - factor * atr2

prevUpperBand = nz(upperBand[1], upperBand)
prevLowerBand = nz(lowerBand[1], lowerBand)

lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand

var int direction = 1
direction := direction == -1 and close > prevLowerBand ? 1 : direction == 1 and close < prevUpperBand ? -1 : direction

superTrend = direction == 1 ? lowerBand : upperBand
bodyMiddle = plot((open + close) / 2, display=display.none)
trend = plot(superTrend, color=direction == 1 ? color.green : color.red, linewidth=2, title="SuperTrend")
fill(bodyMiddle, trend, color=direction == 1 ? color.new(color.green, 90) : color.new(color.red, 90))

Additional instructions:
- CRITICAL: The AI will likely INVERT the logic (buying on Red, selling on Green). Verify the trades on the chart. The correct logic is: Buy when Trend is Green (direction == 1), Sell when Trend is Red (direction == -1).
- Switch the logic if inverted: Buy when Trend is Green, Sell when Trend is Red.

Overview

SuperTrend maintains adaptive trend lines that shift color from green to red based on price position relative to the bands. The green line functions as dynamic support and the red as resistance, with area fill between price and the trend line. Users adjust ATR period and multiplier for sensitivity. Color changes signal trend direction and potential reversals on the price chart.

Details

Published by

trsdn 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

ai-scrumalgorithmic-tradingbacktestingbitcoinbollinger-bandscryptopine-scriptpythonquantitative-financestrategy

Settings

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

SettingTypeDefaultVariable
ATR Periodint10atrPeriod
Multiplierfloat3.0factor
Sourcesourcehl2src
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

318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

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

Bollinger Bands Force

by harryguiacorn
220 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

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