Indicator · Pine Script v6 · Own pane

Nadaraya-Watson Regression Liquidity Sweeps [AlgoAlpha]

by theonetrade· code credited to AlgoAlpha

Calculates a normalized slope oscillator based on Nadaraya-Watson non-parametric regression combined with ATR volatility measurements.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code205
Settings15inputs
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

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

nadaraya_watson_regression_liquidity_sweeps_algoalpha_IdfeKkUv.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha

//@version=6
indicator("Nadaraya-Watson Regression Liquidity Sweeps [AlgoAlpha]", "AlgoAlpha - Nadaraya-Watson Regression Liquidity", overlay = false, max_lines_count = 500)

group_regression = "Regression"
group_oscillator = "Oscillator"
group_volatility = "Volatility"
group_levels = "Liquidity Levels"
group_appearance = "Appearance"

norm_len = input.int(100, "Normalization Length", minval = 1, group = group_oscillator, tooltip = "Controls the standard deviation window used to normalize the Nadaraya-Watson slope. Increasing it makes oscillator scaling more stable and slower to adapt; decreasing it makes scaling adapt faster but can make the oscillator more reactive and noisy.")
nw_bandwidth = input.int(30, "Nadaraya-Watson Bandwidth", minval = 1, group = group_regression, tooltip = "Controls the width of the Nadaraya-Watson kernel. Increasing it makes the regression smoother and slower to turn; decreasing it makes the regression track price more closely but can add noise.")
nw_lookback = input.int(140, "Nadaraya-Watson Lookback", minval = 1, group = group_regression, tooltip = "Controls how many historical bars are included in the Nadaraya-Watson estimate. Increasing it uses more history for a more stable curve; decreasing it focuses more on recent price action and reacts faster.")
osc_smooth_len = input.int(21, "Oscillator Smoothing Length", minval = 1, group = group_oscillator, tooltip = "Controls the WMA smoothing applied to the normalized slope oscillator. Increasing it makes the oscillator smoother with fewer sharp turns; decreasing it makes the oscillator more responsive but choppier.")
signal_len = input.int(14, "Signal Length", minval = 1, group = group_oscillator, tooltip = "Controls the EMA length of the oscillator signal line. Increasing it makes signal crosses slower and less frequent; decreasing it makes crosses happen earlier and more often.")
atr_len = input.int(14, "ATR Length", minval = 1, group = group_volatility, tooltip = "Controls the ATR window used for the price overlay volatility offset. Increasing it makes volatility measurement smoother; decreasing it makes the overlay react faster to recent range expansion or contraction.")
vol_smooth_len = input.int(21, "Volatility Smoothing Length", minval = 1, group = group_volatility, tooltip = "Controls the smoothing applied to ATR before it is used in the overlay. Increasing it creates a steadier volatility offset; decreasing it makes the offset expand and contract more quickly.")

use_tip = input.bool(true, "Use Swing Points", group = group_levels, tooltip = "When enabled, liquidity levels are anchored to the highest high or lowest low reached during the active oscillator phase. When disabled, new levels are anchored to the current bar high or low when the signal event occurs.")

show_nw_band_candles = input.bool(true, "Show Nadaraya-Watson Band Candles", group = group_appearance, tooltip = "When enabled, plots the Nadaraya-Watson volatility band as overlay candles. Disabling it hides the band candles without changing calculations, levels, signals, or alerts.")
show_bar_color_candles = input.bool(true, "Show Bar Colour Candles", group = group_appearance, tooltip = "When enabled, redraws price candles with oscillator-based bullish or bearish colours using plotcandle. Disabling it leaves the chart's normal candles visually unchanged.")
show_signal_line = input.bool(true, "Show Oscillator Signal Line", group = group_appearance, tooltip = "When enabled, displays the EMA signal line of the oscillator. Disabling it hides the signal line but keeps signal-cross logic active.")
show_momentum_signals = input.bool(true, "Show Momentum Weakening Signals", group = group_appearance, tooltip = "When enabled, displays the small momentum weakening dots on the chart. Disabling it hides those visual markers without affecting alert conditions.")
show_rebound_signals = input.bool(true, "Show Rebound Signals", group = group_appearance, tooltip = "When enabled, displays bullish and bearish rebound markers around the Nadaraya-Watson value. Disabling it hides those visual markers without affecting calculations.")

