Neural Probability Channel Upper study, Lower study and MTF version study.
I added clouds, candle color, dark gray inner lines, and divergence for the lower study oscillator. This is a 2-hour chart of /NQ.
Original code can be found here. https://www.tradingview.com/script/mFj3oD5h-Neural-Probability-Channel-AlgoPoint/
The Neural Probability Channel (NPC) is a next-generation volatility and trend analysis tool designed to overcome the limitations of traditional bands (like Bollinger Bands) and smoothing filters (like standard Moving Averages).
Unlike traditional indicators that rely on linear deviation or simple averages, the NPC utilizes a Rational Quadratic Kernel—a concept derived from machine learning regression models—to calculate a non-repainting, highly adaptive baseline (Fair Value). This allows the indicator to distinguish between market noise and genuine trend shifts with superior accuracy.
The volatility bands are dynamically calculated using a hybrid of Standard Error (Mean Deviation) and ATR, ensuring the channels adapt organically to market conditions—expanding during high-impact moves and contracting during consolidation.
How It Works
- The Neural Baseline (Center Line): Instead of a standard Moving Average, the NPC uses a Rational Quadratic Kernel weighting system. This assigns "importance" to price data based on both recency and similarity. It acts as a "Center of Gravity" for price, providing a smoother yet responsive trend detection line without the lag associated with SMAs or EMAs.
Crucially, the math is causal (no lookahead), meaning it does not repaint.
Signal Generation:
How to Use It
If price is holding below the baseline and the cloud is red, the trend is Bearish.
- Squeeze Detection: When the Inner and Outer bands compress significantly, it indicates low volatility and often precedes an explosive breakout.
Upper Chart Code:
Lower Chart Code:
MTF Version
Picture of the 5-min chart using 1-hour MTF.
I added clouds, candle color, dark gray inner lines, and divergence for the lower study oscillator. This is a 2-hour chart of /NQ.
Original code can be found here. https://www.tradingview.com/script/mFj3oD5h-Neural-Probability-Channel-AlgoPoint/
The Neural Probability Channel (NPC) is a next-generation volatility and trend analysis tool designed to overcome the limitations of traditional bands (like Bollinger Bands) and smoothing filters (like standard Moving Averages).
Unlike traditional indicators that rely on linear deviation or simple averages, the NPC utilizes a Rational Quadratic Kernel—a concept derived from machine learning regression models—to calculate a non-repainting, highly adaptive baseline (Fair Value). This allows the indicator to distinguish between market noise and genuine trend shifts with superior accuracy.
The volatility bands are dynamically calculated using a hybrid of Standard Error (Mean Deviation) and ATR, ensuring the channels adapt organically to market conditions—expanding during high-impact moves and contracting during consolidation.
How It Works
- The Neural Baseline (Center Line): Instead of a standard Moving Average, the NPC uses a Rational Quadratic Kernel weighting system. This assigns "importance" to price data based on both recency and similarity. It acts as a "Center of Gravity" for price, providing a smoother yet responsive trend detection line without the lag associated with SMAs or EMAs.
Crucially, the math is causal (no lookahead), meaning it does not repaint.
- Adaptive Volatility Bands: The channel width is not fixed. It uses a Hybrid Volatility Model:
- Inner Channel: Represents the "Probability Zone" (approx. 70% confidence). Price staying here indicates a stable trend.
- Outer Channel: Represents "Extreme Deviation" (Statistical Anomalies). When price touches or breaches these outer bands, it is statistically overextended (Overbought/Oversold).
Signal Generation:
- Reversion Signals: Generated when price breaches the Outer Bands and closes back inside. This suggests a "Snap-back" or Mean Reversion event.
- Trend Confirmation: The color of the baseline and the fill zones changes based on the slope of the Kernel, giving an instant visual read on market bias.
How to Use It
- Mean Reversion Strategy: Look for price action extending beyond the Outer Bands (Thinner lines). If price leaves a wick and closes back inside, it signals a high-probability reversal toward the Neural Baseline.
- Green Signal: Potential Long (Reversal from Lows).
- Red Signal: Potential Short (Reversal from Highs).
- Trend Following: Use the Neural Baseline (Thick Center Line) as a dynamic support/resistance level.
If price is holding below the baseline and the cloud is red, the trend is Bearish.
- Squeeze Detection: When the Inner and Outer bands compress significantly, it indicates low volatility and often precedes an explosive breakout.
Upper Chart Code:
Code:
# ------------------------------------------------------------
# Neural Probability Channel(NPC) [AlgoPoint]
# Original code found at https://www.tradingview.com/script/mFj3oD5h-Neural-Probability-Channel-AlgoPoint/
# Converted and enhanced by Chewie 2/8/2026
# ------------------------------------------------------------
declare upper;
# =========================
# INPUTS
# =========================
input colorbar = yes;
input length = 24;
input h_param = 8.0;
input r_param = 2.0;
input mult_in = 0.65;
input mult_inner = 1.3;
input mult_mid = 1.95;
input mult_outer = 2.6;
# =========================
# COLORS
# =========================
DefineGlobalColor("Bear", CreateColor(242, 54, 69));
DefineGlobalColor("Bull", CreateColor(8, 153, 129));
# =========================
# SOURCE
# =========================
def src = (high + low + close) / 3;
# =========================
# KERNEL REGRESSION (INLINE)
# =========================
def numerator =
fold k1 = 0 to length
with acc1 = 0
do acc1 +
src[k1] *
Power(
1 + Sqr(k1) / (2 * r_param * Sqr(h_param)),
-r_param
);
def denominator =
fold k2 = 0 to length
with acc2 = 0
do acc2 +
Power(
1 + Sqr(k2) / (2 * r_param * Sqr(h_param)),
-r_param
);
def y_hat = numerator / denominator;
# =========================
# VOLATILITY
# =========================
def errorSum =
fold k3 = 0 to length
with acc3 = 0
do acc3 + AbsValue(src[k3] - y_hat);
def meanDeviation = errorSum / length;
def volatility = (meanDeviation + ATR(length)) / 2;
# =========================
# CHANNELS
# =========================
def upperInner1 = y_hat + volatility * mult_inner;
def lowerInner1 = y_hat - volatility * mult_inner;
def upperOuter1 = y_hat + volatility * mult_outer;
def lowerOuter1 = y_hat - volatility * mult_outer;
def uppermid1 = y_hat + volatility * mult_mid;
def lowermid1 = y_hat - volatility * mult_mid;
def uppermidin = y_hat + volatility * mult_in;
def lowermidin = y_hat - volatility * mult_in;
# =========================
# TREND
# =========================
def upTrend = y_hat > y_hat[1];
# =========================
# PLOTS
# =========================
plot Baseline = y_hat;
Baseline.AssignValueColor(if upTrend then GlobalColor("Bull") else GlobalColor("Bear"));
Baseline.SetLineWeight(2);
plot uppermid = uppermidin;
uppermid.setdefaultColor(color.dark_gray);
plot lowermid = lowermidin;
lowermid.setdefaultColor(color.dark_gray);
plot UpperInner = upperInner1;
UpperInner.SetDefaultColor(GlobalColor("Bear"));
plot LowerInner = lowerInner1;
LowerInner.SetDefaultColor(GlobalColor("Bull"));
plot UpperOuter = upperOuter1;
UpperOuter.SetDefaultColor(GlobalColor("Bear"));
UpperOuter.SetLineWeight(2);
plot LowerOuter = lowerOuter1;
LowerOuter.SetDefaultColor(GlobalColor("Bull"));
LowerOuter.SetLineWeight(2);
# =========================
# SIGNALS
# =========================
def buy = if low crosses above lowerOuter then low - ATR(60) / 2 else Double.NaN;
def sell = if high crosses below upperOuter then high + ATR(60) / 2 else Double.NaN;
plot BuySignal = buy;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.SetDefaultColor(COLOR.CYAN);
plot SellSignal = sell;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.SetDefaultColor(COLOR.MAGENTA);
# =========================
# Clouds
# =========================
AddCloud(lowerinner, lowerouter, Color.dark_green, Color.dark_green);
AddCloud(upperinner, upperouter, Color.dark_red, Color.dark_red);
AddCloud(lowermid1, lowerouter, GlobalColor("Bull"), GlobalColor("Bull"));
AddCloud(uppermid1, upperouter, GlobalColor("Bear"), GlobalColor("Bear"));
# =========================
# Color Bars
# =========================
def bull = close > baseline;
def bear = close < baseline;
AssignPriceColor(if !colorbar then Color.CURRENT else if bull then GlobalColor("Bull") else if bear then GlobalColor("Bear") else Color.GRAY);
#END OF CODE
Lower Chart Code:
Code:
# ------------------------------------------------------------
# Neural Probability Channel (PNC) – LOWER STUDY
# Assembled by Chewie 2/8/2026
# ------------------------------------------------------------
declare lower;
# =========================
# INPUTS
# =========================
input length = 24;
input h_param = 8.0;
input r_param = 2.0;
input mult_in = 0.65;
input mult_inner = 1.3;
input mult_mid = 1.95;
input mult_outer = 2.6;
# =========================
# COLORS
# =========================
DefineGlobalColor("Bear", CreateColor(242, 54, 69));
DefineGlobalColor("Bull", CreateColor(8, 153, 129));
DefineGlobalColor("Neutral", Color.DARK_GRAY);
# =========================
# SOURCE
# =========================
def src = (high + low + close) / 3;
# =========================
# KERNEL REGRESSION
# =========================
def numerator =
fold k1 = 0 to length
with acc1 = 0
do acc1 +
src[k1] *
Power(1 + Sqr(k1) / (2 * r_param * Sqr(h_param)), -r_param);
def denominator =
fold k2 = 0 to length
with acc2 = 0
do acc2 +
Power(1 + Sqr(k2) / (2 * r_param * Sqr(h_param)), -r_param);
def y_hat = numerator / denominator;
# =========================
# VOLATILITY
# =========================
def errorSum =
fold k3 = 0 to length
with acc3 = 0
do acc3 + AbsValue(src[k3] - y_hat);
def meanDev = errorSum / length;
def volatility = (meanDev + ATR(length)) / 2;
# =========================
# NORMALIZED OSCILLATOR
# =========================
def osc = (src - y_hat) / volatility;
# =========================
# LEVELS
# =========================
plot ZeroLine = 0;
ZeroLine.AssignValueColor(if osc > 0 then GlobalColor("Bull") else GlobalColor("Bear"));
plot UpperIn = mult_in;
plot LowerIn = -mult_in;
plot UpperInner = mult_inner;
plot LowerInner = -mult_inner;
def UpperMid = mult_mid;
def LowerMid = -mult_mid;
plot UpperOuter = mult_outer;
plot LowerOuter = -mult_outer;
UpperIn.SetDefaultColor(GlobalColor("Neutral"));
LowerIn.SetDefaultColor(GlobalColor("Neutral"));
UpperInner.SetDefaultColor(GlobalColor("Bear"));
LowerInner.SetDefaultColor(GlobalColor("Bull"));
#UpperMid.SetDefaultColor(GlobalColor("Bear"));
#LowerMid.SetDefaultColor(GlobalColor("Bull"));
UpperOuter.SetDefaultColor(GlobalColor("Bear"));
LowerOuter.SetDefaultColor(GlobalColor("Bull"));
UpperOuter.SetLineWeight(2);
LowerOuter.SetLineWeight(2);
# =========================
# OSCILLATOR PLOT
# =========================
plot Oscillator = osc;
Oscillator.AssignValueColor(
if osc > 0 then GlobalColor("Bull") else GlobalColor("Bear")
);
Oscillator.SetLineWeight(2);
# =========================
# SIGNALS
# =========================
plot BuySignal = if osc crosses above -mult_outer then -mult_outer else double.nan;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.SetDefaultColor(color.cyan);
plot SellSignal = if osc crosses below mult_outer then mult_outer else double.nan;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.SetDefaultColor(color.magenta);
# =========================
# CLOUDS
# =========================
AddCloud(Lowermid, LowerOuter, GlobalColor("Bull"), GlobalColor("Bull"));
AddCloud(Uppermid, UpperOuter, GlobalColor("Bear"), GlobalColor("Bear"));
AddCloud(lowerinner, lowerouter, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(upperinner, upperouter, Color.DARK_RED, Color.DARK_RED);
AddCloud(oscillator, zeroline, Color.DARK_GREEN, Color.DARK_red);
# DIVERGENCE
input divergenceLength = 20; #hint divergenceLength: The number of bars used to calculate divergences.
input divergenceType = {default regular, reverse}; #hint divergenceType: The type of divergence. A regular divergence is when price is making higher highs (or lower lows), while the indicator is making lower highs (or higher lows). A reverse divergence (also called a hidden divergence) is when the indicator is making higher highs (or lower lows), while price is making lower highs (or higher lows).
#Hint: The output of this indicator is for informational and educational use only, is not an investment recommendation or advice, and should not be relied upon in making the decision to buy or sell a security or pursue a particular investment strategy.
def xDownBars;
def xUpBars;
def xDowns;
def xUps;
def hiBars;
def loBars;
def pivotTop;
def pivotBottom;
def hiInd;
def loInd;
def hiPrice;
def loPrice;
plot bearishd;
plot bullishd;
def K = Oscillator;
def Over_Boughta = upperinner;
def Over_Solda = lowerinner;
def ind;
ind = k;
# Bearish
pivotTop =
if
divergenceType == divergenceType.regular
then
ind[1] > over_Boughta and ind[1] == Highest(ind, divergenceLength + 1)
else
ind[1] >= 50 and
ind[1] == highest(ind, divergenceLength + 1) and
ind[1] == highest(ind, divergenceLength+1)[-divergenceLength+1];
if pivotTop
then {
hiBars = 1;
hiInd = ind[1];
hiPrice = max(high[2], max(high[1], high[0]));
}
else {
hiBars = hiBars[1] + 1;
hiInd = hiInd[1];
hiPrice = hiPrice[1];
}
if ind[1] crosses below Over_Boughta
then {
xDownBars = 1;
xDowns = xDowns[1] + 1;
}
else {
xDownBars = xDownBars[1] + 1;
xDowns = if pivotTop[1] then 0 else xDowns[1];
}
def bearCond;
switch (divergenceType) {
case regular:
bearCond =
ind[1] >= ZeroLine and
ind < ind[1] and
high[1] == Highest(high, divergenceLength + 1) and
hiBars[1] > xDownBars[1] and
xDowns == 1 and
close < close[1] and
hiPrice[1] < high[1] and
hiInd[1] > ind[1];
case reverse:
bearCond =
ind[1] >= ZeroLine and
ind < ind[1] and
# high[1] == Highest(high, divergenceLength) and
# hiBars[1] > xDownBars[1] and
# xDowns == 1 and
close < close[1] and
hiPrice[1] > high[1] and hiPrice[1] > high and
hiInd[1] < ind[1];}
bearishd =
if
bearCond
then
ind[1]
else
Double.NaN;;
bearishd.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bearishd.SetDefaultColor(Color.light_gray);
bearishd.setLineWeight(2);
bearishd.hideTitle();
bearishd.hideBubble();
def countBear = if bearCond[-1] then countBear[1] + 1 else countBear[1];
def recentBear = countBear == HighestAll(countBear);
def secHigh = highestAll(if bearCond[-1] and recentBear then ind else Double.NaN);
#def firstHigh = highestAll(if bearCond and recentBear and ind[1] == secHigh then hiInd[1] else double.NaN);
def FH_bar = highestAll(if recentBear and bearCond[-1] and ind == secHigh then getvalue(barNumber(), hibars) else double.NaN);
plot bearTrendline =
if
recentBear and bearCond[-1] and ind == secHigh
then
max(ind[1], ind[0])
else
# if pivotTop and hiInd == firstHigh
if
FH_bar == barNumber()
then
ind
else
double.NaN;
bearTrendline.EnableApproximation();
bearTrendline.setDefaultColor(color.RED);
bearTrendline.setLineWeight(4);
bearTrendline.hideBubble();
bearTrendline.hideTitle();
#Bullish
pivotBottom =
if
divergenceType == divergenceType.regular
then
ind[1] < over_Solda and ind[1] == lowest(ind, divergenceLength + 1)
else
ind[1] <= 50 and
ind[1] == lowest(ind, divergenceLength+1) and
ind[1] == lowest(ind, divergenceLength+1)[-divergenceLength+1];
if pivotBottom
then {
loBars = 1;
loInd = ind[1];
loPrice = min(low[2], min(low[1], low[0]));
}
else {
loBars = loBars[1] + 1;
loInd = loInd[1];
loPrice = loPrice[1];
}
if ind[1] crosses above over_Solda
then {
xUpBars = 1;
xUps = xUps[1] + 1;
}
else {
xUpBars = xUpBars[1] + 1;
xUps = if pivotBottom[1] then 0 else xUps[1];
}
def bullCond;
switch (divergenceType){
case regular:
bullCond =
ind[1] <= ZeroLine and
ind > ind[1] and
low[1] == Lowest(low, divergenceLength + 1) and
loBars[1] > xUpBars[1] and
xUps == 1 and
close > close[1] and
loPrice[1] > low[1] and
loInd[1] < ind[1];
case reverse:
bullCond =
ind[1] <= ZeroLine and
ind > ind[1] and
# low[1] == Lowest(low, divergenceLength) and
# loBars[1] > xUpBars[1] and
# xUps == 1 and
close > close[1] and
loPrice[1] < low[1] and loPrice[1] < low and
loInd[1] > ind[1];}
bullishd =
if
bullCond
then
ind[1]
else
Double.NaN;
bullishd.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bullishd.SetDefaultColor(Color.light_gray);
bullishd.setLineWeight(2);
bullishd.HideTitle();
bullishd.HideBubble();
def countBull = if bullCond[-1] then countBull[1] + 1 else countBull[1];
def recentBull = countBull == HighestAll(countBull);
def secLow = highestAll(if bullCond[-1] and recentBull then ind else Double.NaN);
#def firstLow = highestAll(if bullCond and recentBull and ind[1] == secLow then loInd[1] else double.NaN);
def FL_bar = highestAll(if recentBull and bullCond[-1] and ind == secLow then getvalue(barNumber(), lobars) else double.NaN);
plot bullTrendline =
if
recentBull and bullCond[-1] and ind == secLow
then
min(ind[1], ind[0])
else
if
# pivotBottom and loInd == firstLow
FL_bar == barNumber()
then
ind[0]
else
double.NaN;
bullTrendline.EnableApproximation();
bullTrendline.setDefaultColor(color.GREEN);
bullTrendline.setLineWeight(4);
bullTrendline.hideBubble();
bullTrendline.hideTitle();
#END CODE
MTF Version
Picture of the 5-min chart using 1-hour MTF.
Code:
# ------------------------------------------------------------
# MTF_Neural Probability Channel(NPC) [AlgoPoint]
# Original code found at https://www.tradingview.com/script/mFj3oD5h-Neural-Probability-Channel-AlgoPoint/
# Converted and enhanced by Chewie 2/8/2026
# ------------------------------------------------------------
declare upper;
# =========================
# INPUTS
# =========================
input colorbar = yes;
input htf = AggregationPeriod.HOUR;
input length = 24;
input h_param = 8.0;
input r_param = 2.0;
input mult_in = 0.65;
input mult_inner = 1.3;
input mult_mid = 1.95;
input mult_outer = 2.6;
# =========================
# COLORS
# =========================
DefineGlobalColor("Bear", CreateColor(242, 54, 69));
DefineGlobalColor("Bull", CreateColor(8, 153, 129));
# =========================
# HTF SOURCE
# =========================
def hHigh = high(period = htf);
def hLow = low(period = htf);
def hClose = close(period = htf);
def srcHTF = (hHigh + hLow + hClose) / 3;
# =========================
# HTF BAR DETECTION
# =========================
def newHTFBar = close(period = htf) != close(period = htf)[1];
# =========================
# KERNEL REGRESSION (HTF)
# =========================
def numHTF =
fold k1 = 0 to length
with acc1 = 0
do acc1 +
srcHTF[k1] *
Power(1 + Sqr(k1) / (2 * r_param * Sqr(h_param)), -r_param);
def denHTF =
fold k2 = 0 to length
with acc2 = 0
do acc2 +
Power(1 + Sqr(k2) / (2 * r_param * Sqr(h_param)), -r_param);
def yHatHTF_raw = numHTF / denHTF;
# =========================
# VOLATILITY (HTF)
# =========================
def errHTF =
fold k3 = 0 to length
with acc3 = 0
do acc3 + AbsValue(srcHTF[k3] - yHatHTF_raw);
def meanDevHTF = errHTF / length;
def trueRangeHTF =
TrueRange(
high(period = htf),
close(period = htf),
low(period = htf)
);
def atrHTF = Average(trueRangeHTF, length);
def volHTF_raw = (meanDevHTF + atrHTF) / 2;
# =========================
# BAR-GATED RECS
# =========================
rec y_hat =
if newHTFBar then yHatHTF_raw else y_hat[1];
rec volatility =
if newHTFBar then volHTF_raw else volatility[1];
# =========================
# CHANNELS
# =========================
def upperInner = y_hat + volatility * mult_inner;
def lowerInner = y_hat - volatility * mult_inner;
def upperOuter = y_hat + volatility * mult_outer;
def lowerOuter = y_hat - volatility * mult_outer;
def upperMid = y_hat + volatility * mult_mid;
def lowerMid = y_hat - volatility * mult_mid;
def upperIn = y_hat + volatility * mult_in;
def lowerIn = y_hat - volatility * mult_in;
# =========================
# TREND
# =========================
def upTrend = y_hat > y_hat[1];
# =========================
# PLOTS
# =========================
plot Baseline = y_hat;
Baseline.AssignValueColor(if upTrend then GlobalColor("Bull") else GlobalColor("Bear"));
Baseline.SetLineWeight(2);
plot UpperInnerPlot = upperInner;
UpperInnerPlot.SetDefaultColor(GlobalColor("Bear"));
plot LowerInnerPlot = lowerInner;
LowerInnerPlot.SetDefaultColor(GlobalColor("Bull"));
plot UpperOuterPlot = upperOuter;
UpperOuterPlot.SetDefaultColor(GlobalColor("Bear"));
UpperOuterPlot.SetLineWeight(2);
plot LowerOuterPlot = lowerOuter;
LowerOuterPlot.SetDefaultColor(GlobalColor("Bull"));
LowerOuterPlot.SetLineWeight(2);
plot UpperInPlot = upperIn;
UpperInPlot.SetDefaultColor(Color.DARK_GRAY);
plot LowerInPlot = lowerIn;
LowerInPlot.SetDefaultColor(Color.DARK_GRAY);
# =========================
# SIGNALS (LTF PRICE vs HTF CHANNEL)
# =========================
def buy =
low crosses above lowerOuter;
def sell =
high crosses below upperOuter;
plot BuySignal = if buy then low - ATR(60) / 2 else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.SetDefaultColor(Color.CYAN);
plot SellSignal = if sell then high + ATR(60) / 2 else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.SetDefaultColor(Color.MAGENTA);
# =========================
# CLOUDS
# =========================
AddCloud(lowerInner, lowerOuter, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(upperInner, upperOuter, Color.DARK_RED, Color.DARK_RED);
AddCloud(lowerMid, lowerOuter, GlobalColor("Bull"), GlobalColor("Bull"));
AddCloud(upperMid, upperOuter, GlobalColor("Bear"), GlobalColor("Bear"));
# =========================
# COLOR BARS (LTF)
# =========================
def bull = close > y_hat;
def bear = close < y_hat;
AssignPriceColor(
if !colorbar then Color.CURRENT
else if bull then GlobalColor("Bull")
else if bear then GlobalColor("Bear")
else Color.GRAY
);
Last edited: