Indicator · Pine Script v5 · On the chart

Trend Strength & Volatility

by Zettt

This indicator evaluates market momentum and risk by calculating trend metrics and volatility stats, displaying them in an on-chart table pane.

View on GitHub

GitHub stars43on the repository
Pine versionv5runs as is
Lines of code83
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago23 Sep 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

83 lines of Pine Script v5 from Trend Strength & Volatility.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Trend Strength & Volatility.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Zettt

//@version=5
indicator("Trend Strength & Volatility", overlay=true)
// import TradingView/ta/7

// EMA lengths
ema1Length = input.int(defval = 21, title = "EMA 1", tooltip = "This EMA is also used for ATR/Keltner.") 
ema2Length = input.int(defval = 55, title = "EMA 2")
ema3Length = input.int(defval = 100, title = "EMA 3")

// Trend Strength
// ##############
// We use MACD as trend strength indicator because it calculates the difference of 2 EMAs
[macdShort, signalShort, histShort] = ta.macd(close[1], ema1Length, ema2Length, 9) // MACD for shorter EMAs
[macdLong, signalLong, histLong] = ta.macd(close[1], ema2Length, ema3Length, 9) // MACD for longer EMAs

// Volatility
// ##########
lookbackLength = input.int(title='Lookback Length', defval=365, minval=1)
stdevMultiplier = input.float(title='Standard Deviation Multiplier', defval=1, minval=0, step=0.1)

averageReturn = ta.roc(close, lookbackLength)
risk = ta.stdev(averageReturn, lookbackLength)

// Sharpe
// ######
// Sharpe can function as indication for trend strength
// lookbackLength = input.int(title='Lookback Length', defval=20, minval=1)
// stdevMultiplier = input.float(title='Standard Deviation Multipliert', defval=2, minval=1, step=0.1)

// averageReturn = ta.roc(close, lookbackLength)

stdev = ta.stdev(averageReturn, lookbackLength)
sharpe = (averageReturn / stdev)

// ATR/Keltner 
// ###########
// Measures distance to price, and displays in percent
[kcMiddleShort, kcUpperShort, kcLowerShort] = ta.kc(close, ema1Length, 2)
atrShort = 0.0
if macdShort >= 0
    atrShort := 100 - ((kcLowerShort/close[1]) * 100)
else if macdShort < 0
    atrShort := 100 - ((kcUpperShort/close[1]) * 100)

// A second ATR value is necessary if trend is different for
// long and short EMAs
[kcMiddleLong, kcUpperLong, kcLowerLong] = ta.kc(close, ema1Length, 2)
atrLong = 0.0
if macdLong >= 0
    atrLong := 100 - ((kcLowerLong/close[1]) * 100)
else if macdLong < 0
    atrLong := 100 - ((kcUpperLong/close[1]) * 100)



// Create a table with two columns and three rows
t = table.new(position.bottom_left, 6, 2, bgcolor=color.new(color.white, 10))

// Update table cells
// Table Header
table.cell(t, 0, 0, text="Short") // Trend strength short
table.cell(t, 1, 0, text="Long") // Trend strength short
table.cell(t, 2, 0, text="Sharpe") // Trend strength short
// table.cell(t, 3, 0, text="HV") // Historical volatility = realized vol = annualized vol
table.cell(t, 3, 0, text="ATR S") // ATR distance in percent
table.cell(t, 4, 0, text="ATR L") // ATR distance in percent

// Column 0
table.cell(t, 0, 1, text=str.tostring(macdShort, "#.##"))

// Column 1
table.cell(t, 1, 1, text=str.tostring(macdLong, "#.##"))
// Column 2
table.cell(t, 2, 1, text=str.tostring(sharpe, "#.##"))
// Column 3
// table.cell(t, 3, 1, text=str.tostring(risk, "#.##"))
// Column 4
table.cell(t, 3, 1, text=str.tostring(atrShort, "#.##"))
// Column 5
table.cell(t, 4, 1, text=str.tostring(atrLong, "#.##"))

Overview

Trend Strength & Volatility measures short-term and long-term trend strength via two MACD configurations built on three customizable EMA lengths. It also calculates a Sharpe ratio based on rate of change standard deviation, alongside ATR percentage distances derived from Keltner Channels. The results are formatted in a bottom-left dashboard table overlay.

Details

Published by

Zettt on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands, Screeners & dashboards, 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
EMA 1int21ema1Length
EMA 2int55ema2Length
EMA 3int100ema3Length
Lookback Lengthint365lookbackLength
Standard Deviation Multiplierfloat1stdevMultiplier
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

7 stars

This indicator plots a zero-lag EMA center line with ATR bands on the price chart. It marks bullish or bearish mode after closes stay beyond a band for a set number of bars and the center line slopes that way. Confirmed buy and sell labels appear only after th

Indicator v6 TrendMoving averages Repaints
Updated 3 months ago · None stated GitHub repository of GK Trend Ribbon SWING + PREPARE HUD

Calculates market volatility, velocity, dynamic VIX thresholds, and multi-timeframe directional bias to assess risk regimes for Nifty index options trading. It computes a danger score based on ATR, VIX rate of change, Bollinger Band width, and price velocity t

Indicator v5 Volatility & bandsScreeners & dashboards
Updated 13 days ago · None stated GitHub repository of NIFTY SpreadGuard V2024 - Mega-Sidebar Sniper

Quick Stats

by etnt
2 stars

Quick Stats displays key trading metrics directly on the price chart overlay. It calculates Mark Minervini's Trend Template rules by scoring moving average alignments (50, 150, and 200 SMAs), 200 SMA slope, and 52-week high/low proximities. Additionally, it co

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Quick Stats

Calculates a Zero Lag Exponential Moving Average (ZLEMA) combined with Average True Range volatility bands to determine market trends. It plots the ZLEMA basis line, volatility bands, trend reversal labels, and entry signals directly on the price chart. Additi

Indicator v5 TrendMoving averages Repaints
Updated 5 weeks ago · None stated GitHub repository of Zero Lag Trend Signals (MTF) [AlgoAlpha]

This indicator draws a SPY scalping panel in a separate pane. It calculates a Supertrend side from ATR smoothed by a selectable average, defaulting to HMA, and uses three moving averages of selectable type, defaulting to EMA lengths 13, 50, and 75. Colors mark

Indicator v5 TrendMoving averages
Updated 5 months ago · None stated GitHub repository of J8 30 123 Spy Scalping Lower Pro 2 Jerry

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