green = input.color(#00ffbb, "Bullish Colour", group = group_appearance, tooltip = "Sets the bullish color used for positive oscillator fills, bullish price overlay coloring, lower liquidity levels, and bullish momentum events.")
red = input.color(#ff1100, "Bearish Colour", group = group_appearance, tooltip = "Sets the bearish color used for negative oscillator fills, bearish price overlay coloring, upper liquidity levels, and bearish momentum events.")

nw(series float src, simple int bandwidth, simple int lookback) =>
    float num = 0.0
    float den = 0.0
    float h2  = 2.0 * math.pow(bandwidth, 2)
    for i = 0 to lookback - 1
        float w = math.exp(-math.pow(i, 2) / h2)
        num += src[i] * w
        den += w
    num / den

pseudo_transp(color c, int transp) =>
    color.from_gradient(transp, 0, 100, c, chart.bg_color)

nw_val   = nw(close, nw_bandwidth, nw_lookback)
nw_slope = nw_val - nw_val[1]

slope_std = ta.stdev(nw_slope, norm_len)
osc_      = nw_slope / slope_std
osc       = ta.wma(osc_, osc_smooth_len)
signal    = ta.ema(osc, signal_len)

volatility = ta.sma(ta.atr(atr_len), vol_smooth_len)

overflow = math.max(math.abs(osc) - 2, 0)

con1 = ta.crossunder(osc, signal)
con2 = ta.crossover(osc, signal)

above_signal = osc > signal
below_signal = osc < signal

var float above_tip_price = na
var int above_tip_bar = na

var float below_tip_price = na
var int below_tip_bar = na

if above_signal
    if not above_signal[1]
        above_tip_price := high
        above_tip_bar := bar_index
    else if na(above_tip_price) or high > above_tip_price
        above_tip_price := high
        above_tip_bar := bar_index

if below_signal
    if not below_signal[1]
        below_tip_price := low
        below_tip_bar := bar_index
    else if na(below_tip_price) or low < below_tip_price
        below_tip_price := low
        below_tip_bar := bar_index

draw_upper_line = osc > 0 and con1
draw_lower_line = osc < 0 and con2
draw_new_line = draw_upper_line or draw_lower_line

var line active_line = na
var float active_line_price = na
var int active_line_type = 0

upper_level_swept = not na(active_line) and active_line_type == 1 and close > active_line_price
lower_level_swept = not na(active_line) and active_line_type == -1 and close < active_line_price

if not na(active_line) and active_line_type != 0
    line.set_x2(active_line, bar_index)

    line_crossed = active_line_type == 1 ? close > active_line_price : close < active_line_price

    if line_crossed or draw_new_line
        active_line_type := 0

if draw_upper_line
    float level_price = use_tip and not na(above_tip_price) ? above_tip_price : high
    int level_bar = use_tip and not na(above_tip_bar) ? above_tip_bar : bar_index

    active_line := line.new(
         x1 = level_bar,
         y1 = level_price,
         x2 = bar_index,
         y2 = level_price,
         xloc = xloc.bar_index,
         extend = extend.none,
         color = red,
         style = line.style_solid,
         width = 2,
         force_overlay = true
     )

    active_line_price := level_price
    active_line_type := 1

if draw_lower_line
    float level_price = use_tip and not na(below_tip_price) ? below_tip_price : low
    int level_bar = use_tip and not na(below_tip_bar) ? below_tip_bar : bar_index

    active_line := line.new(
         x1 = level_bar,
         y1 = level_price,
         x2 = bar_index,
         y2 = level_price,
         xloc = xloc.bar_index,
         extend = extend.none,
         color = green,
         style = line.style_solid,
         width = 2,
         force_overlay = true
     )

    active_line_price := level_price
    active_line_type := -1

weakening_bullish_momentum = osc > 0 and con1
weakening_bearish_momentum = osc < 0 and con2
bullish_zero_cross = ta.crossover(osc, 0)
bearish_zero_cross = ta.crossunder(osc, 0)
bullish_signal_cross = con2
bearish_signal_cross = con1
bullish_rebound = osc > 0 and close[1] < nw_val and close > nw_val
bearish_rebound = osc < 0 and close[1] > nw_val and close < nw_val

main = plot(osc, "Oscillator", color.blue, 2, plot.style_line, display = display.none)
plot(signal, "Signal Line", show_signal_line ? color.new(chart.fg_color, 50) : na)

ovf = plot(osc > 2 ? overflow : osc < -2 ? -overflow : 0, "Overflow", display = display.none)

zero = plot(0, "Zero Line", chart.fg_color)

col_ = osc > 0 ? color.from_gradient(osc, 0, 3, pseudo_transp(green, 80), pseudo_transp(green, 30)) : color.from_gradient(osc, -3, 0, pseudo_transp(red, 30), pseudo_transp(red, 80))

fill(main, ovf, col_, "Oscillator Fill")
fill(zero, ovf, osc > 0 ? green : red, "Oscillator Fill")

plotcandle(
     open = show_nw_band_candles ? nw_val + (osc > 0 ? -volatility : volatility) : na,
     high = show_nw_band_candles ? osc < 0 ? high : nw_val : na,
     low = show_nw_band_candles ? osc > 0 ? low : nw_val : na,
     close = show_nw_band_candles ? nw_val : na,
     title = "Nadaraya-Watson Band",
     bordercolor = na,
     force_overlay = true,
     color = col_,
     wickcolor = color.new(col_, 70)
 )

plotcandle(
     open = show_bar_color_candles ? open : na,
     high = show_bar_color_candles ? high : na,
     low = show_bar_color_candles ? low : na,
     close = show_bar_color_candles ? close : na,
     title = "Price",
     color = col_,
     wickcolor = col_,
     bordercolor = col_,
     force_overlay = true
 )

plotchar(show_momentum_signals and weakening_bullish_momentum, "Weakening Bullish Momentum", "●", location.abovebar, green, size = size.tiny, force_overlay = true)
plotchar(show_momentum_signals and weakening_bearish_momentum, "Weakening Bearish Momentum", "●", location.belowbar, red, size = size.tiny, force_overlay = true)

plotchar(show_rebound_signals and bullish_rebound ? nw_val - volatility * 1.5 : na, "Bullish Rebound", "▲", location.absolute, green, size = size.tiny, force_overlay = true)
plotchar(show_rebound_signals and bearish_rebound ? nw_val + volatility * 1.5 : na, "Bearish Rebound", "▼", location.absolute, red, size = size.tiny, force_overlay = true)

//ALERTS
alertcondition(weakening_bullish_momentum, title = "Weakening Bullish Momentum")
alertcondition(weakening_bearish_momentum, title = "Weakening Bearish Momentum")
alertcondition(bullish_signal_cross, title = "Bullish Signal Cross")
alertcondition(bearish_signal_cross, title = "Bearish Signal Cross")
alertcondition(bullish_zero_cross, title = "Bullish Zero Cross")
alertcondition(bearish_zero_cross, title = "Bearish Zero Cross")
alertcondition(draw_upper_line, title = "New Upper Liquidity Sweep Level")
alertcondition(draw_lower_line, title = "New Lower Liquidity Sweep Level")
alertcondition(upper_level_swept, title = "Upper Liquidity Sweep Level Swept")
alertcondition(lower_level_swept, title = "Lower Liquidity Sweep Level Swept")

Overview

Nadaraya-Watson Regression Liquidity Sweeps [AlgoAlpha] generates momentum weakening signals, rebound signals, and tracks liquidity levels anchored to price swing points or signal events. Key settings adjust the regression bandwidth, lookback window, normalization period, oscillator smoothing, and signal EMA lengths. The indicator plots in a separate pane with options for custom bar coloring and visual candle overlays.

Details

Published by

theonetrade on GitHub

Code credit

AlgoAlpha, as written in the script's header

Draws

Separate pane below the 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
Normalization Lengthint100norm_len
Nadaraya-Watson Bandwidthint30nw_bandwidth
Nadaraya-Watson Lookbackint140nw_lookback
Oscillator Smoothing Lengthint21osc_smooth_len
Signal Lengthint14signal_len
ATR Lengthint14atr_len
Volatility Smoothing Lengthint21vol_smooth_len
Use Swing Pointsbooltrueuse_tip
Show Nadaraya-Watson Band Candlesbooltrueshow_nw_band_candles
Show Bar Colour Candlesbooltrueshow_bar_color_candles
Show Oscillator Signal Linebooltrueshow_signal_line
Show Momentum Weakening Signalsbooltrueshow_momentum_signals
Show all 15 settings
SettingTypeDefaultVariable
Show Rebound Signalsbooltrueshow_rebound_signals
Bullish Colourcolor#00ffbbgreen
Bearish Colourcolor#ff1100red
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

4 stars

This indicator is a live strategy scanner for cryptocurrency pairs. It runs six strategies on the current chart, tracks their wins and losses, and rates them to show the best one for this pair and timeframe. It uses ATR for adaptive TP/SL, auto-scales based on

Indicator v5 Oscillators & momentumVolatility & bands
Updated 3 weeks ago · None stated GitHub repository of Crypto Pair Selector v2 STEPFUN

Moon Dev Lunar Sniper

by moondevonyt
98 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper
14 stars

Self-Aware Trend System calculates volatility-adaptive ATR trailing bands using a Trend Quality Index engine that evaluates market efficiency, momentum persistence, and structural pivots. It plots adaptive trend bands and character-flip trend signals directly

Indicator v6 TrendVolatility & bands
Updated 6 weeks ago · MIT GitHub repository of Self-Aware Trend System [WillyAlgoTrader]

Cerebr Wave

by jerryinyang
5 stars

Cerebr Wave is an overlay indicator that combines multi-timeframe Keltner Channels with a Wave Trend oscillator to analyze market structure and momentum. It calculates higher-timeframe and lower-timeframe Keltner Channels alongside Wave Trend crossover signals

Indicator v4 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Cerebr Wave

Cyber HUD XAU

by panzmoravylab
3 stars

Cyber HUD XAU is an overlay indicator designed for XAUUSD that combines trend, momentum, and volatility filters. It calculates fast and slow ATR ratios alongside local price ranges to detect consolidation and chop filter states. The script evaluates candle bod

Indicator v6 Volatility & bandsOscillators & momentum
Updated 4 months ago · None stated GitHub repository of Cyber HUD XAU

Setup-1

by IAMATOMIC001
3 stars

This indicator plots multiple technical analysis components directly on the price chart, including a Nadaraya-Watson envelope, pivot-based trendlines, and a kernel regression oscillator. It also renders visual overlay panels for the Relative Strength Index and

Indicator v5 TrendOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Setup-1

More Trend 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