1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
117 lines of Pine Script v5 from SuperThree.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
SuperThree.pine
// Copyright (c) 2024, Anish Manissery
// Licensed under MIT (https://github.com/anishmanissery/SuperThree/blob/main/LICENSE)
// @description
// The SuperThree is a comprehensive technical indicator designed to identify the following:
// Uptrend (Green Fill), Downtrend (Red Fill), Sideways Trend (Blue Fill), and Counter-Trend Momentum (Blue Arrows)
//@version=5
indicator("SuperThree", overlay=true, timeframe="", timeframe_gaps=false)
// *********************** Inputs ***********************
atrPeriod = input.int(10, "ATR Length", inline="01", minval=1)
factor = input.float(3.0, "Factor", step=0.1, inline="01", minval=0.1)
trendConfirmation = input.string(defval="Quick", title="New trend confirmation", options=["Quicker", "Quick", "Strict"])
counterTrendMomentumLevel = input.int(5, "Counter-trend momentum level", options=[1, 2, 3, 4 , 5, 6, 7, 8, 9, 10])
// ********************* Calculation *********************
// SuperTrend
src = hl2
atrPeriod := (atrPeriod < 1) ? 1 : atrPeriod
factor := (factor < 0.1) ? 0.1 : factor
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
basicUpperBand = upperBand
basicLowerBand = lowerBand
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
// Detect trend direction
trendBand = (trendConfirmation == "Strict") ? superTrend : (trendConfirmation == "Quick") ? ((direction < 0) ? lowerBand : upperBand) : ((direction < 0) ? basicLowerBand : basicUpperBand)
trendBand_1 = (trendConfirmation == "Strict") ? superTrend[1] : (trendConfirmation == "Quick") ? ((direction < 0) ? lowerBand[1] : upperBand[1]) : ((direction < 0) ? basicLowerBand[1] : basicUpperBand[1])
trendBand_2 = (trendConfirmation == "Strict") ? superTrend[2] : (trendConfirmation == "Quick") ? ((direction < 0) ? lowerBand[2] : upperBand[2]) : ((direction < 0) ? basicLowerBand[2] : basicUpperBand[2])
string trend = na
checkCandleColorNPrevClose = true
checkCandleColorNPrevCloseSide = true
if ( (direction < 0) and ( (trendConfirmation == "Quicker") ? (trendBand < trendBand_1) and (trendBand_1 < trendBand_2) : (trendBand == trendBand_1) and (trendBand_1 == trendBand_2)) and (checkCandleColorNPrevCloseSide ? (close < open) and (close < close[1]) : true) )
trend := "sideways"
else if ( (direction > 0) and ( (trendConfirmation == "Quicker") ? (trendBand > trendBand_1) and (trendBand_1 > trendBand_2) : (trendBand == trendBand_1) and (trendBand_1 == trendBand_2)) and (checkCandleColorNPrevCloseSide ? (close > open) and (close > close[1]) : true) )
trend := "sideways"
else if ( (direction < 0) and (trendBand > trendBand_1) and (trendBand_1 > trendBand_2) and (checkCandleColorNPrevClose ? (close > open) and (close > close[1]) : true) )
trend := "up"
else if ( (direction > 0) and (trendBand < trendBand_1) and (trendBand_1 < trendBand_2) and (checkCandleColorNPrevClose ? (close < open) and (close < close[1]) : true) )
trend := "down"
else if ( trend[1] == "sideways" ) // extend
trend := "sideways"
else if ( (trend[1] == "up") and (direction == direction[1]) )
trend := "up"
else if ( (trend[1] == "down") and (direction == direction[1]) )
trend := "down"
// Counter-trend momentum
var count = 0
var gapSum = 0.0
count := (direction != direction[1]) ? 1 : count + 1
gapSum := (direction != direction[1]) ? math.abs(close - superTrend) : gapSum + math.abs(close - superTrend)
gapAverage = gapSum/count
gapAverageMultiple = counterTrendMomentumLevel/10
gapAverageThreshold = gapAverage * gapAverageMultiple
gap = math.abs(close - superTrend)
string counterTrendMomentum = na
if ( (direction < 0) and (close < open) and (basicLowerBand < basicLowerBand[1]) and (basicLowerBand[1] < basicLowerBand[2]) and (close < close[1]) and (gap < gapAverageThreshold ) )
counterTrendMomentum := "bearish"
if ( (direction > 0) and (close > open) and (basicUpperBand > basicUpperBand[1]) and (basicUpperBand[1] > basicUpperBand[2]) and (close > close[1]) and (gap < gapAverageThreshold ) )
counterTrendMomentum := "bullish"
// ********************* Plot *********************
// Supertrend
upTrend = plot(direction < 0 ? superTrend : na, "Up direction", color = color.green, style=plot.style_linebr)
downTrend = plot(direction > 0 ? superTrend : na, "Down direction", color = color.red, style=plot.style_linebr)
// bodyMiddle, bodyMiddle or UpLine, bodyMiddle or DownLine
bodyMiddle = plot((open + close) / 2, display=display.none, editable=false)
bodyMiddleOrUp = plot(direction < 0 ? (open + close) / 2 : superTrend, display=display.none, editable=false)
bodyMiddleOrDown = plot(direction > 0 ? (open + close) / 2 : superTrend, display=display.none, editable=false)
// Fill trend colors
fill(bodyMiddle, upTrend, (trend == "up") and (direction < 0) ? color.new(color.green, 70) : na, title="Uptrend", fillgaps=false)
fill(bodyMiddle, downTrend, (trend == "down") and (direction > 0) ? color.new(color.red, 70) : na, title="Downtrend", fillgaps=false)
fill(bodyMiddleOrUp, bodyMiddleOrDown, (trend == "up") and (direction < 0) and (direction[1] > 0) ? color.new(color.green, 70) : na, title="Uptrend at direction change", fillgaps=false) // during direction change
fill(bodyMiddleOrUp, bodyMiddleOrDown, (trend == "down") and (direction > 0) and (direction[1] < 0) ? color.new(color.red, 70) : na, title="Downtrend at direction change", fillgaps=false)
fill(bodyMiddle, upTrend, (trend == "sideways") and (direction < 0) ? color.new(color.blue, 60) : na, title="Sideways U", fillgaps=false)
fill(bodyMiddle, downTrend, (trend == "sideways") and (direction > 0) ? color.new(color.blue, 60) : na, title="Sideways D", fillgaps=false)
fill(bodyMiddleOrUp, bodyMiddleOrDown, (trend == "sideways") and (direction != direction[1]) ? color.new(color.blue, 60) : na, title="Sideways at direction change", fillgaps=false) // during direction change
// Counter-trend momentum
plotshape(counterTrendMomentum=="bearish", "Bearish Counter-trend momentum", shape.triangledown, location.abovebar, color.blue, size=size.tiny)
plotshape(counterTrendMomentum=="bullish", "Bullish Counter-trend momentum", shape.triangleup, location.belowbar, color.blue, size=size.tiny)
Overview
SuperThree calculates upper and lower bands based on Average True Range (ATR) and a multiplier factor. Visual fills on the price chart display market regimes using green for uptrends, red for downtrends, and blue for sideways consolidation, while blue arrows highlight counter-trend momentum shifts. Inputs let users adjust ATR period, multiplier factor, trend confirmation strictness, and counter-trend sensitivity.
Color-coded chart fills for uptrend, downtrend, and sideways trends
Supertrend band calculation using ATR and multiplier
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
ATR Length
int
10
atrPeriod
Factor
float
3.0
factor
New trend confirmation
string
Quick
trendConfirmation
Counter-trend momentum level
int
5
counterTrendMomentumLevel
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.
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.
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
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
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
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
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