OPEN-SOURCE SCRIPT
Updated Kalman Filter

Kalman Filter Indicator Description
This indicator applies a Kalman Filter to smooth the selected price series (default is the close) and help reveal the underlying trend by filtering out market noise. The filter is based on a recursive algorithm consisting of two main steps:
Prediction Step:
The filter predicts the next state using the last estimated value and increases the uncertainty (error covariance) by adding the process noise variance (Q). This step assumes that the price follows a random walk, where the last known estimate is the best guess for the next value.
Update Step:
The filter computes the Kalman Gain, which determines the weight given to the new measurement (price) versus the prediction. It then updates the state estimate by combining the prediction with the measurement error (using the measurement noise variance, R). The error covariance is also updated accordingly.
Key Features:
Customizable Input:
Visual Trend Indication:
The filtered trend line is plotted directly on the chart:
When enabled, the line is colored green when trending upward and red when trending downward.
If color option is disabled, the line appears in blue.
This indicator is ideal for traders looking to smooth price data and identify trends more clearly by reducing the impact of short-term volatility.
This indicator applies a Kalman Filter to smooth the selected price series (default is the close) and help reveal the underlying trend by filtering out market noise. The filter is based on a recursive algorithm consisting of two main steps:
Prediction Step:
The filter predicts the next state using the last estimated value and increases the uncertainty (error covariance) by adding the process noise variance (Q). This step assumes that the price follows a random walk, where the last known estimate is the best guess for the next value.
Update Step:
The filter computes the Kalman Gain, which determines the weight given to the new measurement (price) versus the prediction. It then updates the state estimate by combining the prediction with the measurement error (using the measurement noise variance, R). The error covariance is also updated accordingly.
Key Features:
Customizable Input:
- Source: Choose any price series (default is the closing price) for filtering.
- Measurement Noise Variance (R): Controls the sensitivity to new measurements (default is 0.1). A higher R makes the filter less responsive.
- Process Noise Variance (Q): Controls the assumed level of inherent price variability (default is 0.01). A higher Q allows the filter to adapt more quickly to changes.
Visual Trend Indication:
The filtered trend line is plotted directly on the chart:
When enabled, the line is colored green when trending upward and red when trending downward.
If color option is disabled, the line appears in blue.
This indicator is ideal for traders looking to smooth price data and identify trends more clearly by reducing the impact of short-term volatility.
Release Notes
Adaptive Kalman Filter (Volatility Based)This indicator applies a 1-dimensional Kalman filter to the price, providing a highly adaptive and smooth representation of the underlying trend. Unlike traditional moving averages that use a fixed lookback period, this filter dynamically adjusts its behavior based on real-time market volatility.
Core Concept 🧠
The strength of this indicator lies in its adaptive nature. It continuously measures market volatility—using either ATR or Standard Deviation—and uses this information to dynamically adjust its internal noise parameters (R and Q).
This means the filter can:
Become smoother during choppy, high-volatility periods to reduce noise.
Remain responsive to persistent trends.
The result is a filtered price line that intelligently balances smoothing and responsiveness, offering a clearer view of the market's direction.
Key Settings ⚙️
You can easily fine-tune the filter's behavior to match your trading style:
- Volatility Measure: Choose between ATR and StdDev to quantify market volatility.
- R Multiplier (Smoothing Sensitivity): Controls the measurement noise. Higher values make the filter trust the price data less during volatile periods, resulting in more smoothing.
- Q Multiplier (Adaptation Speed): Controls the process noise. Higher values make the filter adapt to new price information more quickly, increasing its responsiveness.
- Color for trends: When enabled, the filter line turns green when rising and red when falling, providing a simple visual cue for the current trend direction.
How to Use It 📈
The Adaptive Kalman Filter can be used as a sophisticated, noise-canceling baseline for trend analysis. It serves as an intelligent alternative to traditional moving averages.
Trend Identification: Use the slope and color of the filter line to identify the prevailing trend.
Dynamic Support/Resistance: The filter line can act as a dynamic level of support or resistance.
Signal Generation: Crossovers between the price and the filter line can be used as potential entry or exit signals, similar to a moving average crossover strategy.
Release Notes
Added alerts for filtered value direction changeOpen-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.