Neural Kernel Bands [JOAT]NEURAL KERNEL BANDS
A non-parametric kernel-regression centreline wrapped in adaptive residual sigma bands. Where a moving average assumes price was generated by a fixed-form equation (linear in lag, weighted in lag, etc.), kernel regression makes no such assumption — it lets the local density of the data decide where the centreline should sit. The result is a smoother, more honest representation of where price really is, without the corner-cutting that EMAs and HMAs introduce around pivots.
Why kernel regression instead of another moving average
Every moving average is a kernel — but a rectangular one (or in HMA's case, a chained-weighted one). Kernel regression generalises the idea: instead of one fixed weight curve, you pick the shape of the curve based on the assumption you want to make about how much each historical bar should matter. Neural Kernel Bands ships three:
Gaussian — the textbook bell curve, K(u) = exp(−u² / 2h²). Heavy tails, smooth everywhere. The most stable default.
Epanechnikov — compact-support parabolic, K(u) = max(0, 1 − u²/h²). Mathematically optimal in the mean-squared-error sense; lightest tails, slightly more responsive than Gaussian at the leading edge.
Tricube — LOWESS-style, K(u) = max(0, (1 − |u/h|³)³). Very smooth shoulders; great on noisy intraday data where you want a confident centreline rather than a chasing one.
All three feed the same Nadaraya–Watson skeleton — a weighted-average estimator of the form ŷ = Σ K(i)·close / Σ K(i) — and all three respect the bandwidth h in the same way. The kernel choice changes the personality of the line; the bandwidth controls its memory.
Adaptive bandwidth (ATR-scaled)
Static bandwidths break in changing regimes. When realised volatility expands, a fixed bandwidth produces a centreline that lags badly; when it contracts, the same bandwidth becomes noise-amplifying. Neural Kernel Bands scales h in real time by normalised ATR — so the kernel widens when the market is volatile and tightens when it is quiet. The scale is intentional: h_effective = h_base × (1 + ATR/close × factor) , which keeps the band stable across instruments without per-symbol tuning.
A bandwidth-jump alert fires when h moves by more than a user-set fraction in a single bar. This is your early-warning signal that the volatility regime has flipped — useful both as a confirmation for breakouts and as a heads-up that any reversion play has just become higher-risk.
Residual sigma bands
The bands themselves are not arbitrary multiples of ATR. They are the rolling standard deviation of the residual (close − kernel MA), EMA-smoothed, then scaled by your sigma multiplier. This is a meaningful number — it answers the question: how much do we usually deviate from the kernel before reverting? When the answer is small, the bands hug the line and a breakout is statistically significant; when the answer is large, breaks of the band are normal and should be downweighted accordingly.
A confirmed close above the upper band latches the state to Bullish ; a confirmed close below the lower band latches to Bearish . State only flips on the opposite band — there is no neutral repainting. Buy / Sell labels fire on the state-flip bar, not on every confirming bar, so the chart stays clean.
Divergence engine
A pure slope-comparison divergence runs in parallel: it compares the kernel slope over a lookback window against the price slope over the same window. Bullish divergence is registered when price slope is negative AND kernel slope is positive (price falling, kernel turning up); bearish divergence is the mirror. Both slopes must exceed a user-set fraction of ATR × lookback so flat regions never trigger noise divergences, and a cooldown spaces them out. Divergence labels print ▲ Div or ▼ Div in the palette colour at the wick they fire from.
Three visual modes
The same kernel and sigma feed every mode — pick the one that matches your chart style:
Bands — classic upper / lower envelope with toggleable fill. Best for mean-reversion and band-touch analysis.
Single Line — kernel centreline with a gradient fill between the line and price. Best for pure trend-following.
Trail — only the trailing band is drawn, in the active state colour, with an optional sin-modulated pulse alpha that creates a subtle animated breathing effect. Best for visual conviction in directional moves.
State candles and bar colouring are independent toggles, so you can layer or strip the visual stack to taste.
Dashboard
A 10-row monospaced table with a subtle vertical-alpha gradient, positionable to any of nine corners. Each row carries one live diagnostic:
Signal — current latched state with directional glyph.
Kernel MA — current centreline value.
Upper Band — current upper-sigma band.
Lower Band — current lower-sigma band.
Band Width σ — the residual sigma itself (volatility metric).
Bandwidth h — current kernel bandwidth, with (adaptive) tag when ATR-scaling is on.
Kernel — active kernel name (Gaussian / Epanechnikov / Tricube).
Divergence — bull / bear divergence active, with bar age.
Regime — stable or ⚡ SHIFT, with the % bandwidth jump that triggered it.
Alerts
Five alert conditions, each non-repainting:
NKB — Bullish Breakout (close crosses above upper band)
NKB — Bearish Breakdown (close crosses below lower band)
NKB — Bullish Divergence
NKB — Bearish Divergence
NKB — Bandwidth Regime Shift
How to use it
For trend-following: switch to Single Line or Trail mode, set the kernel to Tricube with adaptive bandwidth ON, and take state-flip labels in the direction of the higher-timeframe kernel. For mean-reversion: switch to Bands mode, set the kernel to Gaussian or Epanechnikov, and fade band touches that occur with a divergence label and a low band-width-sigma reading. The Bandwidth Regime Shift alert is most useful as a heads-up — it fires before either of the directional alerts and tells you the volatility surface has just changed; whatever play you had on a minute ago may need to be re-evaluated.
Suggested settings
Defaults are tuned for the 15m–1H window on liquid futures and crypto. For 5m and below, drop Lookback Window to ~20 and Base Bandwidth (h) to ~6.0. For daily and above, raise Lookback to 50 and Bandwidth to 12. The kernel choice and the bandwidth jointly control how much the line trusts the recent past ; the sigma multiplier separately controls how much movement you are willing to call normal .
Limitations
The kernel regression is computed each bar over the lookback window — on very long lookbacks the script does real arithmetic across many bars, so very low timeframes on very long windows can feel heavy. State transitions and signals are confirmed on bar close, so a band-touch within the bar that gets reabsorbed will not fire a signal — this is deliberate and prevents intra-bar repainting. Divergence is non-repainting but is computed at the current bar, so it carries the natural lag of comparing slopes over a window.
—
Closed-source: the kernel weighting routine, the adaptive-bandwidth scaling factor, the residual-sigma smoothing chain, and the regime-shift trigger logic are proprietary. Behaviour is fully described above so you can judge fit before deciding it belongs on your chart.
—
-made with passion by jackofalltrades
Pine Script®指标






















