OPEN-SOURCE SCRIPT

AetherEdge - Kalman State Filter

329
🖊️ Overview

AE-KSF is a self-evolving state-space estimator that treats price as a hidden state. It models the true price as a **local linear trend — a level and a velocity — and recovers it from noisy observations with a Kalman filter. Critically, it does more than smooth: it carries the full uncertainty (covariance) of its estimate and projects it forward as a widening confidence cone. And because it estimates measurement noise online from the innovation stream, the Kalman gain self-tunes to every instrument and regime.

🔶 Key Features

A full Kalman filter engine — predict (x'=Fx, P'=FPF^T+Q) and update (x=x'+K(z−Hx')) run every bar, jointly estimating level and velocity.
Self-evolving adaptive noise — measurement noise R is estimated from the innovation stream, so the Kalman gain self-adjusts to volatility and noise level.
Uncertainty cone — the covariance is propagated forward into a probability cone that widens with confidence, visualizing how far the estimate can be trusted rather than a bare point line.
In-sample confidence band — a translucent ±σ band hugs the centerline, conveying current state uncertainty at a glance.
Velocity & trend strength — velocity (per-bar drift) and its signal-to-noise ratio (a t-statistic) quantify how certain the trend is.
Semantic coloring — centerline, band, and cone are auto-colored by velocity sign and confidence (Rising / Falling / Flat).
Live statistics panel — trend direction, velocity, trend strength, Kalman gain, estimated noise R, state uncertainty, and innovation.
Non-repainting design — state updates on confirmed bars only, with no look-ahead.

🧠 Technical Architecture

The state is two-dimensional — level p and velocity v. Transition F = [[1,1],[0,1]] (constant-velocity), observation H = [1,0] (level only). Each confirmed bar runs a predict step (advancing state and covariance P) and an update step (folding in the innovation z−Hx' through gain K). Observation is in log-price space by default, so the cone becomes multiplicative and asymmetric in price — a financially natural shape.
The heart of the self-evolution is adaptive noise estimation. An EMA tracks the squared innovation, and measurement noise is estimated as R ≈ EMA(innov²) − P'_position (floored). The filter thus dials its gain down in noisy phases (smoother) and up when structure is clear (snappier) — balancing itself. Process noise q is set as a ratio to that estimated R via the "Responsiveness" knob, auto-scaling to the instrument's noise level. The forward cone is built by propagating state and covariance with no measurements; its width starts at the current state uncertainty and widens with horizon.

🎯 Three design choices stand out. First, carrying covariance delivers a confidence-aware estimate beyond a smooth line. Second, adaptive R auto-calibrates the cone to real price noise. Third, confining state updates to confirmed bars keeps the historical estimate non-repainting.

⚙️ Recommended Settings & Tuning Guide

As a crypto starting point — BTC/ETH (1D, 4H): Responsiveness 20, Adaptive Noise on, Confidence σ = 2.0, horizon 16; smooth, low-lag trend tracking. High-volatility names (SOL, XRP): lower Responsiveness to 10–15 to absorb noise, and widen Confidence σ toward 2.5 for a steadier centerline and cone in rough action.
Per parameter: Responsiveness is the main knob — higher tracks price faster (less lag, less smoothing); lower is smoother (more lag, more noise tolerance). Adaptive Noise is best left on — it auto-calibrates per market; for manual control, set Manual Noise (R) directly. Confidence σ sets band and cone width; Horizon sets projection length. Trend Deadband (t-stat) sets how much trend certainty counts as Rising / Falling.

💡 How to Use in Practice

The core read is centerline × velocity × trend strength. When the centerline tilts up (cyan) with a high trend-strength (t-statistic), it reads as a tailwind for buying dips. A tag-and-reject at the in-sample band edge marks a deviation from the state estimate — a mean-reversion cue. A contracting band/cone means a calm, high-confidence state; an expanding one means rising uncertainty — useful for sizing. The forward cone's slope and width convey trend direction and confidence at a glance.
For multi-timeframe work, read the higher-timeframe centerline for the backdrop and use velocity turns (t-stat sign flips) on a lower timeframe for execution. Layered over support/resistance or volume, the Kalman centerline acts as a proxy for the "smooth price path institutions watch" — a reference line for entries and exits.

⚠️ Important Notes

Estimates are hidden until the warmup period (default 30 bars) completes (kept short, as the Kalman converges fast). Reloading the indicator makes the filter reprocess history from scratch — state is not persisted. This is a constant-velocity (local linear trend) model, so the forward point estimate is a straight line — it does not foretell sharp moves or reversals themselves. The uncertainty cone is a probabilistic range under the model's assumptions, not a certain forecast. State updates on confirmed bars; on the forming bar the centerline holds its last confirmed value.

🚨 Disclaimer

This indicator is for educational and informational purposes only and does not constitute financial or investment advice. Past performance is not indicative of future results. All trading involves risk. Use it alongside your own thorough testing and sound risk management; all trading decisions remain solely your own responsibility.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.