Wikipedia says

Hodrick Prescott Filter (HP Filter) does Time series decomposition which involves separating a time series into several distinct components(Cycle component and Trend Component). And this filter looks like it can be applied to any time-series data especially with stock prices to understand the underlying trend and the cycle involved in it.

Here is a simple ipython notebook example for Hodrick Prescott Filter Analysis. We use **statsmodel** library to compute the Hodrick Prescott Filter Components, **Matplotlib** to plot the data, **NSEpy** to retrieve the stock data from NSEIndia and **Pandas** to handle the time series data.

The above chart shows the Stock TCS price and HP Filter components trend and cycles component. You might have noticed that the trend component is ultra-smooth and very good in forecasting the future of medium TCS price direction. And the Cycle Component extreme values suggest a possible trend reversal. To my view, it should be a better tool for traders and investors to know the underlying trend. Especially HP filter suits both trend followers and mean reversion traders!

I know for a fact that Prescott filter is re-calculating the past bars and so is not reliable due to repainting. So how can it be used for trading?

Yeh Agree but it is said that Prescott Windows is tradeable http://www.neuroshell.com/manuals/ais1/hodrickprescottwindow.htm which eliminates recalculation for previous bars. And one can manage strategy that is tradeable.

Where is the code? I couldn’t find in this page

You should be able to see the code now. Coz of site updates some of the components got missed out.

Now back to normal.