Indicator · Pine Script v6 · On the chart

2 Supertrend

by ktg0413· code credited to kimteagyun0413

Calculates and plots two Supertrend lines with different sensitivity settings alongside a 200-period EMA baseline on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code52
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago12 Oct 2025

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 v6 from 2 Supertrend/2 Supertrend.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

2 Supertrend.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kimteagyun0413

//@version=6
indicator("2 Supertrend", overlay = true)

// Supertrend 1 Configuration (Fast/Sensitive) / Supertrend 1 설정 (빠름/민감)
atrPeriod1 = input.int(10, "ATR Length 1", minval = 1)
factor1 = input.float(1.2, "Factor 1", minval = 0.01, step = 0.01)
[supertrend1, direction1] = ta.supertrend(factor1, atrPeriod1)
supertrend1 := barstate.isfirst ? na : supertrend1

// Plot Supertrend 1 lines / Supertrend 1 라인 표시
upTrend1 = plot(direction1 < 0 ? supertrend1 : na, "Up Trend 1", color = color.green, style = plot.style_linebr)
downTrend1 = plot(direction1 < 0 ? na : supertrend1, "Down Trend 1", color = color.red, style = plot.style_linebr)

// Supertrend 2 Configuration (Slow/Conservative) / Supertrend 2 설정 (느림/보수적)
atrPeriod2 = input.int(10, "ATR Length 2", minval = 1)
factor2 = input.float(3.0, "Factor 2", minval = 0.01, step = 0.01)
[supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2)
supertrend2 := barstate.isfirst ? na : supertrend2

// Plot Supertrend 2 lines / Supertrend 2 라인 표시
upTrend2 = plot(direction2 < 0 ? supertrend2 : na, "Up Trend 2", color = color.lime, style = plot.style_linebr)
downTrend2 = plot(direction2 < 0 ? na : supertrend2, "Down Trend 2", color = color.maroon, style = plot.style_linebr)

// Supertrend 3 Configuration (Optional - Currently Commented Out) / Supertrend 3 설정 (선택사항 - 현재 주석 처리됨)
// atrPeriod3 = input.int(10, "ATR Length 3", minval = 1)
// factor3 = input.float(10.0, "Factor 3", minval = 0.01, step = 0.01)
// [supertrend3, direction3] = ta.supertrend(factor3, atrPeriod3)
// supertrend3 := barstate.isfirst ? na : supertrend3
// upTrend3 = plot(direction3 < 0 ? supertrend3 : na, "Up Trend 3", color = color.teal, style = plot.style_linebr)
// downTrend3 = plot(direction3 < 0 ? na : supertrend3, "Down Trend 3", color = color.purple, style = plot.style_linebr)

// Calculate body middle point for background fill reference / 배경 채우기 기준점으로 바디 중간점 계산
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle", display = display.none)

// Calculate and plot 200-period EMA as trend baseline / 추세 기준선으로 200일 EMA 계산 및 표시
ema200 = ta.ema(close,200)
plot(ema200, color = color.white, linewidth = 3)

// Background fills for Supertrend 1 / Supertrend 1 배경 채우기
fill(bodyMiddle, upTrend1, title = "Uptrend 1 background", color = color.new(color.green, 90), fillgaps = false)
fill(bodyMiddle, downTrend1, title = "Downtrend 1 background", color = color.new(color.red, 90), fillgaps = false)

// Background fills for Supertrend 2 / Supertrend 2 배경 채우기
fill(bodyMiddle, upTrend2, title = "Uptrend 2 background", color = color.new(color.lime, 90), fillgaps = false)
fill(bodyMiddle, downTrend2, title = "Downtrend 2 background", color = color.new(color.maroon, 90), fillgaps = false)

// Background fills for Supertrend 3 (Optional - Currently Commented Out) / Supertrend 3 배경 채우기 (선택사항 - 현재 주석 처리됨)
// fill(bodyMiddle, upTrend3, title = "Uptrend 3 background", color = color.new(color.teal, 90), fillgaps = false)
// fill(bodyMiddle, downTrend3, title = "Downtrend 3 background", color = color.new(color.purple, 90), fillgaps = false)

Overview

The fast Supertrend uses a smaller ATR multiplier to capture short-term price momentum, while the slow Supertrend uses a larger multiplier for broader trend direction. Colored background fills between the body midpoint and the Supertrend levels visually highlight trend zones. Settings allow users to adjust ATR lengths and factors for both calculations.

Details

Published by

ktg0413 on GitHub

Code credit

kimteagyun0413, 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.

Settings

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

SettingTypeDefaultVariable
ATR Length 1int10atrPeriod1
Factor 1float1.2factor1
ATR Length 2int10atrPeriod2
Factor 2float3.0factor2
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