OPEN-SOURCE SCRIPT
Regression Slope Oscillator [QuantAlgo]

🟢 Overview
The Regression Slope Oscillator measures the rate of directional change in price using a robust regression estimator that resists outliers, then converts that slope into a scale free reading so a single threshold carries the same meaning across instruments and timeframes. Rather than fitting a least squares line, which a single spike or gap can pull off course, it takes the median of pairwise slopes inside a rolling window to produce a trend estimate that holds up through erratic data. A three state engine with separate entry and exit thresholds then translates the normalized slope into a bullish, bearish, or neutral regime, holding established states through pullbacks instead of flickering whenever the reading brushes the boundary.

🟢 How It Works
The indicator's core methodology lies in its combination of outlier resistant slope estimation and volatility relative normalization, where a trend regime is only established once the fitted rate of change clears a threshold expressed in units of the instrument's own volatility.
First, the source is optionally moved into log space so the fitted slope becomes a proportional rate of change rather than an absolute one, keeping readings comparable across instruments at very different price levels and across histories where price has moved by an order of magnitude:
Pine Script®
Then the slope is fitted across the window using a robust estimator rather than ordinary least squares, which has an effective breakdown point of zero and lets a single gap or liquidation wick tilt the fit for the entire window. Theil-Sen takes the median of every pairwise slope inside the window, tolerating roughly 29 percent contaminated data while staying close to a least squares fit on clean data:
Pine Script®
Repeated Median nests the same idea, taking a median of pairwise slopes anchored on each bar and then a median of those results, which lifts the breakdown point to 50 percent, the theoretical maximum, at several times the computational cost. Both estimators target the same underlying quantity, so switching between them changes robustness without shifting the scale.
The raw slope is then divided by a volatility unit to strip out the instrument's price scale and volatility regime, producing a reading that means the same thing on any chart:
Pine Script®
Each path is dimensionally self consistent with the log transform, so numerator and denominator always move together and the resulting reading stays dimensionless. In ATR mode a value of 0.10 means the trend is advancing at one tenth of an average true range per bar.
The normalized slope then drives a state engine where the level required to establish a regime and the level required to release it are deliberately different, creating a hysteresis band that suppresses boundary flicker:
Pine Script®
Finally, in Candles display mode the estimator runs two additional passes against the chart high and the chart low, building a synthetic OHLC series in slope space where the body spans the change in slope and the wicks reveal how far trend disperses across the bar range, with an optional Heikin-Ashi transform applied on top:
Pine Script®

🟢 Signal Interpretation
▶ Bullish State (Oscillator Above the Upper Entry Band with Bullish Color)
The normalized slope has cleared the positive entry threshold, meaning price is advancing faster than the instrument's own recent volatility rather than simply drifting higher. Trend traders take the confirmation as a long entry and hold through pullbacks, since the state only releases once the slope retreats below the exit level rather than on every minor pause, and a reading that climbs deeper into the upper zones represents strengthening rather than a reason to exit. Mean reversion traders read the same plot for depth instead of direction. A reading sitting in the first zone is an ordinary trend and offers nothing to fade, but a push into the second or third upper zone means price is rising at two or three times the rate required for confirmation, which is statistically unusual and marks the region where an advance is most likely to decelerate and revert toward the band. The trigger for a fade is the turn back down out of the outer zone rather than arrival in it, because a steep slope can hold for a surprisingly long stretch in a genuine trend.
▶ Bearish State (Oscillator Below the Lower Entry Band with Bearish Color)
The normalized slope has cleared the negative entry threshold, confirming that price is declining at a rate meaningful relative to its own volatility. Trend traders use this for short entries or long exits and keep directional bias through corrective bounces that fail to reverse the underlying rate of change. Mean reversion traders again work from zone depth, treating a reading in the lower second or third zone as an accelerated decline that is stretched far enough for a bounce back toward the band to carry a favorable expected move. In either direction, a slope that decays back toward the entry band while price continues in the trend direction is an early rate of change divergence, giving mean reversion traders advance notice of exhaustion and trend traders a reason to tighten stops before the state formally releases.
▶ Neutral State (Oscillator Inside the Threshold Band with Neutral Color)
The oscillator has released into neutral, either because an established regime decayed back through its exit level or because the slope never cleared entry to begin with. This reading carries the same meaning for both styles, since price is neither trending quickly enough to follow nor stretched far enough to fade. Trend traders stand aside and watch for the compression that frequently precedes the next confirmed regime, while mean reversion traders treat the return into the band as a completed reversion and the natural place to close a fade, the move having exhausted itself by definition once the slope no longer clears the threshold.

