# Recursive Least Squares Forecast

An adaptive linear regression that re-estimates its slope and intercept on every bar, plotting an equilibrium RLS Mean, volatility-adjusted bands, and a forward Ghost Line projection wrapped in standard-deviation forecast bands. Rules-based mean reversion signals included. For trend followers and mean reversion traders wanting low lag.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Feb 9, 2026.
- Access: free.
- Concepts: [Linear Regression](https://www.luxalgo.com/library/concept/linear-regression/) (primary), [Online/incremental Learning](https://www.luxalgo.com/library/concept/online-incremental-learning/)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=cmpwn557a0078vhsgilzrimfg
- Page: https://www.luxalgo.com/library/indicator/recursive-least-squares-forecast/

**Recursive Least Squares Forecast** fits an adaptive [linear regression](https://www.luxalgo.com/library/concept/linear-regression/) whose slope and intercept are re-estimated on every bar, plotting the result as an equilibrium RLS Mean with volatility-adjusted bands. A forward "Ghost Line" projects the current estimate ahead, wrapped in standard-deviation forecast bands that visualize the model's uncertainty, a low-lag alternative to static fits.

## How to Trade the Recursive Least Squares Forecast?

- **RLS Mean slope**: a rising mean with an upward Ghost Line frames bullish conditions; a declining structure signals bearish pressure.
- **Outer band excursion**: price beyond the Upper or Lower Band is statistically overextended for the current regime, the start of a mean-reversion setup.
- **BUY / SELL labels**: printed when price crosses back inside the band; the RLS Mean serves as the natural profit objective.
- **Forgetting Factor tuning**: values near 0.95 privilege recent action and pivot fast; values near 0.99 favor stability and smoothness.

The engine is an adaptive filter updated through a gain vector in a state-space framework, a form of [online, incremental learning](https://www.luxalgo.com/library/concept/online-incremental-learning/) that discounts older observations instead of refitting a fixed window. That is what lets it pivot quickly through regime shifts without excessive lag or noise.

## Recursive Least Squares Forecast Settings

- **Forgetting Factor (λ)**: how quickly older data is discounted. Higher is smoother and more stable, lower reacts faster to new prices.
- **Band Multiplier**: scales the forecast standard deviation that sets the band width.
- **Forecast Horizon**: how many bars ahead the Ghost Line and forecast bands project.
- **Show Ghost Line & Bands**: toggles the forward projection and uncertainty bands.
- **Show Mean Reversion Signals**: toggles the BUY and SELL labels.

## Frequently Asked Questions

### Does the Recursive Least Squares Forecast repaint?

The model updates in real time as each bar arrives, but historical values reflect only the information available at that time, so past plots remain consistent for study.

### How does it compare to other regression tools in the library?

A fixed-window regression refits from scratch and reacts late to regime changes; RLS updates incrementally with emphasis on recent data. For a nonparametric take on forecasting, [Machine Learning Gaussian Process Regression](https://www.luxalgo.com/library/indicator/machine-learning-gaussian-process-regression/) extrapolates through Gaussian processes rather than a recursively updated line.

### Where can I get this indicator?

It is free via the LuxAlgo Library, and from this page you can drop it into Quant, our coding agent, to test both its trend and mean-reversion sides. You can also copy the source code from this page and run it anywhere Pine Script® runs.

## Related indicators

- [Linear Regression Histogram](https://www.luxalgo.com/library/indicator/linear-regression-histogram/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/linear-regression-histogram.md
- [Linear Regression Fan](https://www.luxalgo.com/library/indicator/linear-regression-fan/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/linear-regression-fan.md
- [Periodic Linear Regressions](https://www.luxalgo.com/library/indicator/periodic-linear-regressions/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/periodic-linear-regressions.md
- [Rolling Segment](https://www.luxalgo.com/library/indicator/rolling-segment/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/rolling-segment.md
- [Rolling Trendline](https://www.luxalgo.com/library/indicator/rolling-trendline/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/rolling-trendline.md
- [Extrapolated Previous Trend](https://www.luxalgo.com/library/indicator/extrapolated-previous-trend/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/extrapolated-previous-trend.md
- [Bitcoin Power Law](https://www.luxalgo.com/library/indicator/bitcoin-power-law/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/bitcoin-power-law.md
- [Spline Quantile Regression Channel](https://www.luxalgo.com/library/indicator/spline-quantile-regression-channel/) (Polynomial Regression): markdown at https://www.luxalgo.com/library/indicator/spline-quantile-regression-channel.md

---

Source: https://www.luxalgo.com/library/indicator/recursive-least-squares-forecast/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
