OPEN-SOURCE SCRIPT

Regression Channel (ShareScope-style, parallel)

37
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.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.