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.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publications is governed by House rules. You can favorite it to use it on a chart.
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.