Indicator · Pine Script v6 · On the chart

Chebyshev Type II Filter (CHEBY2)

by mihakralj

This indicator calculates a second-order Chebyshev Type II lowpass filter and plots the result on the price chart.

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/cheby2/cheby2.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

cheby2.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Chebyshev Type II Filter (CHEBY2)", "CHEBY2", overlay=true)

//@function Calculates 2nd Order Chebyshev Type II Lowpass Filter
//@param src Series to calculate Chebyshev filter from
//@param length Cutoff period (related to cutoff frequency)
//@param attenuation Stopband attenuation in decibels (dB) > 0
//@returns Chebyshev Type II filter value
//@optimized Uses IIR 2nd order Chebyshev Type II filter with O(1) complexity per bar
cheby2(series float src, simple int length, simple float attenuation) =>
    float pi = math.pi
    int safe_length = math.max(length, 2)
    float safe_atten = math.max(attenuation, 0.1)
    float wc = 2.0 * pi / safe_length
    float Wc = 2.0 * math.tan(wc / 2.0)
    float epsilon = 1.0 / math.sqrt(math.pow(10.0, safe_atten / 10.0) - 1.0)
    float asinh_inv_eps = math.log(1.0 / epsilon + math.sqrt(1.0 / (epsilon * epsilon) + 1.0))
    float mu = asinh_inv_eps / 2.0
    float sinh_mu = (math.exp(mu) - math.exp(-mu)) / 2.0
    float cosh_mu = (math.exp(mu) + math.exp(-mu)) / 2.0
    float sqrt2 = math.sqrt(2.0)
    float sigma_p = -Wc * sinh_mu / sqrt2
    float omega_p = Wc * cosh_mu / sqrt2
    float omega_z = Wc / math.cos(pi / 4.0)
    float Kp = sigma_p * sigma_p + omega_p * omega_p
    float Kz = omega_z * omega_z
    float DC_gain = Kz / Kp
    float a0_z = 1.0 - 2.0 * sigma_p + Kp
    float a1_z = 2.0 * Kp - 2.0
    float a2_z = 1.0 + 2.0 * sigma_p + Kp
    float b0_z = DC_gain * (1.0 + Kz)
    float b1_z = DC_gain * (2.0 * Kz - 2.0)
    float b2_z = DC_gain * (1.0 + Kz)
    float B0 = b0_z / a0_z
    float B1 = b1_z / a0_z
    float B2 = b2_z / a0_z
    float A1 = a1_z / a0_z
    float A2 = a2_z / a0_z
    float sumB = B0 + B1 + B2
    float sumA = 1.0 + A1 + A2
    float norm = sumA / sumB
    B0 *= norm
    B1 *= norm
    B2 *= norm
    var float filt = na
    if bar_index < 2
        filt := nz(src, 0.0)
    else
        float s0 = nz(src, 0.0)
        float s1 = nz(src[1], s0)
        float s2 = nz(src[2], s1)
        float f1 = nz(filt[1], s0)
        float f2 = nz(filt[2], f1)
        filt := B0 * s0 + B1 * s1 + B2 * s2 - A1 * f1 - A2 * f2
    filt

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

// Inputs
i_length = input.int(10, "Length", minval=2)
i_attenuation = input.float(5.0, "Stopband Attenuation (dB)", minval=0.1, step=1.0)
i_source = input.source(close, "Source")

// Calculation
cheby2_val = cheby2(i_source, i_length, i_attenuation)

// Plot
plot(cheby2_val, "Cheby2", color=color.yellow, linewidth=2)

Overview

Length sets the cutoff period, and stopband attenuation in decibels controls how strongly higher-frequency components are reduced. The source input selects the series being filtered. The recursive calculation uses a fixed number of prior source and filter values on each bar. It does not generate entry or exit signals.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend

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
Lengthint10i_length
Stopband Attenuation (dB)float5.0i_attenuation
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

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns

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