🟢 Features
▶ Preconfigured Presets: Three optimized parameter sets tailored to different trading styles and timeframes, each configuring the slope window, normalization length, entry threshold, exit fraction, and normalization method together so the threshold always stays matched to the units it is measured in. "Default" balances noise filtering against responsiveness for swing trading on 4-hour and daily charts. "Fast Response" shortens the window and lowers the entry threshold to engage regimes early for intraday use on 5-minute to 1-hour charts, while a raised exit fraction releases them quickly. "Smooth Trend" lengthens the window and raises the entry threshold to produce few, high conviction regimes held through deep pullbacks, suited to position trading on daily and weekly charts.

▶ Built-in Alerts: Six alert conditions plus a dynamic alert message enable automated monitoring of regime transitions without constant chart observation. "Bullish State" and "Bearish State" trigger on first confirmation of a directional regime, "Neutral State" fires when a directional regime is released, and "Any State Change" provides a combined alert covering all transitions through a single setup. "Bullish Zero Cross" and "Bearish Zero Cross" track the moment the slope changes sign, offering an earlier and more sensitive trigger than threshold confirmation.

▶ Visual Customization: A Candles or Line display toggle switches between the full synthetic slope candle series and a single plotted value for a lighter, cleaner presentation. In Candles mode, an optional Heikin-Ashi transform makes sustained trend phases visually contiguous, and hollow up candles layer bar direction on top of the regime color so momentum inside a state can be read at a glance, for example a filled bar within a bullish phase indicating the slope eased on that bar. Graduated threshold zones fill at one, two, and three multiples of the entry threshold at progressively increasing transparency, giving an immediate sense of how far beyond confirmation the current reading sits.

Six color presets (Classic, Aqua, Cosmic, Cyber, Neon, plus Custom) accommodate different chart themes with coordinated bullish and bearish schemes applied consistently across every element.

