OPEN-SOURCE SCRIPT
Kalman Regime [Jamallo]

(2025)
Intro
Kalman Regime filters price through two stages — a Gaussian kernel weighted average followed by an adaptive Kalman filter — to produce a smooth, noise-resistant baseline. ATR is used throughout to make the system volatility-aware.
Breakdown
The Gaussian kernel pre-smooths price using a bell-shaped weight profile that blends recency bias (recent bars matter more) with center localization (edge bars contribute less). This pre-smoothed value is then passed into an adaptive Kalman filter, which recursively estimates the "true" price state by balancing how much to trust the new measurement versus the prior state — with that balance dynamically scaled by current ATR.
The resulting baseline drives regime detection through a two-tier state machine. A strong signal fires when price breaks the ATR envelope and the baseline slope confirms direction. A weaker signal fires when price crosses the baseline and slope exceeds an ATR-scaled threshold. This dual-gate structure reduces whipsaws without adding lag.
END
A two-stage price filter combining a Gaussian kernel pre-smoother with an adaptive Kalman filter, using ATR envelopes and slope confirmation for regime detection.
Intro
Kalman Regime filters price through two stages — a Gaussian kernel weighted average followed by an adaptive Kalman filter — to produce a smooth, noise-resistant baseline. ATR is used throughout to make the system volatility-aware.
Breakdown
The Gaussian kernel pre-smooths price using a bell-shaped weight profile that blends recency bias (recent bars matter more) with center localization (edge bars contribute less). This pre-smoothed value is then passed into an adaptive Kalman filter, which recursively estimates the "true" price state by balancing how much to trust the new measurement versus the prior state — with that balance dynamically scaled by current ATR.
The resulting baseline drives regime detection through a two-tier state machine. A strong signal fires when price breaks the ATR envelope and the baseline slope confirms direction. A weaker signal fires when price crosses the baseline and slope exceeds an ATR-scaled threshold. This dual-gate structure reduces whipsaws without adding lag.
END
A two-stage price filter combining a Gaussian kernel pre-smoother with an adaptive Kalman filter, using ATR envelopes and slope confirmation for regime detection.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Join the Growing (Econophysics Trading) Community! ⚛️
discord.com/invite/qb4RKFdwYJ
Trade the physics of price.
discord.com/invite/qb4RKFdwYJ
Trade the physics of price.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Join the Growing (Econophysics Trading) Community! ⚛️
discord.com/invite/qb4RKFdwYJ
Trade the physics of price.
discord.com/invite/qb4RKFdwYJ
Trade the physics of price.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.