Indicator · Pine Script v5 · On the chart

MA & BB Levels [ST]

by eddiebelaval· code credited to BigGuavaTrading

This indicator draws horizontal daily and weekly levels on the price chart from two exponential moving averages and a Bollinger-style envelope.

View on GitHub

Repaints

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code119
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update3 months ago24 Jul 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

119 lines of Pine Script v5 from pinescript/moving_averages/ma-bb-levels-st.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

ma-bb-levels-st.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigGuavaTrading
//@version=5

// 1. STANDARDIZATION: Name [ST]
indicator("MA & BB Levels [ST]", overlay=true, max_lines_count=16, max_labels_count=16)

// 2. VERSION CONTROL
string ver_num  = "v2.0"
string ver_date = "2026-02-09"

// ==========================================
// 1. INPUTS
// ==========================================
grp_week  = "Weekly Levels"
grp_day   = "Daily Levels"
grp_conf  = "Indicator Settings"
grp_style = "Style Settings"

// Weekly Switches
plotW_EMA9    = input.bool(true, "MA9 (Weekly)", group=grp_week)
plotW_EMA20   = input.bool(true, "MA20 (Weekly)", group=grp_week)
plotW_BBUpper = input.bool(true, "BB Upper (Weekly)", group=grp_week)
plotW_BBLower = input.bool(true, "BB Lower (Weekly)", group=grp_week)

// Daily Switches
plotD_EMA9    = input.bool(true, "MA9 (Daily)", group=grp_day)
plotD_EMA20   = input.bool(true, "MA20 (Daily)", group=grp_day)
plotD_BBUpper = input.bool(true, "BB Upper (Daily)", group=grp_day)
plotD_BBLower = input.bool(true, "BB Lower (Daily)", group=grp_day)

// Indicator Settings
ema9Len   = input.int(9,  "EMA 9 Period",  inline="ema", group=grp_conf)
ema20Len  = input.int(20, "EMA 20 Period", inline="ema", group=grp_conf)
bbLen     = input.int(20, "BB Period",     inline="bb",  group=grp_conf)
bbStdDev  = input.float(2.0, "BB StdDev",  inline="bb",  group=grp_conf)

// Style Settings
textSizeInput = input.string("Normal", "Text Size", options = ["Small", "Normal", "Large", "Huge"], group=grp_style)

finalSize = switch textSizeInput
    "Small"  => size.small
    "Normal" => size.normal
    "Large"  => size.large
    "Huge"   => size.huge
    => size.normal

// ==========================================
// 2. CALCULATIONS
// ==========================================
// Core Indicators
ema9      = ta.ema(close, ema9Len)
ema20     = ta.ema(close, ema20Len)
ema_basis = ta.ema(close, bbLen) 
dev       = bbStdDev * ta.stdev(close, bbLen)
bbUpper   = ema_basis + dev
bbLower   = ema_basis - dev

// ==========================================
// 3. MTF DATA FETCHING
// ==========================================
// Weekly Data
w_ema9    = request.security(syminfo.tickerid, "W", ema9,    lookahead=barmerge.lookahead_on)
w_ema20   = request.security(syminfo.tickerid, "W", ema20,   lookahead=barmerge.lookahead_on)
w_bbUpper = request.security(syminfo.tickerid, "W", bbUpper, lookahead=barmerge.lookahead_on)
w_bbLower = request.security(syminfo.tickerid, "W", bbLower, lookahead=barmerge.lookahead_on)

// Daily Data
d_ema9    = request.security(syminfo.tickerid, "D", ema9,    lookahead=barmerge.lookahead_on)
d_ema20   = request.security(syminfo.tickerid, "D", ema20,   lookahead=barmerge.lookahead_on)
d_bbUpper = request.security(syminfo.tickerid, "D", bbUpper, lookahead=barmerge.lookahead_on)
d_bbLower = request.security(syminfo.tickerid, "D", bbLower, lookahead=barmerge.lookahead_on)

