Indicator · Pine Script v5 · On the chart

Multiple Moving Averages

by namuan

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods.

View on GitHub

GitHub stars318on the repository
Pine versionv5runs as is
Lines of code42
Settings7inputs
LicenceMIT
Last update2 months ago18 Aug 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

42 lines of Pine Script v5 from tv-scripts/tvt-multiple-moving-averages.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

tvt-multiple-moving-averages.pine
//@version=5

indicator(title="[TVT] Multiple Moving Averages", shorttitle="TVT-MMA", overlay=true)

// === INPUTS ===
src = input(close)
use_ema = input.bool(defval = true, title="Use EMA over SMA?")
bb_mult = input.float(defval = 2.0, minval=0.001, maxval=50, title="BB Oversold/Overbought deviation")

// Short Moving Averages
ma1   = input(3,title='Short MA-1')
ma2   = input(8,title='Short MA-2')
ma3   = input(21,title='Short MA-3, Also used for BB')
ma4   = input(50,title='Short MA-4')

blend_color = color.white

ma_series1 = use_ema ? ta.sma(src, ma1) : ta.ema(src, ma1)
ma_series2 = use_ema ? ta.sma(src, ma2) : ta.ema(src, ma2)
ma_series3 = use_ema ? ta.sma(src, ma3) : ta.ema(src, ma3)
ma_series4 = use_ema ? ta.sma(src, ma4) : ta.ema(src, ma4)

//plot moving averages
p_ma1 = plot(ma_series1,title='MA-1',color=blend_color, linewidth=1)
p_ma2 = plot(ma_series2,title='MA-2',color=blend_color, linewidth=1)
p_ma3 = plot(ma_series3,title='MA-3',color=blend_color, linewidth=1)
p_ma4 = plot(ma_series4,title='MA-4',color=blend_color, linewidth=1)

up_color = color.lime
down_color = color.maroon

fill(p_ma1, p_ma2, color=ma_series1 > ma_series2 ? color.new(up_color, transp=70) : color.new(down_color, transp=70))
fill(p_ma2, p_ma3, color=ma_series2 > ma_series3 ? color.new(up_color, transp=55) : color.new(down_color, transp=55))
fill(p_ma3, p_ma4, color=ma_series3 > ma_series4 ? color.new(up_color, transp=30) : color.new(down_color, transp=30))

// BB Expansion
bb_stdev = bb_mult * ta.stdev(src, ma3)
bb_upper = ma_series3 + bb_stdev
bb_lower = ma_series3 - bb_stdev

bgcolor((close > bb_upper) ? color.new(color.orange, 90) : na, title="Overbought")
bgcolor((close < bb_lower) ? color.new(color.orange, 90) : na, title="Oversold")

Overview

Multiple Moving Averages fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes Bollinger Bands around the 21-period average to identify volatility extremes, highlighting overbought and oversold zones by tinting the background color when price breaks beyond the bands. Users can toggle between moving average calculation types, adjust periods, and configure the band standard deviation multiplier.

Details

Published by

namuan on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Trend, Volatility & bands

Markets

Stocks

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

trading-strategiesmarket-analysisdtalestock-market-analysistelegram-botearnings-calendaroptions-trading

Settings

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

SettingTypeDefaultVariable
srcsourceclosesrc
Use EMA over SMA?booltrueuse_ema
BB Oversold/Overbought deviationfloat2.0bb_mult
Short MA-1int3ma1
Short MA-2int8ma2
Short MA-3, Also used for BBint21ma3
Short MA-4int50ma4
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

NVDA Trend Ribbon

by longsurf-ai
277 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 yesterday · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
219 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

Adaptive Price Zone

by mihakralj
99 stars

The Adaptive Price Zone indicator calculates volatility bands around a double-smoothed exponential moving average baseline directly on the price chart. It calculates internal smoothing factors using the square root of the user-specified period, double-smoothin

Indicator v6 Volatility & bandsTrend
Updated 4 weeks ago · Apache-2.0 GitHub repository of Adaptive Price Zone

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