Hodrick-Prescott filter [Jamallo]

(2025)
Intro
The Hodrick-Prescott (HP) filter is a tool originally developed by economists to remove short-term noise from data and reveal the underlying long-term trend — think of it like a moving average, but mathematically smarter.
Instead of just averaging recent prices, it solves for the smoothest possible trendline that still follows the data. Applied to price, it produces a cleaner baseline than most traditional moving averages.
---
However it comes with 3 problems in practical day trading.
Problem #1 Standard HP Repaints History (core issue)
The standard HP filter is non-causal — the value at any point in time depends on future values CEPR, meaning past signals can change retroactively.
How I solved it:
Switching to a one-sided implementation fixes this — it only looks at past data, so history never changes once a bar closes.
Problem #2 One-Sided HP Hooks at Turns
Going one-sided introduces an endpoint artifact — near turning points the trend line briefly curves in the wrong direction before reversing, producing a false signal.
How I solved it:
Feeding the HP output into a range filter solves this. The line only moves when HP breaks outside a volatility band, so the false hook gets absorbed into a flat zone and never fires a signal.
Problem #3 Fixed Band Would Be Too Rigid
A fixed band would whipsaw in volatile markets and lag in calm ones.
How I solved it:
Instead the band is sized dynamically using a percentile of True Range, scaling automatically with current market conditions.
Intro
The Hodrick-Prescott (HP) filter is a tool originally developed by economists to remove short-term noise from data and reveal the underlying long-term trend — think of it like a moving average, but mathematically smarter.
Instead of just averaging recent prices, it solves for the smoothest possible trendline that still follows the data. Applied to price, it produces a cleaner baseline than most traditional moving averages.
---
However it comes with 3 problems in practical day trading.
Problem #1 Standard HP Repaints History (core issue)
The standard HP filter is non-causal — the value at any point in time depends on future values CEPR, meaning past signals can change retroactively.
How I solved it:
Switching to a one-sided implementation fixes this — it only looks at past data, so history never changes once a bar closes.
Problem #2 One-Sided HP Hooks at Turns
Going one-sided introduces an endpoint artifact — near turning points the trend line briefly curves in the wrong direction before reversing, producing a false signal.
How I solved it:
Feeding the HP output into a range filter solves this. The line only moves when HP breaks outside a volatility band, so the false hook gets absorbed into a flat zone and never fires a signal.
Problem #3 Fixed Band Would Be Too Rigid
A fixed band would whipsaw in volatile markets and lag in calm ones.
How I solved it:
Instead the band is sized dynamically using a percentile of True Range, scaling automatically with current market conditions.
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.
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.