# R-squared Trend Fit

Regresses price on time across a 20-bar window and plots R-squared between 0 and 1, gated by a critical value derived from the significance test at 95% confidence: the fit must beat what random data would produce before a trend is declared. Slope supplies direction, a dashboard reports fit, threshold and regime, and five alerts cover gate flips, qualified trends and maturity warnings.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Jun 8, 2026.
- Access: free.
- Concepts: [R-squared Trend Fit](https://www.luxalgo.com/library/concept/r-squared-trend-fit/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=b0g08utqjn6zx3z5cytew4vu
- Page: https://www.luxalgo.com/library/indicator/r-squared-trend-fit/

**R-squared Trend Fit** scores how much of the lookback's price action a straight line explains, then refuses to call it a trend until the score beats luck, the first library build of the [R-squared trend fit](https://www.luxalgo.com/library/concept/r-squared-trend-fit/). Price is regressed against time over the lookback and the variance-explained reading plots between 0 and 1, colored by regime. In Statistical mode the gate's critical value comes from the significance test for the window length and confidence level, so short windows, which score high by chance, must clear a higher bar.

## How to Trade the R-squared Trend Fit?

- **Significant fit with a rising slope**: the regime turns Trending Up and the Clean Uptrend Qualified alert fires; the mirrored condition qualifies downtrends.
- **Reading below the critical value**: the window is statistically indistinguishable from noise, range conditions; both gate crossings are alerted.
- **Trend maturity warning**: consecutive falling readings after an extended significant stretch flag an aging trend, a decay symptom, explicitly not a reversal signal.

## R-squared Trend Fit Settings

- **Length** (default 20): the regression window.
- **Source** (default close).
- **Use Log Price** (default off): fits the logarithm for comparability across large moves.
- **Threshold Mode** (default Statistical) with **Confidence Level** (default 95%): the two-tailed t-test with n - 2 degrees of freedom sets the critical value.
- **Fixed Level** (default 0.25): the manual cutoff in Fixed mode.
- **Maturity: Bars In Trend** (default 10) and **Maturity: Falling Bars** (default 3): the warning's two streaks.
- Display: **Show Dashboard** (on), **Regime Background** (off), **Gradient Fill** (on).

## Frequently Asked Questions

### R-squared or ADX for trend strength?

The [Average Directional Index](https://www.luxalgo.com/library/indicator/average-directional-index/) accumulates smoothed directional movement, reading strength with deliberate lag and no natural significance level. R-squared is a bounded goodness-of-fit statistic with an explicit cutoff for randomness: more testable, and less forgiving when a trend curves.

### Why did a strong-looking trend read as No Trend?

Usually curvature: R-squared rewards straight-line progress, so a parabolic acceleration or a deep mid-window pullback explains less variance linearly and can fall below the critical value while direction persists. Direction comes from the slope, which the squaring discards.

### What does the critical value actually represent?

The R-squared level random data would exceed at the chosen confidence for that window length. The build maps the t-test cutoff for a correlation onto R-squared, matching the published tables. Readings below it are unremarkable however trendy the chart looks.

## Related indicators

- [Structure & Trend Dashboard](https://www.luxalgo.com/library/indicator/structure-trend-dashboard/) (Trend Regime Label): markdown at https://www.luxalgo.com/library/indicator/structure-trend-dashboard.md
- [Trending Market Toolkit](https://www.luxalgo.com/library/indicator/trending-market-toolkit/) (Trend Regime Label): markdown at https://www.luxalgo.com/library/indicator/trending-market-toolkit.md
- [Change-Point Detection (CUSUM)](https://www.luxalgo.com/library/indicator/change-point-detection-cusum/) (Trend Regime Label): markdown at https://www.luxalgo.com/library/indicator/change-point-detection-cusum.md
- [Correlation Trend Indicator](https://www.luxalgo.com/library/indicator/correlation-trend-indicator/) (Trend): markdown at https://www.luxalgo.com/library/indicator/correlation-trend-indicator.md
- [HyperTrend](https://www.luxalgo.com/library/indicator/hypertrend/) (Trend Regime Label): markdown at https://www.luxalgo.com/library/indicator/hypertrend.md
- [HTF Candle Consistency](https://www.luxalgo.com/library/indicator/htf-candle-consistency/) (Higher-timeframe Trend Filter): markdown at https://www.luxalgo.com/library/indicator/htf-candle-consistency.md
- [Average Directional Index](https://www.luxalgo.com/library/indicator/average-directional-index/) (ADX / DMI System): markdown at https://www.luxalgo.com/library/indicator/average-directional-index.md
- [Anchored Powered KAMA](https://www.luxalgo.com/library/indicator/anchored-powered-kama/) (Kaufman Efficiency Ratio): markdown at https://www.luxalgo.com/library/indicator/anchored-powered-kama.md

---

Source: https://www.luxalgo.com/library/indicator/r-squared-trend-fit/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
