OPEN-SOURCE SCRIPT
Regression Channel (ShareScope-style, parallel)

What it does
Replicates ShareScope’s Trend of displayed data look: a single straight linear-regression line (dashed) across a chosen window with parallel, constant-width bands above and below, plus optional shading.
Use it to see the overall trend gradient for a period and a statistically sized channel based on the fit’s residual error.
How it works (math, short)
Computes an OLS regression once over the analysis window.
Residual standard error s is derived from SSE and degrees of freedom (n−2).
Band half-width is constant across the window:
Mean CI (narrower): half = z * s / √n
Prediction (wider): half = z * s * √(1 + 1/n)
Three straight, parallel lines are drawn from the regression endpoints; midline is dashed.
This is intentionally not a tapered CI (which widens at the ends). It matches the visual behaviour of ShareScope’s shaded trend line channel.
Inputs
Source – Price series (Close, High, Low, HL2, etc.).
Use last N bars / N (bars) – Rolling window length.
From / To (date mode) – Alternative fixed date window.
Confidence (%) – 90 / 95 / 99 / Custom (uses z≈t).
Custom Z (t) – Override the quantile if desired.
Prediction bands – Use wider prediction envelope instead of mean CI.
Shade region + colors / opacity / line width.
Usage
To mimic ShareScope exactly, pick the same date span (use date mode) and set Confidence 99%.
Choose Prediction OFF for a tighter “confidence” look; ON for a wider, more permissive channel.
If ShareScope used High as source, set Source = High here as well.
Notes & limitations
TradingView does not expose the visible viewport to Pine. The script cannot auto-read “displayed data.” Use last N bars or date range.
Bands are parallel by design. Prices may close outside; the channel does not bend.
Window capped at 5,000 bars for performance. No alerts are emitted.
Differences vs TV’s native tools
Linear Regression (drawing) – manual object; no statistical sizing or shading.
Linear Regression Channel (indicator) – uses price standard deviations around the regression; width is a user stdev multiple.
This script – uses residual error of the OLS fit and a z/t quantile to size a statistically meaningful parallel channel.
Changelog
r3.1 – Guard fix (no return at top level), minor refactor, stable line updates.
r3 – Switched to single-fit OLS with parallel constant-width bands (ShareScope look).
(Earlier experimental builds r1–r2.2 implemented rolling/tapered CI; superseded.)
Disclaimer: Educational use only. Not investment advice.
Replicates ShareScope’s Trend of displayed data look: a single straight linear-regression line (dashed) across a chosen window with parallel, constant-width bands above and below, plus optional shading.
Use it to see the overall trend gradient for a period and a statistically sized channel based on the fit’s residual error.
How it works (math, short)
Computes an OLS regression once over the analysis window.
Residual standard error s is derived from SSE and degrees of freedom (n−2).
Band half-width is constant across the window:
Mean CI (narrower): half = z * s / √n
Prediction (wider): half = z * s * √(1 + 1/n)
Three straight, parallel lines are drawn from the regression endpoints; midline is dashed.
This is intentionally not a tapered CI (which widens at the ends). It matches the visual behaviour of ShareScope’s shaded trend line channel.
Inputs
Source – Price series (Close, High, Low, HL2, etc.).
Use last N bars / N (bars) – Rolling window length.
From / To (date mode) – Alternative fixed date window.
Confidence (%) – 90 / 95 / 99 / Custom (uses z≈t).
Custom Z (t) – Override the quantile if desired.
Prediction bands – Use wider prediction envelope instead of mean CI.
Shade region + colors / opacity / line width.
Usage
To mimic ShareScope exactly, pick the same date span (use date mode) and set Confidence 99%.
Choose Prediction OFF for a tighter “confidence” look; ON for a wider, more permissive channel.
If ShareScope used High as source, set Source = High here as well.
Notes & limitations
TradingView does not expose the visible viewport to Pine. The script cannot auto-read “displayed data.” Use last N bars or date range.
Bands are parallel by design. Prices may close outside; the channel does not bend.
Window capped at 5,000 bars for performance. No alerts are emitted.
Differences vs TV’s native tools
Linear Regression (drawing) – manual object; no statistical sizing or shading.
Linear Regression Channel (indicator) – uses price standard deviations around the regression; width is a user stdev multiple.
This script – uses residual error of the OLS fit and a z/t quantile to size a statistically meaningful parallel channel.
Changelog
r3.1 – Guard fix (no return at top level), minor refactor, stable line updates.
r3 – Switched to single-fit OLS with parallel constant-width bands (ShareScope look).
(Earlier experimental builds r1–r2.2 implemented rolling/tapered CI; superseded.)
Disclaimer: Educational use only. Not investment advice.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.