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.
Script open-source
Dans l'esprit de TradingView, le créateur de ce script l'a rendu open-source, afin que les traders puissent examiner et vérifier sa fonctionnalité. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit de TradingView, le créateur de ce script l'a rendu open-source, afin que les traders puissent examiner et vérifier sa fonctionnalité. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.