Indicator · Pine Script v5 · On the chart

Bollinger Bands (Nadaraya Smoothed) | Flux Charts

by theonetrade· code credited to fluxchart

This indicator plots multi-period Bollinger Bands smoothed using a Nadaraya-Watson kernel estimator directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code186
Settings19inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

186 lines of Pine Script v5 from assets/indicator/bit-exact/bollinger_bands_nadaraya_smoothed_flux_charts_LUoxSDKw.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

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

//@version=5
indicator("Bollinger Bands (Nadaraya Smoothed) | Flux Charts", overlay = true, max_lines_count = 500, max_bars_back = 500)
group_smoothing = "smoothing"
h = input.float(6, "Smoothing Factor", step = .5, tooltip = "The bandwith(h) used in the kernel of the Nadaraya-Watson estimator function." ,group = group_smoothing)
repaint = input.bool(false,"Repaint Smoothing", tooltip = "This setting allows for repainting of the estimation" , group = group_smoothing)
sens = 4

group_boll = "Bollinger Bands Settings (Short, Medium, Long)"
short_period = input.int(20, "Period", inline = "short", group = group_boll)
short_stdev = input.float(3, "Deviation", inline = "short", group = group_boll)
med_period = input.int(75, "Period", inline = "med", group = group_boll)
med_stdev = input.float(4, "Deviation", inline = "med", group = group_boll)
long_period = input.int(100, " Period", inline = "long", group = group_boll)
long_stdev = input.float(4.25, "Deviation", inline = "long", group = group_boll)

group_graphics = "Plots and Labels"
label_src = input.string("Close", "Label Source",["Pivots", "Close", "High/Low"] , group = group_graphics, tooltip = "The source used to determine if price is outside of the Bollinger Bands. The Pivots setting has a four bar delay.")
labels = input.bool(true, "Labels", inline = "label" , group = group_graphics , display = display.none)
plots = input.bool(true, "Plot Lines",  group = group_graphics , display = display.none)
plot_thickness = input.int(2, "Line Width", group = group_graphics , display = display.none)

bands_lvl1 = input.bool(true, "Level 1 Bands", inline = "bands", group = group_graphics)
bands_lvl2 = input.bool(true, "Level 2 Bands", inline = "bands", group = group_graphics)

grp = "Color Theme"
pallete_bear = input.color(color.red, "Bearish", inline = "theme", group = grp, display = display.none)
pallete_bull = input.color(color.green, "Bullish", inline = "theme", group = grp, display = display.none)
alpha1 = input.float(.90, "Transparency: Level 1 ", minval = .1, maxval = 1,inline = "alpha", step = .1, display = display.none)
alpha2 = input.float(.85, "Level 2", minval = .1, maxval = 1, inline = "alpha", step = .1, display = display.none)

grp_n = "Notifications"
notifs = input.bool(false, "Band Breaks", group = grp_n, tooltip = "Recieve notifications when price goes above or below the first level.", display = display.none)

type pallete 
    color bear
    color bull 
    color shade1_bear 
    color shade1_bull 
    color shade2_bear 
    color shade2_bull

create_pallete(color bear, color bull, float alpha1 = 1, float alpha2 = 2) =>
    float shade1 = 100 * alpha1
    float shade2 = 100 * alpha2
    color shade1_bear = color.new(bear, shade1)
    color shade1_bull = color.new(bull, shade1)
    color shade2_bear = color.new(bear, shade2)
    color shade2_bull = color.new(bull, shade2)
    pallete.new(bear, bull, shade1_bear, shade1_bull, shade2_bear, shade2_bull)
    
theme = create_pallete(pallete_bear, pallete_bull, alpha1, alpha2)

const bool bollinger_bands_lvl1 = true
const bool bollinger_bands_lvl2 = true
float tp = (high + low + close) /3

int n_first = 20 
int n_second = 75 
int n_third = 100

