indicator · own pane · open source

Linear Regression R-Squared indicator

Linear Regression R-Squared is a free open-source indicator by @deepwick. Linear Regression R-Squared measures how well price fits a straight line on a 0-1 scale. Deepwick Script runs a subset of Pine Script.

Deepwick · @deepwickv1Updated 3 Nov 2026▲ 0 users
Running…
Loading chart…

What Linear Regression R-Squared does

Linear Regression R-Squared measures how well price fits a straight line on a 0-1 scale. Above 0.7 = price is trending cleanly; below 0.5 = noise dominates.

  • Use as a trend-strength filter for any regression-based signal.
  • Drops below 0.5 during chop and during the early bars of a new trend — be wary.
  • Sustained readings above 0.7 are when trend systems make their money.

Source code

Deepwick Script, a subset of Pine Script · read-only

//@version=6
indicator("Linear Regression R-Squared", overlay=false)
len = input.int(14, "Length", minval=2, maxval=200)
colorMid2 = input.color("color.teal", "Color  Mid2")
colorNeutral = input.color("color.gray", "Color  Neutral")
colorUp = input.color("color.green", "Color  Up")
lrVal = ta.linreg(close, len, 0)
slope = lrVal - lrVal[1]
mean = ta.sma(close, len)
ssRes = math.sum(math.pow(close - (lrVal + slope * (bar_index - bar_index[len])), 2), len)
ssTot = math.sum(math.pow(close - mean, 2), len)
r2 = 1 - ssRes / ssTot
hline(0.5, "Noise floor", color=colorNeutral, linestyle=hline.style_dashed)
hline(0.7, "Trending", color=colorUp, linestyle=hline.style_dashed)
p_R2 = plot(r2, "R2", color=colorMid2, linewidth=2)
alertcondition(ta.crossover(r2, 0.7), "R2 enters trending", "R-squared crossed above 0.7 — trend is clean")
alertcondition(ta.crossunder(r2, 0.5), "R2 exits trending", "R-squared dropped below 0.5 — trend is messy")

Comments

No comments yet.

Sign in to comment.