MATHEMATICS & METHODS9 min read10 March 2026

Kalman Filter in Trading: How to Eliminate Market Noise from Your Charts

Developed by Rudolf Kálmán for NASA's Apollo program, the Kalman filter is arguably the most mathematically sophisticated noise-reduction tool available to traders. Here's how it works and why it outperforms moving averages for signal clarity.

Kalman FilterNoise ReductionTradingViewPine ScriptSignal Processing
TABLE OF CONTENTS
  1. From Apollo to TradingView: The Kalman Filter's Origins
  2. How the Kalman Filter Works: The Core Mechanics
  3. The Q and R Parameters: Tuning the Filter
  4. Kalman Filter vs Moving Averages: A Direct Comparison
  5. Using Kalman Velocity for Signal Generation
  6. Implementing Kalman Filter in Pine Script v6
  7. Frequently Asked Questions

From Apollo to TradingView: The Kalman Filter's Origins

The Kalman filter was introduced by Hungarian-American engineer Rudolf Kálmán in 1960 and was immediately adopted by NASA for the Apollo navigation system. Its job: estimate the true position and velocity of the spacecraft based on noisy sensor measurements.

The filter solves a fundamental problem — how do you extract the genuine signal from a stream of measurements that are corrupted by random noise? It does so by maintaining an estimate of the current state and updating that estimate with each new measurement, weighted by a confidence factor (the Kalman gain) that balances trust in the model versus trust in the measurement.

Financial price series face exactly the same problem: the 'true' price trend exists beneath layers of noise generated by market microstructure. The Kalman filter's mathematical framework translates directly to this domain.

How the Kalman Filter Works: The Core Mechanics

The standard Kalman filter maintains two quantities: a state estimate (in trading: the filtered price and its velocity) and an error covariance (a measure of uncertainty in the estimate). At each new price observation, it performs two steps:

  • Predict: Project the current state estimate forward one step using the state transition model. In price terms: new estimated price = last filtered price + last estimated velocity.
  • Update: Incorporate the new observation (the actual close price) to correct the prediction. The degree of correction is governed by the Kalman gain K = P / (P + R), where P is the prediction uncertainty and R is the measurement noise parameter.

The Q and R Parameters: Tuning the Filter

The two tunable parameters — Q (process noise) and R (measurement noise) — determine the filter's behaviour:

Q controls how much the filter trusts its own model versus new data. A higher Q makes the filter more responsive (less lag, more noise). A lower Q makes it more stable (more lag, less noise).

R controls how much noise is assumed in the measurements. A higher R makes the filter treat observations as noisier and rely more on its own model.

The ratio Q/R is what effectively determines the Kalman gain. For trading applications on 30M Gold (XAUUSD), typical values are Q = 0.001–0.01 and R = 0.1–1.0. Highly volatile instruments like crypto benefit from higher Q values to maintain responsiveness.

TIP

An adaptive Kalman filter — one that adjusts Q dynamically based on recent price volatility (ATR) — outperforms fixed-parameter implementations across different market conditions. This is the approach used in Quantum DeCasteljau.

Kalman Filter vs Moving Averages: A Direct Comparison

Both the Kalman filter and moving averages attempt to smooth price data, but they differ fundamentally in how they handle noise and lag:

  • Lag: A 20-period SMA introduces ~10 bars of lag. The Kalman filter's lag is adaptive — it reduces lag when the filter is confident in the trend direction, and increases stability when uncertainty is high.
  • Noise response: SMAs weight all observations equally; EMAs weight recent observations more. Neither distinguishes between a genuine price move and random noise. The Kalman filter explicitly models noise and downweights observations it classifies as anomalous.
  • Velocity tracking: The Kalman filter maintains an internal velocity estimate (rate of price change), which is not available from a moving average. This velocity can be used to predict where the next bar is likely to open — providing a forward-looking component absent from traditional averages.
  • Parameter adaptivity: A moving average's behaviour is fixed by its period. An adaptive Kalman filter can tighten or loosen its responsiveness in real time based on recent ATR, making it more robust across volatile and quiet market phases.

Using Kalman Velocity for Signal Generation

Beyond noise reduction, the Kalman filter's velocity estimate provides a directly tradeable signal. Positive velocity indicates the filter's model 'believes' price is moving upward; negative velocity indicates a downward trend in the filtered price series.

Crossings of the velocity through zero — from negative to positive or vice versa — correspond to the Kalman filter's assessment of a trend reversal in the smoothed price. These signals lag real-time reversals but are dramatically less prone to false triggering than raw price crossings.

In Quantum DeCasteljau, the Kalman velocity is fed as one of eight inputs to the ML ensemble, contributing to the overall signal score rather than being used as a standalone trigger. This avoids the risk of acting on a velocity signal that is contradicted by other models.

Implementing Kalman Filter in Pine Script v6

The core Kalman filter update cycle in Pine Script v6 requires two `var` variables to persist state across bars: the filtered price estimate and the prediction error covariance. On each bar, the predict step projects the estimate forward, and the update step incorporates the new close price.

Key implementation notes for Pine Script: avoid recalculating the entire filter history on every bar (use `var` declarations). Ensure the filter only updates on `barstate.isconfirmed` if it feeds into non-repainting signals. The Q and R parameters should be user-configurable inputs to allow tuning for different instruments and timeframes.

Frequently Asked Questions

What is a Kalman filter in trading?

A Kalman filter in trading is a recursive algorithm that estimates the 'true' price trend by separating genuine price movement from random noise. It works by maintaining a state estimate (filtered price and velocity) and updating it with each new observation, weighted by a confidence factor. It produces cleaner trend signals with less lag than moving averages.

Is the Kalman filter better than a moving average?

For noise reduction purposes, the Kalman filter generally outperforms fixed-period moving averages because it adaptively balances responsiveness and stability based on recent price behaviour. It also produces a velocity estimate not available from moving averages. However, it requires parameter tuning (Q and R values) that moving averages do not.

What are the Q and R parameters in a Kalman filter for trading?

Q is the process noise parameter, controlling how much the filter trusts its internal model versus new data. R is the measurement noise parameter, representing assumed noise in price observations. A higher Q/R ratio makes the filter more responsive but noisier; a lower ratio makes it smoother with more lag.

SEE IT IN ACTION

Every method in this article is live in Quantum DeCasteljau v10.7 PRO ML

De Casteljau projection, Kalman filter, Hurst Exponent, 8-model ML ensemble — all running in a single Pine Script v6 indicator.

View Indicator →
MORE ARTICLES
TRADINGVIEW GUIDES

Non-Repainting TradingView Indicators: The Complete Guide (2026)

Read →
MARKET GUIDES

Best TradingView Indicators for Gold (XAUUSD) in 2026

Read →
MATHEMATICS & METHODS

The De Casteljau Algorithm in Trading: Bézier Curves for Price Projection

Read →