guass_w(x, h) => 
   math.exp (-1 *( (x*x) / (2*(h*h)) ))

bollingers(n, factor = 3) =>
    bolu = ta.sma(tp, n) + (factor * ta.stdev(tp, n))
    bold = ta.sma(tp, n) - (factor * ta.stdev(tp, n))
    [bolu, bold]

[BOLU_FIRST, BOLD_FIRST] = bollingers(n_first, short_stdev) 
float BOL_FIRST_GAP = BOLU_FIRST - BOLD_FIRST

[BOLU_SECOND, BOLD_SECOND] = bollingers(n_second, short_stdev) 
float BOL_SECOND_GAP = BOLU_SECOND - BOLD_SECOND

[BOLU_THIRD, BOLD_THIRD] = bollingers(n_third, med_stdev) 
float BOL_THIRD_GAP = BOLU_THIRD - BOLD_THIRD

[BOLU_FOURTH, BOLD_FOURTH] = bollingers(n_third, long_stdev) 

var pivots = array.new<float>()
var pivots2 = array.new<float>()

pivot_rad = sens

float pivot_high = ta.pivothigh(high, pivot_rad, pivot_rad)
float pivot_low = ta.pivotlow(low, pivot_rad, pivot_rad)


add_cols(mat, h_n = 1) =>
    sum_array = array.new<float>()
    for i=0 to matrix.rows(mat)-1
        array.push(sum_array, array.sum(matrix.row(mat, i))/h_n)
    sum_array

nadaraya(src, color) =>
    smoothed = array.new<float>() 
    if barstate.islast and repaint
        for i=0 to 499
            sum = 0.
            gk = array.new<float>()
            for y =0 to 499
                gk.push(guass_w(y - i, h))
            gk_sum = gk.sum()
            for y =0 to 499
                sum += src[y]*(gk.get(y)/gk_sum)
            smoothed.push(sum)
            if i%2 == 0 and i != 0
                line.new(bar_index[i-1], smoothed.get(i-1), bar_index[i], smoothed.get(i), color = color, width = 2)
    smoothed

running_nadaraya(src, n)=>
    var gk = array.new<float>(0)
    var gk_sum =  0.
    var src_matrix = matrix.new<float>()
    smoothed = 0.
    if barstate.isfirst and not repaint
        for i=0 to n
            gk.push(guass_w(i, h))
        gk_sum := gk.sum()
    if not repaint
        for i=n to 0
            smoothed += src[i] * (gk.get(i)/gk_sum)
    smoothed 

n = 499


smoothed_bolu_1 = running_nadaraya(BOLU_FIRST, n)
smoothed_bold_1 = running_nadaraya(BOLD_FIRST, n)

smoothed_bolu_2 = running_nadaraya(BOLU_SECOND, n)
smoothed_bold_2 = running_nadaraya(BOLD_SECOND, n)

smoothed_bolu_3 = running_nadaraya(BOLU_THIRD, n)
smoothed_bold_3 = running_nadaraya(BOLD_THIRD, n)

smoothed_bolu_4 = running_nadaraya(BOLU_FOURTH, n)
smoothed_bold_4 = running_nadaraya(BOLD_FOURTH, n)

BOLU_FIRST_PLOT = plot(smoothed_bolu_1, display = display.none)
BOLD_FIRST_PLOT = plot(smoothed_bold_1, display = display.none)

BOLU_SECOND_PLOT = plot(smoothed_bolu_2, display = display.none)
BOLD_SECOND_PLOT = plot(smoothed_bold_2, display = display.none)

BOLU_THIRD_PLOT = plot(smoothed_bolu_3, display = display.none)
BOLD_THIRD_PLOT = plot(smoothed_bold_3, display = display.none)

BOLU_FOURTH_PLOT = plot(smoothed_bolu_4, display = display.none)
BOLD_FOURTH_PLOT = plot(smoothed_bold_4, display = display.none)