// Style Definitions
lineColor = color.new(#FFBF00, 30) // Gold with transparency
lineStyle = line.style_solid
textColor = color.blue

// ==========================================
// 4. PLOTTING (Lines & Labels)
// ==========================================
if barstate.islast
    int labelOffset = 1 
    // Label sits on top of the line, aligned to the right
    string lblStyle = label.style_label_lower_left 
    
    // --- WEEKLY LEVELS ---
    if plotW_EMA9
        line.new(bar_index, w_ema9, bar_index + 10, w_ema9, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, w_ema9, "W EMA9: " + str.tostring(w_ema9, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)
    
    if plotW_EMA20
        line.new(bar_index, w_ema20, bar_index + 10, w_ema20, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, w_ema20, "W EMA20: " + str.tostring(w_ema20, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)
    
    if plotW_BBUpper
        line.new(bar_index, w_bbUpper, bar_index + 10, w_bbUpper, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, w_bbUpper, "W BB UP: " + str.tostring(w_bbUpper, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)
    
    if plotW_BBLower
        line.new(bar_index, w_bbLower, bar_index + 10, w_bbLower, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, w_bbLower, "W BB LW: " + str.tostring(w_bbLower, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)

    // --- DAILY LEVELS ---
    if plotD_EMA9
        line.new(bar_index, d_ema9, bar_index + 10, d_ema9, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, d_ema9, "D EMA9: " + str.tostring(d_ema9, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)
    
    if plotD_EMA20
        line.new(bar_index, d_ema20, bar_index + 10, d_ema20, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, d_ema20, "D EMA20: " + str.tostring(d_ema20, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)
    
    if plotD_BBUpper
        line.new(bar_index, d_bbUpper, bar_index + 10, d_bbUpper, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, d_bbUpper, "D BB UP: " + str.tostring(d_bbUpper, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)
    
    if plotD_BBLower
        line.new(bar_index, d_bbLower, bar_index + 10, d_bbLower, extend=extend.right, color=lineColor, style=lineStyle, width=2)
        label.new(bar_index + labelOffset, d_bbLower, "D BB LW: " + str.tostring(d_bbLower, "#.##"), color=color(na), textcolor=textColor, size=finalSize, style=lblStyle)

Overview

MA & BB Levels [ST] calculates EMA 9, EMA 20, and an EMA-based band with a configurable standard-deviation width, then requests those values from the daily and weekly timeframes. Separate switches show or hide each level. Users can change both EMA lengths, the band period and deviation, and the label text size. Lines and labels are created on the last bar. Higher-timeframe requests use lookahead, so plotted levels can change before those bars close.

Details

Published by

eddiebelaval on GitHub

Code credit

BigGuavaTrading, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Volatility & bands, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
MA9 (Weekly)booltrueplotW_EMA9
MA20 (Weekly)booltrueplotW_EMA20
BB Upper (Weekly)booltrueplotW_BBUpper
BB Lower (Weekly)booltrueplotW_BBLower
MA9 (Daily)booltrueplotD_EMA9
MA20 (Daily)booltrueplotD_EMA20
BB Upper (Daily)booltrueplotD_BBUpper
BB Lower (Daily)booltrueplotD_BBLower
EMA 9 Periodint9ema9Len
EMA 20 Periodint20ema20Len
BB Periodint20bbLen
BB StdDevfloat2.0bbStdDev
Show all 13 settings
SettingTypeDefaultVariable
Text SizestringNormaltextSizeInput
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

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

MA Envelope (MAE)

by mihakralj
99 stars

The MA Envelope indicator calculates upper and lower channel bands shifted by a user-defined percentage around a baseline moving average. It supports Simple Moving Average, Exponential Moving Average, and Weighted Moving Average calculation types. The script p

Indicator v6 Moving averagesSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of MA Envelope (MAE)

Moon Dev GEX Walls & Trap

by moondevonyt
92 stars

This indicator estimates gamma exposure levels and intraday context for index instruments like SPY and ES. It calculates VWAP with standard deviation bands as a gamma flip proxy, highlighting market regimes through background colors. It plots prior day high, l

Indicator v5 Support & resistanceSessions & time
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev GEX Walls & Trap

Median

by TWODS-CAPITAL
37 stars

The Median indicator calculates the median of a selected source series such as the high-low average over a user-defined length and plots it as a red line on the price chart. It draws an EMA of the median as a blue line and fills the space between them, changin

Indicator v5 Moving averagesVolatility & bands
Updated 3 years ago · MIT GitHub repository of Median
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

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