This post includes both lower and upper chart.
The Regression Slope Oscillator is a trend–momentum tool that applies multiple linear regression slope calculations over different lookback ranges, then averages them into a single oscillator line. This design helps traders visualize when price is extending beyond typical regression behavior, as well as when momentum is shifting up or down.
Original Code: https://www.tradingview.com/script/5W4FYJfC-Regression-Slope-Oscillator-BigBeluga/
Color Gradient – The oscillator and candles are colored dynamically from oversold (orange) to overbought (aqua), based on slope extremes observed within the user–defined Color Range.
Trend Oscillation – When the oscillator rises, price trend is strengthening; when it falls, momentum weakens.
Signal Line (SMA) – A moving average of the slope oscillator used to identify momentum reversals.
Lower chart code:
Upper chart study with crossover dots.
The Regression Slope Oscillator is a trend–momentum tool that applies multiple linear regression slope calculations over different lookback ranges, then averages them into a single oscillator line. This design helps traders visualize when price is extending beyond typical regression behavior, as well as when momentum is shifting up or down.
Original Code: https://www.tradingview.com/script/5W4FYJfC-Regression-Slope-Oscillator-BigBeluga/
Color Gradient – The oscillator and candles are colored dynamically from oversold (orange) to overbought (aqua), based on slope extremes observed within the user–defined Color Range.
Trend Oscillation – When the oscillator rises, price trend is strengthening; when it falls, momentum weakens.
Signal Line (SMA) – A moving average of the slope oscillator used to identify momentum reversals.
- Bullish Reversal Signal – Triggered when the oscillator crosses above the signal line while below zero, indicating downside momentum exhaustion and potential trend recovery.
- Bearish Reversal Signal – Triggered when the oscillator crosses below the signal line while above zero, indicating upside momentum exhaustion and potential trend rollover.
- Confirmation Logic – Signals are only printed on confirmed bars to reduce repainting and false triggers.
- Watch the oscillator cross above/below zero: signals shifts in regression slope direction.
- Use the signal line crossovers near zero to identify early trend reversals.
- Use high Color Range settings to identify potential overbought/oversold extremes in trend slope.
- Use low Color Range settings for a faster, momentum–driven color change that tracks slope rising/falling.
- Candle coloring highlights short–term trend pressure in sync with the oscillator.
- Combine reversal signals with structure, support/resistance, or volume for higher–probability entries.
Lower chart code:
Code:
# Regression Slope Oscillator
# Converted by Chewie 2/15/2026
# Original code https://www.tradingview.com/script/5W4FYJfC-Regression-Slope-Oscillator-BigBeluga/
declare lower;
# -------------------------
# Inputs
# -------------------------
input minRange = 10;
input step = 5;
input samples = 6; # number of stepped regressions
input sigLine = 7;
# -------------------------
# Log Regression Script
# -------------------------
script LogSlope {
input length = 20;
def sumX = length * (length + 1) / 2;
def sumXSqr = length * (length + 1) * (2 * length + 1) / 6;
def logPrice = Log(close);
def sumY =
fold i = 0 to length
with s = 0
do s + GetValue(logPrice, i);
def sumXY =
fold j = 0 to length
with t = 0
do t + (j + 1) * GetValue(logPrice, j);
def slope =
(length * sumXY - sumX * sumY) /
(length * sumXSqr - sumX * sumX);
plot result = -slope;
}
# -------------------------
# Fixed Step Lengths
# -------------------------
def L1 = minRange;
def L2 = minRange + step;
def L3 = minRange + step * 2;
def L4 = minRange + step * 3;
def L5 = minRange + step * 4;
def L6 = minRange + step * 5;
def slopeOscillator =
( LogSlope(L1)
+ LogSlope(L2)
+ LogSlope(L3)
+ LogSlope(L4)
+ LogSlope(L5)
+ LogSlope(L6)
) / samples;
# -------------------------
# Signal
# -------------------------
def sigL = Average(slopeOscillator, sigLine);
def isBull = slopeOscillator >= 0;
# -------------------------
# Plots
# -------------------------
plot Osc = slopeOscillator;
Osc.SetLineWeight(2);
Osc.AssignValueColor(if isBull then Color.CYAN else Color.ORANGE);
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);
plot Signal = sigL;
Signal.SetDefaultColor(Color.WHITE);
AddCloud(
if isBull then Osc else Double.NaN,
ZeroLine,
Color.CYAN,
Color.CYAN
);
AddCloud(
if !isBull then Osc else Double.NaN,
ZeroLine,
Color.ORANGE,
Color.ORANGE
);
# -------------------------
# Reversal Signals
# -------------------------
def crossDown =
slopeOscillator crosses below sigL and slopeOscillator > 0;
def crossUp =
slopeOscillator crosses above sigL and slopeOscillator < 0;
plot RevDown =
if crossDown then slopeOscillator else Double.NaN;
RevDown.SetPaintingStrategy(PaintingStrategy.POINTS);
RevDown.SetDefaultColor(Color.WHITE);
RevDown.SetLineWeight(3);
plot RevUp =
if crossUp then slopeOscillator else Double.NaN;
RevUp.SetPaintingStrategy(PaintingStrategy.POINTS);
RevUp.SetDefaultColor(Color.WHITE);
RevUp.SetLineWeight(3);
AssignPriceColor(if isBull then Color.CYAN else Color.ORANGE);
Upper chart study with crossover dots.
Code:
# Regression Slope Oscillator
# Upper Chart Signal Version
# Assembled by Chewie 2/15/2026
declare upper;
# -------------------------
# Inputs
# -------------------------
input minRange = 10;
input step = 5;
input samples = 6;
input sigLine = 7;
# -------------------------
# Log Regression Slope Script
# -------------------------
script LogSlope {
input length = 20;
def sumX = length * (length + 1) / 2;
def sumXSqr = length * (length + 1) * (2 * length + 1) / 6;
def logPrice = Log(close);
def sumY =
fold i = 0 to length
with s = 0
do s + GetValue(logPrice, i);
def sumXY =
fold j = 0 to length
with t = 0
do t + (j + 1) * GetValue(logPrice, j);
def slope =
(length * sumXY - sumX * sumY) /
(length * sumXSqr - sumX * sumX);
plot result = -slope;
}
# -------------------------
# Fixed Step Lengths
# -------------------------
def L1 = minRange;
def L2 = minRange + step;
def L3 = minRange + step * 2;
def L4 = minRange + step * 3;
def L5 = minRange + step * 4;
def L6 = minRange + step * 5;
def slopeOscillator =
( LogSlope(L1)
+ LogSlope(L2)
+ LogSlope(L3)
+ LogSlope(L4)
+ LogSlope(L5)
+ LogSlope(L6)
) / samples;
# -------------------------
# Signal Line
# -------------------------
def sigL = Average(slopeOscillator, sigLine);
# -------------------------
# Cross Conditions
# -------------------------
def crossDown =
slopeOscillator crosses below sigL and slopeOscillator > 0;
def crossUp =
slopeOscillator crosses above sigL and slopeOscillator < 0;
# -------------------------
# Upper Chart Dots
# -------------------------
plot DownDot =
if crossDown then high + ATR(60) / 2 else Double.NaN;
DownDot.SetPaintingStrategy(PaintingStrategy.POINTS);
DownDot.SetDefaultColor(Color.WHITE);
DownDot.SetLineWeight(4);
plot UpDot =
if crossUp then low - ATR(60) / 2 else Double.NaN;
UpDot.SetPaintingStrategy(PaintingStrategy.POINTS);
UpDot.SetDefaultColor(Color.WHITE);
UpDot.SetLineWeight(4);