if repaint
    nadaraya(BOLU_FIRST, theme.bear)
    nadaraya(BOLD_FIRST, theme.bull)
    
spacing = ta.atr(300)

band_test_upper_source = label_src == "Pivots" ? pivot_high : label_src == "Close" ? close : high
band_test_lower_source = label_src == "Pivots" ? pivot_low : label_src == "Close" ? close : low

offset = label_src == "Pivots" ? sens : 0

upper_band_test = band_test_upper_source  >= smoothed_bolu_1[offset] and (band_test_upper_source[1] <= smoothed_bolu_1[offset] or na(band_test_upper_source[1])) and not repaint ? band_test_upper_source + spacing * 1.01  : na
lower_band_test = band_test_lower_source  <= smoothed_bold_1[offset] and (band_test_lower_source[1] >= smoothed_bold_1[offset] or na(band_test_upper_source[1])) and not repaint ? band_test_lower_source - spacing * 1.01  : na


if notifs and close > smoothed_bolu_1
    alert("Upper Band Crossed on " + syminfo.ticker, alert.freq_once_per_bar_close)
else if notifs and close < smoothed_bold_1
    alert("Lower Band Crossed on " + syminfo.ticker, alert.freq_once_per_bar_close)



plotshape(labels ? upper_band_test : na, style = shape.triangledown, location = location.absolute, color = theme.bear, offset = -1*offset, size = size.tiny)
plotshape(labels ? lower_band_test : na, style = shape.triangleup, location = location.absolute, color = theme.bull, offset = -1*offset, size = size.tiny)

plot(not repaint and plots ? smoothed_bolu_1 : na, linewidth = plot_thickness, color = theme.bear)
plot(not repaint and plots ? smoothed_bold_1 : na, linewidth = plot_thickness, color = theme.bull)

fill(BOLU_FIRST_PLOT, BOLU_SECOND_PLOT, theme.shade1_bear, display = bands_lvl1 ? display.all: display.none)
fill(BOLD_FIRST_PLOT, BOLD_SECOND_PLOT, theme.shade1_bull, display = bands_lvl1 ? display.all: display.none)
fill(BOLU_SECOND_PLOT, BOLU_THIRD_PLOT, theme.shade2_bear, display = bands_lvl2 ? display.all: display.none)
fill(BOLD_SECOND_PLOT, BOLD_THIRD_PLOT, theme.shade2_bull, display = bands_lvl2 ? display.all: display.none)

Overview

Bollinger Bands (Nadaraya Smoothed) | Flux Charts calculates three distinct band sets—short, medium, and long periods—with customizable standard deviation multipliers and color themes. Traders can toggle dual-level shading, visual break labels, line thicknesses, and alert notifications for price breaches outside the bands. A smoothing bandwidth parameter controls the kernel calculation, with an optional setting to enable repainting estimations for smoother outputs.

Details

Published by

theonetrade on GitHub

Code credit

fluxchart, as written in the script's header

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Smoothing Factorfloat6h
Repaint Smoothingboolfalserepaint
Periodint20short_period
Deviationfloat3short_stdev
Periodint75med_period
Deviationfloat4med_stdev
Periodint100long_period
Deviationfloat4.25long_stdev
Label SourcestringCloselabel_src
Labelsbooltruelabels
Plot Linesbooltrueplots
Line Widthint2plot_thickness
Show all 19 settings
SettingTypeDefaultVariable
Level 1 Bandsbooltruebands_lvl1
Level 2 Bandsbooltruebands_lvl2
Bearishcolorcolor.redpallete_bear
Bullishcolorcolor.greenpallete_bull
Transparency: Level 1 float.90alpha1
Level 2float.85alpha2
Band Breaksboolfalsenotifs
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

321 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 8 days ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
280 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 4 weeks ago · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
220 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 2 years ago · None stated GitHub repository of Adaptive MA Slope

More Volatility & bands scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers