Regression Slope Oscillator [BigBeluga] for ThinkorSwim

chewie76

Well-known member
VIP
VIP Enthusiast
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.
  • 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.
HOW TO USE
  • 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.
1771202003038.png


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);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1200 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top