# Kalman Filter

Kalman Filter is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

Kalman Filter runs the classic predict-and-update recursion on price, plotting an adaptive estimate whose responsiveness comes from Process Noise (Q, default 0.01) and Measurement Noise (R, default 1) rather than a length. A slope-colored line, price/filter gradient fill and crossing alerts give trend traders a moving-average-style read tuned by noise assumptions.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Apr 24, 2026.
- Access: free.
- Concepts: [Kalman Filter](https://www.luxalgo.com/library/concept/kalman-filter/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=qmr0gkamql72vf3zj9eh29cw
- Page: https://www.luxalgo.com/library/indicator/kalman-filter/

**Kalman Filter** brings the [Kalman filter](https://www.luxalgo.com/library/concept/kalman-filter/) to the chart as a clean single-line adaptive smoother: every bar the estimate is carried forward, its uncertainty widened by the process noise, and the prediction pulled toward the new price by the Kalman gain. The line colors by its slope, a gradient fill spans price and filter, and the live gain is readable in the data window. The recursion is causal on purpose - each bar's estimate is formed without peeking forward, so printed values never repaint.

## How to Trade the Kalman Filter?

- **Price crossing the filter**: read exactly like moving-average crossovers, with responsiveness set by the noise model instead of a bar count; optional markers, alerts either way.
- **Slope color flip**: bullish while the filtered level rises, bearish while it falls, with dedicated slope-turn alerts.
- **Gradient fill**: price holding above the estimate frames it as a trailing reference that pullbacks keep testing.

Watching the Kalman Gain readout while adjusting settings is the fastest way to learn the tool - it is the live smoothness-versus-lag consequence of your Q/R choice.

## Kalman Filter Settings

- **Source** (default close): the measurement fed to the filter; feeding a noisy indicator series instead covers the pre-processing use.
- **Process Noise (Q)** (default 0.01): how strongly the level itself is assumed to wander per bar. Raising it lifts the gain so the line hugs price; lowering it smooths at the cost of lag.
- **Measurement Noise (R)** (default 1): how noisy each print is assumed to be. Raising it flattens the line so it rides out chop.
- **Slope Trend Coloring** (default on): direction-colored line; disable for the neutral color.
- **Price / Filter Gradient Fill** (default on) and **Price Crossing Markers** (default off): display toggles - crossing alerts work regardless.

## Frequently Asked Questions

### How does this differ from a moving average?

A [moving average](https://www.luxalgo.com/library/indicator/moving-average/) applies fixed weights across a fixed window; the filter recursively blends its own prediction with each observation, recomputing the weight every bar from the noise model. At the defaults it settles near a 20-bar EMA's responsiveness, but tuning happens through noise assumptions rather than a length.

### What do Q and R actually control?

Q says how far the true level may drift per bar, R says how untrustworthy each print is, and in steady state only their ratio matters. A common workflow keeps R fixed at 1 and tunes Q alone as a single smoothness knob.

### Does the filter repaint?

No. The predict/update loop runs on information available at each bar, and the seed values only affect early history - the gain settles into the same steady state wherever it starts.

## Related indicators

- [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
- [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
- [Recursive Least Squares Forecast](https://www.luxalgo.com/library/indicator/recursive-least-squares-forecast/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/recursive-least-squares-forecast.md
- [Adaptive Harmonic Forecast](https://www.luxalgo.com/library/indicator/adaptive-harmonic-forecast/) (FFT/spectral Analysis): markdown at https://www.luxalgo.com/library/indicator/adaptive-harmonic-forecast.md
- [Bitcoin Expectile Model](https://www.luxalgo.com/library/indicator/bitcoin-expectile-model/) (Quantile Regression): markdown at https://www.luxalgo.com/library/indicator/bitcoin-expectile-model.md
- [Rolling Segment](https://www.luxalgo.com/library/indicator/rolling-segment/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/rolling-segment.md
- [Daily Polynomial Regressions](https://www.luxalgo.com/library/indicator/daily-polynomial-regressions/) (Polynomial Regression): markdown at https://www.luxalgo.com/library/indicator/daily-polynomial-regressions.md
- [Rolling Trendline](https://www.luxalgo.com/library/indicator/rolling-trendline/) (Linear Regression): markdown at https://www.luxalgo.com/library/indicator/rolling-trendline.md

---

Source: https://www.luxalgo.com/library/indicator/kalman-filter/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
