Indicator · Pine Script v5 · On the chart

Multiple Moving Average Envelope

by palitojendthen

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.

View on GitHub

GitHub stars20on the repository
Pine versionv5runs as is
Lines of code67
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago12 Jul 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

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

multiple_ma_envelope.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © palitoj_endthen

//@version=5
indicator(title = 'Multiple Moving Average Envelope', shorttitle = 'ma_envelope', overlay = true)


// input
src = input.source(defval = ohlc4, title = 'Source', group = 'Options', tooltip = 'Determines the source of input data')
ma_type = input.string(defval = 'WMA', title = 'MA Type', group = 'Options', options = ['EMA', 'SMA', 'WMA', 'HMA'], tooltip = 'Choose between moving average types')
mult = input.float(defval = 0.1, title = 'Initial Multiplier', group = 'Options', step = 0.1, maxval = 1, tooltip = 'Determines value of multiplier for upper and lower band')
value_at_risk = input.float(defval = 5.0, title = 'Confidence', group = 'Options', tooltip = 'Input confidence level (ps: no need convert to decimal)')
show_ma = input.bool(defval = true, title = 'MA', group = 'Moving Average', tooltip = 'Determines whether to display moving average line', inline = 'f')
length = input.int(defval = 10, title = 'Length', group = 'Moving Average', tooltip = 'Determines lookback period of moving average', inline = 'f')


// switch between moving average type
float ma = switch ma_type
    "EMA" => ta.ema(src, length)
    "SMA" => ta.sma(src, length)
    "WMA" => ta.wma(src, length)
    "HMA" => ta.hma(src, length)

// multiple moving envelope
env(_mult)=>
    upper_band = ma*(1+_mult)
    lower_band = ma*(1-_mult)
    [upper_band, lower_band]


// visualize
// moving average envelope
[u1, l1] = env(mult) // -> base
[u2, l2] = env(mult+.2) // -> mult = .3
[u3, l3] = env(mult+.4) // -> mult = .5
[u4, l4] = env(mult+.6) // -> mult = .7
fill(plot(u1, color = na), plot(l1, color = na), color.new(#1E90FF, 97))
fill(plot(u2, color = na), plot(l2, color = na), color.new(#1E90FF, 97))
fill(plot(u3, color = na), plot(l3, color = na), color.new(#1E90FF, 97))
fill(plot(u4, color = na), plot(l4, color = na), color.new(#1E90FF, 97))

// moving average
plot(show_ma ? ma : na, color = color.maroon, linewidth = 2)


// information table
y = input.string(defval = 'top', title = 'Position', inline = '8', options = ['top', 'middle', 'bottom'], group = 'Information Value')
x = input.string(defval = 'right', title = '', inline = '8', options = ['left', 'center', 'right'], group = 'Information Value')
var table information_table = table.new(y + "_" + x, 2, 5)
table.cell(information_table, 0, 1, 'Information' , text_halign = text.align_left, text_size = size.normal, text_color = color.new(color.maroon, 50))
table.cell(information_table, 1, 1, 'Value' , text_size = size.normal, text_color = color.new(color.maroon, 50))

// deviation
returns = (close/close[1])-1
stdev = math.round(ta.stdev(returns, length), 3)*100
table.cell(information_table, 0, 2, 'Std. Deviation' , text_halign = text.align_left, text_size = size.normal, text_color = color.new(color.white, 50))
table.cell(information_table, 1, 2, str.tostring(stdev)+'%' , text_size = size.normal, text_color = color.new(color.white, 50))

// compounding growth
compounded_growth = math.round(((math.pow((close/close[length]), (1/length))-1)*100),3)
table.cell(information_table, 0, 3, 'Growth Rate' , text_halign = text.align_left, text_size = size.normal, text_color = color.new(color.white, 50))
table.cell(information_table, 1, 3, str.tostring(compounded_growth) + '%', text_halign = text.align_left, text_size = size.normal, text_color = color.new(color.white, 50))

// value-at-risk
VaR = math.round(ta.percentile_nearest_rank(returns, length, value_at_risk),3)*100
table.cell(information_table, 0, 4, 'Value-at-Risk' , text_halign = text.align_left, text_size = size.normal, text_color = color.new(color.white, 50))
table.cell(information_table, 1, 4, str.tostring(VaR)+'%' ,text_size = size.normal, text_color = color.new(color.white, 50))

Overview

Users can adjust the length, source, moving average type, and initial envelope multiplier. Additionally, the script computes key statistical metrics over the chosen lookback period, including standard deviation of returns and growth rate, displaying them in a configurable information table.

Details

Published by

palitojendthen on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Volatility & bands, Support & resistance, 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.

Topics

indicatortechnical-analysispinescripttrading-algorithms

Settings

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

SettingTypeDefaultVariable
Sourcesourceohlc4src
MA TypestringWMAma_type
Initial Multiplierfloat0.1mult
Confidencefloat5.0value_at_risk
MAbooltrueshow_ma
Lengthint10length
Positionstringtopy
xstringrightx
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

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
7 stars

This indicator plots standard Bollinger Bands alongside scaled Average True Range (ATR) bands directly on the price chart. It is designed to assist traders in identifying price consolidation zones, potential breakout levels, dynamic stops, and take-profit targ

Indicator v5 Moving averagesVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Bollinger and ATR Bands

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

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP
218 stars

This indicator maps market structure and supply and demand zones on the price chart. It marks validated and optional unvalidated swing highs and lows using a pivot length and extra confirmation bars. Consolidation and impulse moves are measured against ATR to

Indicator v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Market Structure + Supply/Demand

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