Indicator · Pine Script v6 · Own pane

Ehlers Roofing Filter (ROOFING)

by mihakralj

The Ehlers Roofing Filter isolates cyclical market components by eliminating low-frequency macro trends and high-frequency market noise.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code70
Settings3inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 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

70 lines of Pine Script v6 from lib/filters/roofing/roofing.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

roofing.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
// Indicator algorithm (C) 2004-2024 John F. Ehlers
indicator("Ehlers Roofing Filter (ROOFING)", "ROOFING", overlay=false)

//@function Calculates Ehlers Roofing Filter (2-pole HPF → Super Smoother composite)
//@param source Series to calculate Roofing Filter from
//@param hpLength Cutoff period for the highpass stage (removes trend below this period)
//@param ssLength Cutoff period for the super smoother stage (removes noise above this period)
//@returns Bandpass-filtered value oscillating around zero
//@optimized Uses two cascaded 2-pole IIR filters with O(1) complexity per bar
roofing(series float src, simple int hpLength, simple int ssLength) =>
    var float SQRT2_PI = math.sqrt(2.0) * math.pi

    // --- Stage 1: 2-pole Butterworth Highpass Filter (removes trend) ---
    int safe_hp = math.max(hpLength, 1)
    var float hp_c1 = 0.0
    var float hp_c2 = 0.0
    var float hp_c3 = 0.0
    var int prev_hp = 0
    if prev_hp != safe_hp
        float hp_arg = SQRT2_PI / float(safe_hp)
        float hp_exp_arg = math.exp(-hp_arg)
        hp_c2 := 2.0 * hp_exp_arg * math.cos(hp_arg)
        hp_c3 := -hp_exp_arg * hp_exp_arg
        hp_c1 := (1.0 + hp_c2 - hp_c3) / 4.0
        prev_hp := safe_hp

    var float hp = 0.0
    float ssrc = nz(src, src[1])
    float src1 = nz(src[1], ssrc)
    float src2 = nz(src[2], src1)
    float hp1 = nz(hp[1], 0.0)
    float hp2 = nz(hp[2], 0.0)
    hp := hp_c1 * (ssrc - 2.0 * src1 + src2) + hp_c2 * hp1 + hp_c3 * hp2

    // --- Stage 2: Super Smoother Filter (removes noise from HP output) ---
    int safe_ss = math.max(ssLength, 1)
    var float ss_c1 = 0.0
    var float ss_c2 = 0.0
    var float ss_c3 = 0.0
    var int prev_ss = 0
    if prev_ss != safe_ss
        float ss_arg = SQRT2_PI / float(safe_ss)
        float ss_exp_arg = math.exp(-ss_arg)
        ss_c2 := 2.0 * ss_exp_arg * math.cos(ss_arg)
        ss_c3 := -ss_exp_arg * ss_exp_arg
        ss_c1 := 1.0 - ss_c2 - ss_c3
        prev_ss := safe_ss

    var float roof = 0.0
    float hp_cur = hp
    float hp_prev1 = nz(hp[1], hp_cur)
    roof := ss_c1 * hp_cur + ss_c2 * nz(roof[1], hp_prev1) + ss_c3 * nz(roof[2], nz(hp[2], hp_prev1))
    roof

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

// Inputs
i_hpLength = input.int(48, "HP Length", minval=1, tooltip="Highpass cutoff period — removes cycles longer than this")
i_ssLength = input.int(10, "SS Length", minval=1, tooltip="Super Smoother cutoff period — removes cycles shorter than this")
i_source   = input.source(close, "Source")

// Calculation
roof_val = roofing(i_source, i_hpLength, i_ssLength)

// Plot
plot(roof_val, "Roofing", color=color.yellow, linewidth=2)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)

Overview

Ehlers Roofing Filter (ROOFING) combines a two-pole Butterworth high-pass filter with a Super Smoother filter. The high-pass stage removes cycle components longer than the high-pass period setting, while the Super Smoother stage removes noise shorter than the Super Smoother length. The resulting bandpass-filtered series oscillates around a zero line and is plotted in a separate pane.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum

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

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
HP Lengthint48i_hpLength
SS Lengthint10i_ssLength
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

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

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