The Regression Slope Oscillator measures the rate of directional change in price using a robust regression estimator that resists outliers, then converts that slope into a scale free reading so a single threshold carries the same meaning across instruments and timeframes. Rather than fitting a least squares line, which a single spike or gap can pull off course, it takes the median of pairwise slopes inside a rolling window to produce a trend estimate that holds up through erratic data. A three state engine with separate entry and exit thresholds then translates the normalized slope into a bullish, bearish, or neutral regime, holding established states through pullbacks instead of flickering whenever the reading brushes the boundary.
🟢 How It Works
The indicator's core methodology lies in its combination of outlier resistant slope estimation and volatility relative normalization, where a trend regime is only established once the fitted rate of change clears a threshold expressed in units of the instrument's own volatility.
First, the source is optionally moved into log space so the fitted slope becomes a proportional rate of change rather than an absolute one, keeping readings comparable across instruments at very different price levels and across histories where price has moved by an order of magnitude:
Then the slope is fitted across the window using a robust estimator rather than ordinary least squares, which has an effective breakdown point of zero and lets a single gap or liquidation wick tilt the fit for the entire window. Theil-Sen takes the median of every pairwise slope inside the window, tolerating roughly 29 percent contaminated data while staying close to a least squares fit on clean data:
Repeated Median nests the same idea, taking a median of pairwise slopes anchored on each bar and then a median of those results, which lifts the breakdown point to 50 percent, the theoretical maximum, at several times the computational cost. Both estimators target the same underlying quantity, so switching between them changes robustness without shifting the scale.
The raw slope is then divided by a volatility unit to strip out the instrument's price scale and volatility regime, producing a reading that means the same thing on any chart:
Each path is dimensionally self consistent with the log transform, so numerator and denominator always move together and the resulting reading stays dimensionless. In ATR mode a value of 0.10 means the trend is advancing at one tenth of an average true range per bar.
The normalized slope then drives a state engine where the level required to establish a regime and the level required to release it are deliberately different, creating a hysteresis band that suppresses boundary flicker:
Finally, in Candles display mode the estimator runs two additional passes against the chart high and the chart low, building a synthetic OHLC series in slope space where the body spans the change in slope and the wicks reveal how far trend disperses across the bar range, with an optional Heikin-Ashi transform applied on top:
🟢 Signal Interpretation
▶ Bullish State (Oscillator Above the Upper Entry Band with Bullish Color)
The normalized slope has cleared the positive entry threshold, meaning price is advancing faster than the instrument's own recent volatility rather than simply drifting higher. Trend traders take the confirmation as a long entry and hold through pullbacks, since the state only releases once the slope retreats below the exit level rather than on every minor pause, and a reading that climbs deeper into the upper zones represents strengthening rather than a reason to exit. Mean reversion traders read the same plot for depth instead of direction. A reading sitting in the first zone is an ordinary trend and offers nothing to fade, but a push into the second or third upper zone means price is rising at two or three times the rate required for confirmation, which is statistically unusual and marks the region where an advance is most likely to decelerate and revert toward the band. The trigger for a fade is the turn back down out of the outer zone rather than arrival in it, because a steep slope can hold for a surprisingly long stretch in a genuine trend.
▶ Bearish State (Oscillator Below the Lower Entry Band with Bearish Color)
The normalized slope has cleared the negative entry threshold, confirming that price is declining at a rate meaningful relative to its own volatility. Trend traders use this for short entries or long exits and keep directional bias through corrective bounces that fail to reverse the underlying rate of change. Mean reversion traders again work from zone depth, treating a reading in the lower second or third zone as an accelerated decline that is stretched far enough for a bounce back toward the band to carry a favorable expected move. In either direction, a slope that decays back toward the entry band while price continues in the trend direction is an early rate of change divergence, giving mean reversion traders advance notice of exhaustion and trend traders a reason to tighten stops before the state formally releases.
▶ Neutral State (Oscillator Inside the Threshold Band with Neutral Color)
The oscillator has released into neutral, either because an established regime decayed back through its exit level or because the slope never cleared entry to begin with. This reading carries the same meaning for both styles, since price is neither trending quickly enough to follow nor stretched far enough to fade. Trend traders stand aside and watch for the compression that frequently precedes the next confirmed regime, while mean reversion traders treat the return into the band as a completed reversion and the natural place to close a fade, the move having exhausted itself by definition once the slope no longer clears the threshold.
🟢 Features
▶ Preconfigured Presets: Three optimized parameter sets tailored to different trading styles and timeframes, each configuring the slope window, normalization length, entry threshold, exit fraction, and normalization method together so the threshold always stays matched to the units it is measured in. "Default" balances noise filtering against responsiveness for swing trading on 4-hour and daily charts. "Fast Response" shortens the window and lowers the entry threshold to engage regimes early for intraday use on 5-minute to 1-hour charts, while a raised exit fraction releases them quickly. "Smooth Trend" lengthens the window and raises the entry threshold to produce few, high conviction regimes held through deep pullbacks, suited to position trading on daily and weekly charts.
▶ Built-in Alerts: Six alert conditions plus a dynamic alert message enable automated monitoring of regime transitions without constant chart observation. "Bullish State" and "Bearish State" trigger on first confirmation of a directional regime, "Neutral State" fires when a directional regime is released, and "Any State Change" provides a combined alert covering all transitions through a single setup. "Bullish Zero Cross" and "Bearish Zero Cross" track the moment the slope changes sign, offering an earlier and more sensitive trigger than threshold confirmation.
▶ Visual Customization: A Candles or Line display toggle switches between the full synthetic slope candle series and a single plotted value for a lighter, cleaner presentation. In Candles mode, an optional Heikin-Ashi transform makes sustained trend phases visually contiguous, and hollow up candles layer bar direction on top of the regime color so momentum inside a state can be read at a glance, for example a filled bar within a bullish phase indicating the slope eased on that bar. Graduated threshold zones fill at one, two, and three multiples of the entry threshold at progressively increasing transparency, giving an immediate sense of how far beyond confirmation the current reading sits.
Six color presets (Classic, Aqua, Cosmic, Cyber, Neon, plus Custom) accommodate different chart themes with coordinated bullish and bearish schemes applied consistently across every element.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🟢 Access our best trading & investing tools: joinquantalgo.com/plans
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🟢 Access our best trading & investing tools: joinquantalgo.com/plans
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
🟢 Free Special Edition indicators: joinquantalgo.com/special-editions
🟢 Discord: discord.gg/hJaFyGEAyX
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.