Indicator · Pine Script v5 · On the chart

Historical Vol MA Band Indicator

by g-moe· code credited to goodgains

The Historical Vol MA Band Indicator calculates volatility bands around a simple moving average using 52-week high and low data from the weekly timeframe.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code52
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

52 lines of Pine Script v5 from Tradingview/historical-vol-ma-band-indicator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

historical-vol-ma-band-indicator.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Historical Vol MA Band Indicator",overlay=true)

// @keywords: historical-volatility, vol-ma-band, sma, upper-band, lower-band, middle-band, band-fill, standard-deviation, std-dev-multiplier, 52-week-high, 52-week-low, weekly-timeframe, request-security, stop-loss, bar-coloring, paint-bars, dashboard, ta-highest, ta-lowest, price-bands

//INPUTS
paintBars = input(true,title="Paint Bars")
showDashboard = input(true,title="Show Dashboard")
showStop = input(true,title="Show Stop Loss Value")
maPeriod = input(100,title="SMA Period")
stdMultip = input.float(1.0,step=0.1,title="Std Dev Multiplier")
decimalSize = input.int(2,title="Decimal Size")

//CALCS
middle = ta.sma(close,maPeriod)

hHigh = request.security(syminfo.tickerid, "1W", ta.highest(high,52))
lLow = request.security(syminfo.tickerid, "1W", ta.lowest(low,52))

hv = (hHigh - lLow) / ((hHigh + lLow)/2)
em = (close * hv * (math.sqrt(5)/math.sqrt(252)))*stdMultip
sd = (middle * hv * (math.sqrt(5)/math.sqrt(252)))*stdMultip

upper = middle + sd
lower = middle - sd

stopValue = close > upper ? close - em : close < lower ? close + em : na 

//Bar coloring
setBarColor = close > upper ? color.lime : close < lower ? color.red : color.black

//PLOTS
p1 = plot(upper,color=color.teal,linewidth=2,title="Upper Band")
plot(middle,color=color.gray,linewidth=2, title="Middle Band")
p3 = plot(lower,color=color.maroon,linewidth=2, title="Lower Band")

plot(showStop ? stopValue : na ,color=color.orange, title="Stop Value",linewidth=2, style=plot.style_linebr)

fill(p1,p3,color=color.new(color.yellow,70),title="Band Fill")
barcolor(paintBars ? setBarColor : na)

//TABLE
var table nameDisplay = table.new(position.top_right, 1, 5, bgcolor = color.white, frame_width = 2, frame_color = color.black)
if barstate.islast and showDashboard
    table.cell(nameDisplay, 0, 0, "Dashboard",text_color=color.white,bgcolor=color.green,text_halign=text.align_center)
    table.cell(nameDisplay, 0, 1, "SD Value: "+str.tostring(math.round(sd,decimalSize)),text_color=color.black,bgcolor=color.white,text_halign=text.align_left)
    table.cell(nameDisplay, 0, 2, "SD/Close: "+str.tostring( math.round( (sd/close)*100 ,decimalSize))+"%",text_color=color.black,bgcolor=color.white,text_halign=text.align_left)
    table.cell(nameDisplay, 0, 3, "SD Away Value: "+str.tostring( math.round( (middle - close)/sd ,decimalSize)),text_color=color.black,bgcolor=color.white,text_halign=text.align_left)

Overview

Historical Vol MA Band Indicator plots upper, middle, and lower bands on the main price chart along with optional trailing stop-loss levels and custom bar coloring based on band breakouts. A customizable dashboard table in the top right corner displays standard deviation metrics and price distance from the middle moving average line.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Moving averages, Screeners & dashboards

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
Paint BarsbooltruepaintBars
Show DashboardbooltrueshowDashboard
Show Stop Loss ValuebooltrueshowStop
SMA Periodint100maPeriod
Std Dev Multiplierfloat1.0stdMultip
Decimal Sizeint2decimalSize
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

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

8zz反指標v2

by hansai-art
121 stars

The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab

Indicator v6 Moving averagesOscillators & momentum
Updated 3 months ago · None stated GitHub repository of 8zz反指標v2
43 stars

This indicator evaluates market momentum and risk by calculating trend metrics and volatility stats, displaying them in an on-chart table pane. It measures short-term and long-term trend strength via two MACD configurations built on three customizable EMA leng

Indicator v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of Trend Strength & Volatility

Crypto Context Dashboard

by zabor-crypto
20 stars

This indicator draws a visual present-state context panel on the price chart. It classifies volatility from ATR and Bollinger bandwidth percentiles, measures how far price sits from an EMA in ATR units, and scores trailing candle noise with wick ratio, directi

Indicator v6 Screeners & dashboardsVolatility & bands
Updated 3 days ago · MIT GitHub repository of Crypto Context Dashboard
20 stars

This indicator calculates a base moving average (EMA, SMA, WMA, or HMA) and projects multiple symmetrical envelope bands around it directly on the price chart. Users can adjust the length, source, moving average type, and initial envelope multiplier. Additiona

Indicator v5 Moving averagesVolatility & bands
Updated 1 year ago · None stated GitHub repository of Multiple Moving Average Envelope

Bottom Level Finder

by chris-c-thomas
14 stars

Bottom Level Finder is a support identification indicator designed to locate correction and re-entry zones directly on the price chart. It calculates horizon-adaptive Fibonacci retracements, drawdown percentage levels, moving averages, and integrated VIX volat

Indicator v6 Support & resistanceMoving averages
Updated 6 months ago · MIT GitHub repository of Bottom Level Finder

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