OPEN-SOURCE SCRIPT
Iteratively Reweighted Least Squares Range Filter [Jamallo]

Intro
Iteratively Reweighted Least Squares Range Filter
Most filters treat every bar equally. This one doesn't. The IRLS Range Filter uses a robust statistical engine to continuously evaluate how much each bar in the lookback window should be trusted — down-weighting noisy data and rejecting outliers entirely — before computing a consensus price level. The result is a smoother, more honest trend line that is far less susceptible to wicks, gaps, and volatile noise than conventional moving averages.
How It Works
The indicator runs in three stages:
Stage 1 — IRLS Consensus Engine. Every bar in the rolling window is assigned one of three trust states based on how far its price deviates from the current consensus, measured in adaptive sigma units. High Trust bars (within Lo-Trust Band σ) receive full weight. Lo Trust bars receive half weight. Rejected bars receive none. A Schmitt-trigger hysteresis mechanism prevents bars from flickering between states on minor fluctuations. The weighted average of all contributing bars becomes the consensus price. This residual-based weighting scheme is adapted from the IRLS framework described in Li & Deng (2026), arXiv:2603.08158.
Stage 2 — Deadband Quantizer. The continuous consensus is passed through a step filter. The output only moves when the consensus has shifted by more than one deadband unit (Step Size × σ). This eliminates micro-jitter and produces a clean staircase line with fewer false trend flips.
Stage 2.5 — Sample-and-Hold Bands. The volatility channel is only updated when the filter takes a new step, so band width reflects conditions at the last decisive move rather than real-time noise. An EMA-style smoother (Band Smooth) prevents abrupt band jumps between steps.
Reference
Li, J., & Deng, F. (2026). Outlier-robust Autocovariance Least Square Estimation via Iteratively Reweighted Least Square. arXiv preprint arXiv:2603.08158v1.
Iteratively Reweighted Least Squares Range Filter
Most filters treat every bar equally. This one doesn't. The IRLS Range Filter uses a robust statistical engine to continuously evaluate how much each bar in the lookback window should be trusted — down-weighting noisy data and rejecting outliers entirely — before computing a consensus price level. The result is a smoother, more honest trend line that is far less susceptible to wicks, gaps, and volatile noise than conventional moving averages.
How It Works
The indicator runs in three stages:
Stage 1 — IRLS Consensus Engine. Every bar in the rolling window is assigned one of three trust states based on how far its price deviates from the current consensus, measured in adaptive sigma units. High Trust bars (within Lo-Trust Band σ) receive full weight. Lo Trust bars receive half weight. Rejected bars receive none. A Schmitt-trigger hysteresis mechanism prevents bars from flickering between states on minor fluctuations. The weighted average of all contributing bars becomes the consensus price. This residual-based weighting scheme is adapted from the IRLS framework described in Li & Deng (2026), arXiv:2603.08158.
Stage 2 — Deadband Quantizer. The continuous consensus is passed through a step filter. The output only moves when the consensus has shifted by more than one deadband unit (Step Size × σ). This eliminates micro-jitter and produces a clean staircase line with fewer false trend flips.
Stage 2.5 — Sample-and-Hold Bands. The volatility channel is only updated when the filter takes a new step, so band width reflects conditions at the last decisive move rather than real-time noise. An EMA-style smoother (Band Smooth) prevents abrupt band jumps between steps.
Reference
Li, J., & Deng, F. (2026). Outlier-robust Autocovariance Least Square Estimation via Iteratively Reweighted Least Square. arXiv preprint arXiv:2603.08158v1.
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.
No courses, don't sell signals — just my own edge, stats public: jalgo.ca/
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.
No courses, don't sell signals — just my own edge, stats public: jalgo.ca/
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.