Adaptive Moving Average - Kalman

382
A single, honest Kalman-filter smoother for price. It treats price as a noisy observation of a hidden "true" level and reconstructs that level optimally, bar by bar. Unlike an SMA or EMA there is no fixed lag: the filter adapts to the balance between process noise and observation noise — tighter tracking in trends, heavier smoothing in chop.

WHAT IT DOES
• Runs a local-level Kalman filter on your chosen source (default close). Model: price = hidden level + noise, where the hidden level follows a random walk.
• Plots the optimal estimate of that hidden level as the main line, coloured by its own slope (green rising, red falling).
• Optional slower Kalman signal line for a single, built-in crossover — no stacked layers.
• Four alerts: bullish / bearish crossover, slope flips up, slope flips down.

WHY A KALMAN FILTER INSTEAD OF A MOVING AVERAGE
A fixed-length average lags by a fixed amount, which is wrong in at least one regime: too slow in a breakout, too jumpy in a range. A Kalman filter has no "length". It has two variances whose ratio tells it how much to trust each new observation versus the prior estimate, so it adapts per bar without retuning. It is the same mathematics used in navigation and signal processing for decades — it is just rarely implemented cleanly on TradingView.

HOW TO USE
1. Add the indicator; defaults suit most intraday charts.
2. Tune "Process variance — main" (q): higher = more reactive, lower = smoother. Useful range 0.005–0.05.
3. Leave "Observation variance" at 1 — only the ratio q/r matters, so move q and leave r alone.
4. Keep the signal line's q below the main line's q so it stays slower.
5. Main line rising with price above it = long bias; falling with price below = short bias; repeated crosses without follow-through = chop, stand aside.

SETTINGS
Source · process variance (main / signal) · observation variance (main / signal) · signal line on/off · trend colouring on/off.

NOTES
Non-repainting: the estimate on a closed bar never changes. Pine Script v6, zero warnings.

No indicator is infallible. This is a smoothing tool, not a trading system.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.