OPEN-SOURCE SCRIPT
Actualizado

[blackcat] L2 Ehlers Bandpass Filter

2 253
Level: 2

Background

John F. Ehlers introuced Bandpass Filter in his "Cycle Analytics for Traders" chapter 5 on 2004.


Function

After declaring variables, the band-pass filter calculation is preceded by a high-pass filter whose cutoff frequency is one half-bandwidth octave below the lower-frequency critical frequency of the band-pass filter to avoid interference with the action of the band-pass filter while still removing the effects of Spectral Dilation.

Key Signal

Trigger ---> Bandpass Filter fast line
Signal ---> Bandpass Filter slow line


Pros and Cons

100% John F. Ehlers definition translation of original work, even variable names are the same. This help readers who would like to use pine to read his book. If you had read his works, then you will be quite familiar with my code style.

Remarks

The 38th script for Blackcat1402 John F. Ehlers Week publication.

Readme

In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.

The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.

Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.

Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.

Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.

Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.

Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy.
Notas de prensa
b]OVERVIEW The L2 Ehlers Bandpass Filter is an advanced technical indicator that applies a bandpass filter to price data to identify cyclical patterns and potential trading opportunities. It combines signal processing techniques with divergence detection for comprehensive market analysis.
FEATURES
• Customizable bandpass filter parameters:

Period (default: 20)
Bandwidth (default: 0.3) • Visual signal and trigger lines • Buy/Sell labels at crossover points • Divergence detection for four types:
Regular Bullish
Hidden Bullish
Regular Bearish
Hidden Bearish • Configurable lookback periods and range settings • Alert conditions for all divergence types
HOW TO USE

Adjust the Period and Bandwidth inputs to fine-tune sensitivity
Configure divergence detection parameters: • Pivot Lookback Right/Left • Max/Min Lookback Range • Plot options for each divergence type
Monitor the Signal line and Trigger line for crossovers
Watch for labeled signals (BUY/SELL) at crossover points
Use divergence alerts to confirm trading opportunities
LIMITATIONS
• Results depend on proper parameter configuration
• False signals may occur during trending markets
• Best used in conjunction with other analysis tools

NOTES
• The indicator overlays the main chart by default
• Color coding helps distinguish between bullish (green) and bearish (red) signals
• Alerts can be customized through TradingView's alert system
Notas de prensa
█ OVERVIEW

This oscillator isolates the dominant price cycle with John Ehlers' Bandpass Filter and turns it into clear crossover entry signals. V2 upgrades the classic script with a signal state machine, cooldown, bar-close confirmation, ATR-based take-profit and stop-loss tracking, a live dashboard and a complete alert pack.

█ CONCEPTS

The filter works in three layers:

• A high-pass filter detrends price and removes slow drift
• A band-pass stage isolates the frequency band around your Period setting, keeping only the dominant cycle
• The cycle amplitude is normalized by a decaying peak, so the Signal line swings roughly between -1 and +1 and stays comparable across symbols and timeframes

The Trigger line is a fast rate-of-change of the Signal. Because it leads the smoothed cycle, Trigger crossovers act as early turning-point detectors.

█ HOW TO USE

1 — Add the script to any chart. It loads in a separate pane below price.
2 — Set Period to the cycle length you want to trade (default 20) and Bandwidth to how tightly the filter hugs that cycle (default 0.3).
3 — Read BUY labels when Trigger crosses above Signal and SELL labels when it crosses below. The state machine tracks whether you are long, short or flat, and paints the pane background accordingly.
4 — Optional TP/SL tracking starts at each entry: the level, distance in ATR multiples, is shown in the dashboard and data window until price closes beyond it.

Input Parameters
• Period — center cycle length of the bandpass filter (default 20)
• Bandwidth — filter width as a fraction of the period (default 0.3; smaller = narrower, smoother)
• Peak Decay — normalization decay of the cycle peak (default 0.991)
• Confirm Signals on Bar Close — ON fires signals only on the closing tick, avoiding intrabar flip-flops; OFF reproduces raw V1 behavior
• Cooldown Bars — minimum bars between two entries (default 3; 0 disables)
• Enable TP/SL Tracking + ATR Length, Stop Loss xATR, Take Profit xATR — volatility-adaptive exit references
• Divergence group — pivot lookbacks, lookback range and which divergence types to plot
• Visuals — toggle position background and dashboard

█ FEATURES

• Stop-and-reverse entry logic preserved from the original, now governed by a position state machine
• Same-bar exclusivity: TP/SL exits take priority over fresh entries
• Regular and hidden, bullish and bearish divergences between the oscillator and price
• Eight alertcondition hooks plus dynamic close-confirmed alert() messages
• Dashboard with position, Signal, Trigger, ATR, entry, TP and SL at a glance

█ SIGNALS

Visual Elements
• BUY / SELL labels — Trigger/Signal crossover entries in the cycle
• TP (teal) / SL (maroon) crosses — tracked exit level reached on a closed bar
• Green / red pane background — current long / short state
• Bull / Bear labels on the oscillator — divergence confirmations (lag by design, they need a confirmed pivot)

█ IMPLEMENTATION NOTES

Open source under MPL 2.0, originally by blackcat1402, based on John F. Ehlers' band-pass design. Built with built-in ta.crossover, ta.atr, ta.pivotlow, ta.pivothigh and ta.valuewhen. No request.security calls, no lookahead. Signals are non-repainting when Confirm Signals on Bar Close is ON; divergence marks appear lbR bars after the pivot by construction.

█ LIMITATIONS

• Cycle-following logic shines in oscillating markets and whipsaws in strong one-way trends — combine with a trend filter
• Signals are meaningful only when a clean cycle exists; very short periods on noisy low timeframes degrade quickly
• TP/SL levels are reference levels computed on close, not exchange orders
• Not financial advice; always forward-test on your market and timeframe

█ NOTES

• Credits: John F. Ehlers for the bandpass concept, blackcat1402 for the original V1 script
• V1 behavior is one toggle away: set Cooldown Bars to 0, disable TP/SL and turn off bar-close confirmation

════════════════════════════════════════════════════════════════════════
For questions or feedback, please use the comments section below.
Feel free to use and modify — attribution appreciated.

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.