OPEN-SOURCE SCRIPT
AetherEdge - KALMAN | State-Space Trend

🖊️ Overview
AE-KALMAN treats price as a noisy observation and recursively estimates the true underlying trend level and velocity (slope) behind it with a two-state Kalman filter. Rather than averaging the past like a moving average, it runs a predict → observe → correct cycle on every bar. Crucially, the filter re-estimates how noisy the market is from its own forecast residuals, so it adapts automatically as volatility shifts. The lag-versus-smoothness trade-off is resolved probabilistically instead of by a fixed setting — that is the essence of AE-KALMAN.
🔶 Key Features
A slope-colored Kalman trend line estimating level and velocity (slope) simultaneously
Predictive bands whose width adapts to the predictive variance S — not a fixed multiplier
Shock detection via a standardized innovation "surprise" z-score — flags moves and regime breaks the model did not expect, with a marker and background tint
Innovation-based adaptive measurement noise — the filter learns the market's noise level from its own residuals and self-tunes (toggle)
A multi-step forecast ray (level + n·slope) with the projected price labeled
A gold-framed HUD showing trend, velocity, surprise z, Kalman gain, band width, noise, and forecast
No repaint — every signal is gated on bar close
Process/measurement noise is ATR-scaled, aligning automatically with each symbol's volatility
🧠 Technical Architecture
The state-space model is a local linear trend. The state vector is x = [level, slope], with transition F = [[1,1],[0,1]] (level advances by slope; slope is a random walk) and observation H = [1,0] (price = level + measurement noise). Each bar runs the standard recursion:
Predict: level' = level + slope; covariance P' = F·P·Fᵀ + Q
Update: innovation y = price − level'; predictive variance S = P'₁₁ + R; Kalman gain K = P'·Hᵀ / S; state correction x = x' + K·y; covariance P = (I − K·H)·P'
The 2×2 case is implemented in closed form by hand, so it needs no matrix inversion and stays numerically transparent.
Adaptive noise: the observed innovation variance estimates S = P'₁₁ + R, so R ≈ Var(y) − P'₁₁ is tracked online with an EWMA (with a floor). The filter therefore behaves smoothly in quiet conditions and responsively when the market turns turbulent.
Regime adaptation: velocity = slope ÷ ATR is compared against a dead-zone (slopeThr) to classify UP / DOWN / FLAT, while the magnitude of the surprise z = y ÷ √S detects shocks (news, fast moves).
Honest scope: this is a linear-Gaussian state-space filter (Kalman) — not a neural network and not a crystal ball. The forecast is a linear extrapolation of the current state.
⚙️ Recommended Settings & Tuning Guide
The defaults are tuned for crypto. The parameters that matter most are measurement noise (measR), process noise (procLvl / procSlp), band width (bandMult), the flat dead-zone (slopeThr), and the shock threshold (shockThr).
Smoother / slower: raise measR / lower procLvl
Faster / more reactive: raise procLvl / lower measR
procSlp controls how quickly trend direction may change — smaller keeps direction stable
Crypto starting points (tune on your chart):
BTC / ETH (1H–4H): defaults are a solid baseline; raise procLvl toward 0.4 to catch turns faster
SOL / XRP and high-volatility alts: wicky and noisy — use measR 2.0–2.5 and slopeThr 0.03–0.05 to suppress false FLAT/flip reads
Scalping (1–15m): raise procLvl (0.5+) for responsiveness; bandMult 1.5–2.0 for reversion entries
Swing (daily): lower procSlp (0.01–0.02) to stabilize slope; raise measR for a smoother line
For volatile crypto, keep adaptive noise ON; switch it off only when you want a fixed, predictable feel
💡 How to Use in Practice
Trend-following: ride the line color (velocity sign) and the UP/DN signals; treat FLAT as a range/stand-aside state
Mean-reversion: taps of the upper/lower predictive band flag overextension; because band width scales with S, small stretches in low vol and large stretches in high vol are judged on the same footing
S/R flips & breakouts: a decisive close through the Kalman level with a velocity flip marks the start of a regime change
Shock markers: highlight news, liquidations, and fakeouts — useful as an overextension warning or the onset of a volatility expansion
Forecast ray: the extrapolation of current level + velocity, handy for higher-timeframe bias and rough targets
Multi-timeframe: read directional velocity from a higher-timeframe AE-KALMAN and time entries on a lower one; agreement of both line colors is a high-confidence filter
Combinations: pair with AE-STRATA (SMC structure + ML/RL) and act only when Kalman velocity and STRATA's smart-money probability agree
⚠️ Important Notes
Initial convergence: from a large initial uncertainty, the filter takes a few dozen bars to settle — wait for values to stabilize at the start of history or right after switching symbols
Lag vs smoothness is a trade-off: smoother means slower; faster means noisier — there is no universal setting
The forecast is not a guarantee: it is a linear extrapolation (level + n·slope) and will miss sharp turns; treat it as a projection of the current state only
Parameter sensitivity: optimal noise settings vary by timeframe and symbol — always tune on the chart
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and is not financial advice or a recommendation to buy or sell. No method guarantees future profits; past performance does not indicate future results, and trading carries the risk of loss. All trading decisions are your own — please use proper backtesting and disciplined risk management.
AE-KALMAN treats price as a noisy observation and recursively estimates the true underlying trend level and velocity (slope) behind it with a two-state Kalman filter. Rather than averaging the past like a moving average, it runs a predict → observe → correct cycle on every bar. Crucially, the filter re-estimates how noisy the market is from its own forecast residuals, so it adapts automatically as volatility shifts. The lag-versus-smoothness trade-off is resolved probabilistically instead of by a fixed setting — that is the essence of AE-KALMAN.
🔶 Key Features
A slope-colored Kalman trend line estimating level and velocity (slope) simultaneously
Predictive bands whose width adapts to the predictive variance S — not a fixed multiplier
Shock detection via a standardized innovation "surprise" z-score — flags moves and regime breaks the model did not expect, with a marker and background tint
Innovation-based adaptive measurement noise — the filter learns the market's noise level from its own residuals and self-tunes (toggle)
A multi-step forecast ray (level + n·slope) with the projected price labeled
A gold-framed HUD showing trend, velocity, surprise z, Kalman gain, band width, noise, and forecast
No repaint — every signal is gated on bar close
Process/measurement noise is ATR-scaled, aligning automatically with each symbol's volatility
🧠 Technical Architecture
The state-space model is a local linear trend. The state vector is x = [level, slope], with transition F = [[1,1],[0,1]] (level advances by slope; slope is a random walk) and observation H = [1,0] (price = level + measurement noise). Each bar runs the standard recursion:
Predict: level' = level + slope; covariance P' = F·P·Fᵀ + Q
Update: innovation y = price − level'; predictive variance S = P'₁₁ + R; Kalman gain K = P'·Hᵀ / S; state correction x = x' + K·y; covariance P = (I − K·H)·P'
The 2×2 case is implemented in closed form by hand, so it needs no matrix inversion and stays numerically transparent.
Adaptive noise: the observed innovation variance estimates S = P'₁₁ + R, so R ≈ Var(y) − P'₁₁ is tracked online with an EWMA (with a floor). The filter therefore behaves smoothly in quiet conditions and responsively when the market turns turbulent.
Regime adaptation: velocity = slope ÷ ATR is compared against a dead-zone (slopeThr) to classify UP / DOWN / FLAT, while the magnitude of the surprise z = y ÷ √S detects shocks (news, fast moves).
Honest scope: this is a linear-Gaussian state-space filter (Kalman) — not a neural network and not a crystal ball. The forecast is a linear extrapolation of the current state.
⚙️ Recommended Settings & Tuning Guide
The defaults are tuned for crypto. The parameters that matter most are measurement noise (measR), process noise (procLvl / procSlp), band width (bandMult), the flat dead-zone (slopeThr), and the shock threshold (shockThr).
Smoother / slower: raise measR / lower procLvl
Faster / more reactive: raise procLvl / lower measR
procSlp controls how quickly trend direction may change — smaller keeps direction stable
Crypto starting points (tune on your chart):
BTC / ETH (1H–4H): defaults are a solid baseline; raise procLvl toward 0.4 to catch turns faster
SOL / XRP and high-volatility alts: wicky and noisy — use measR 2.0–2.5 and slopeThr 0.03–0.05 to suppress false FLAT/flip reads
Scalping (1–15m): raise procLvl (0.5+) for responsiveness; bandMult 1.5–2.0 for reversion entries
Swing (daily): lower procSlp (0.01–0.02) to stabilize slope; raise measR for a smoother line
For volatile crypto, keep adaptive noise ON; switch it off only when you want a fixed, predictable feel
💡 How to Use in Practice
Trend-following: ride the line color (velocity sign) and the UP/DN signals; treat FLAT as a range/stand-aside state
Mean-reversion: taps of the upper/lower predictive band flag overextension; because band width scales with S, small stretches in low vol and large stretches in high vol are judged on the same footing
S/R flips & breakouts: a decisive close through the Kalman level with a velocity flip marks the start of a regime change
Shock markers: highlight news, liquidations, and fakeouts — useful as an overextension warning or the onset of a volatility expansion
Forecast ray: the extrapolation of current level + velocity, handy for higher-timeframe bias and rough targets
Multi-timeframe: read directional velocity from a higher-timeframe AE-KALMAN and time entries on a lower one; agreement of both line colors is a high-confidence filter
Combinations: pair with AE-STRATA (SMC structure + ML/RL) and act only when Kalman velocity and STRATA's smart-money probability agree
⚠️ Important Notes
Initial convergence: from a large initial uncertainty, the filter takes a few dozen bars to settle — wait for values to stabilize at the start of history or right after switching symbols
Lag vs smoothness is a trade-off: smoother means slower; faster means noisier — there is no universal setting
The forecast is not a guarantee: it is a linear extrapolation (level + n·slope) and will miss sharp turns; treat it as a projection of the current state only
Parameter sensitivity: optimal noise settings vary by timeframe and symbol — always tune on the chart
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and is not financial advice or a recommendation to buy or sell. No method guarantees future profits; past performance does not indicate future results, and trading carries the risk of loss. All trading decisions are your own — please use proper backtesting and disciplined risk management.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.