Indicator · Pine Script v6 · On the chart

Highpass Filter (2-Pole)

by mihakralj

This indicator calculates a 2-pole Infinite Impulse Response highpass filter to isolate higher-frequency components or remove trends from a given price source.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code37
Settings2inputs
LicenceMIT
Last update8 months ago28 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

37 lines of Pine Script v6 from indicators/filters/hpf.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

hpf.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Highpass Filter (2-Pole) (HPF)", "HPF", overlay=true)

//@function Calculates 2-Pole Highpass Filter
//@param src Series to calculate HPF from
//@param length Cutoff period (determines alpha)
//@returns HPF value
//@optimized Uses 2-pole IIR highpass filter with O(1) complexity per bar
hpf(series float src, simple int length) =>
    int safe_length = math.max(length, 1)
    float pi = math.pi
    float omega = 2.0 * pi / safe_length
    float alpha = (math.cos(omega) + math.sin(omega) - 1.0) / math.cos(omega)
    var float hp_val_internal = 0.0
    float hp1 = nz(hp_val_internal[1], 0.0)
    float hp2 = nz(hp_val_internal[2], 0.0)
    float ssrc = nz(src, src[1])
    float src1 = nz(src[1], ssrc)
    float src2 = nz(src[2], src1)
    float alpha_div_2 = alpha / 2.0
    float one_minus_alpha = 1.0 - alpha
    hp_val_internal := (1.0 - alpha_div_2) * (1.0 - alpha_div_2) * (ssrc - 2.0 * src1 + src2) + 2.0 * one_minus_alpha * hp1 - one_minus_alpha * one_minus_alpha * hp2
    hp_val_internal

// ---------- Main loop ----------

// Inputs
i_length = input.int(40, "Length", minval=1)
i_source = input.source(close, "Source")

// Calculation
hp_component = hpf(i_source, i_length)

// Plot
plot(i_source - hp_component, "Trend Component", color=color.yellow, linewidth=2)

Overview

Highpass Filter (2-Pole) computes an internal highpass value based on a configurable length parameter and plots the resulting trend component directly on the price chart. The main settings allow users to adjust the input length and select the data source. It is implemented using an O(1) complexity per bar approach in Pine Script version 6.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptpinescript-indicatorstechnical-analysistradingview-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lengthint40i_length
Sourcesourceclosei_source
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Hampel Filter

by everget
948 stars

The Hampel Filter indicator identifies and filters out price outliers to smooth price data directly on the main chart. It calculates the rolling median and Median Absolute Deviation (MAD) of the chosen source series over a specified length. When a data point e

Indicator v4 Moving averagesVolatility & bands
Updated 10 days ago · GPL-3.0 GitHub repository of Hampel Filter

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

Algo AVT

by ricardosantos79
261 stars

This indicator calculates an outlier-filtered moving average based on statistical filtering concepts. It stores close prices in a rolling array over a user-defined length, calculates the mean and standard deviation, and excludes values falling within a specifi

Indicator v4 Moving averagesVolatility & bands
Updated 4 years ago · None stated GitHub repository of Algo AVT

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers