Indicator · Pine Script v4 · On the chart

Triple Supertrend

by shyrwinsia

This indicator calculates three distinct Supertrend lines on the main price chart, designated as short, medium, and long term.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code52
Settings7inputs
LicenceMIT
Last update5 years ago20 Apr 2021

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

52 lines of Pine Script v4 from Triple Supertrend with Baseline.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Triple Supertrend with Baseline.pine
//@version=4
study("Triple Supertrend", overlay = true, format=format.price, precision=2, resolution="")

src = input(hl2, title="Source")
sPeriod = input(title="Short ATR Period", type=input.integer, defval=10)
sMultiplier = input(title="Short ATR Multiplier", type=input.float, step=0.1, defval=1.0)
mPeriod = input(title="Medium ATR Period", type=input.integer, defval=11)
mMultiplier = input(title="Medium ATR Multiplier", type=input.float, step=0.1, defval=2.0)
lPeriod = input(title="Long ATR Period", type=input.integer, defval=12)
lMultiplier = input(title="Long ATR Multiplier", type=input.float, step=0.1, defval=3.0)


satr = atr(sPeriod)
sup = src - (sMultiplier * satr)
sup1 = nz(sup[1], sup)
sup := close[1] > sup1 ? max(sup, sup1) : sup
sdn = src + (sMultiplier * satr)
sdn1 = nz(sdn[1], sdn)
sdn := close[1] < sdn1 ? min(sdn, sdn1) : sdn
strend = 1
strend := nz(strend[1], strend)
strend := strend == -1 and close > sdn1 ? 1 : strend == 1 and close < sup1 ? -1 : strend
supPlot = plot(strend == 1 ? sup : na, title="Short Up Trend", style=plot.style_linebr, linewidth=1, color=color.green)
sdnPlot = plot(strend == 1 ? na : sdn, title="Short Down Trend", style=plot.style_linebr, linewidth=1, color=color.red)

matr = atr(mPeriod)
mup = src - (mMultiplier * matr)
mup1 = nz(mup[1], mup)
mup := close[1] > mup1 ? max(mup, mup1) : mup
mdn = src + (mMultiplier * matr)
mdn1 = nz(mdn[1], mdn)
mdn := close[1] < mdn1 ? min(mdn, mdn1) : mdn
mtrend = 1
mtrend := nz(mtrend[1], mtrend)
mtrend := mtrend == -1 and close > mdn1 ? 1 : mtrend == 1 and close < mup1 ? -1 : mtrend
mupPlot = plot(mtrend == 1 ? mup : na, title="Medium Up Trend", style=plot.style_linebr, linewidth=3, color=color.green)
mdnPlot = plot(mtrend == 1 ? na : mdn, title="Medium Down Trend", style=plot.style_linebr, linewidth=3, color=color.red)

latr = atr(lPeriod)
lup = src - (lMultiplier * latr)
lup1 = nz(lup[1], lup)
lup := close[1] > lup1 ? max(lup, lup1) : lup
ldn = src + (lMultiplier * latr)
ldn1 = nz(ldn[1], ldn)
ldn := close[1] < ldn1 ? min(ldn, ldn1) : ldn
ltrend = 1
ltrend := nz(ltrend[1], ltrend)
ltrend := ltrend == -1 and close > ldn1 ? 1 : ltrend == 1 and close < lup1 ? -1 : ltrend
lupPlot = plot(ltrend == 1 ? lup : na, title="Long Up Trend", style=plot.style_linebr, linewidth=5, color=color.green)
ldnPlot = plot(ltrend == 1 ? na : ldn, title="Long Down Trend", style=plot.style_linebr, linewidth=5, color=color.red)

plot(ema(close, 200), color=color.white, linewidth=5)

Overview

Each Supertrend line utilizes its own Average True Range period and multiplier settings to identify trend directions across different time horizons. Green lines represent uptrends, while red lines represent downtrends. Additionally, the script plots a white 200-period exponential moving average to serve as a baseline trend filter. Users can customize the price source, ATR lengths, and multipliers for all three trends.

Details

Published by

shyrwinsia on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages

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
Sourcesourcehl2src
Short ATR Periodint10sPeriod
Short ATR Multiplierfloat1.0sMultiplier
Medium ATR Periodint11mPeriod
Medium ATR Multiplierfloat2.0mMultiplier
Long ATR Periodint12lPeriod
Long ATR Multiplierfloat3.0lMultiplier
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
277 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 yesterday · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
219 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 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