PINE LIBRARY

[GYTS] FiltersToolkit Library

147
FiltersToolkit Library
🌸 Part of GoemonYae Trading System (GYTS) 🌸

🌸 --------- 1. INTRODUCTION --------- 🌸

💮 What Does This Library Contain?
This library is a curated collection of high-performance digital signal processing (DSP) filters and auxiliary functions designed specifically for financial time series analysis. It includes a shortlist of our favourite and best performing filters — each rigorously tested and selected for their responsiveness, minimal lag and robustness in diverse market conditions. These tools form an integral part of the GoemonYae Trading System (GYTS), chosen for their unique characteristics in handling market data.

The library contains two main categories:
1. Smoothing filters (low-pass filters and moving averages) for e.g. denoising, trend following
2. Detrending tools (high-pass and band-pass filters, known as "oscillators") for e.g. mean reversion

This collection is finely tuned for practical trading applications and is therefore not meant to be exhaustive. However, will continue to expand as we discover and validate new filtering techniques. I welcome collaboration and suggestions for novel approaches.


🌸 ——— 2. ADDED VALUE ——— 🌸

💮 Unified syntax and comprehensive documentation
The FiltersToolkit Library brings together a wide array of valuable filters under a unified, intuitive syntax. Each function is thoroughly documented, with clear explanations and academic sources that underline the mathematical rigour behind the methods. This level of documentation not only facilitates integration into trading strategies but also helps underlying the underlying concepts and rationale.

💮 Optimised performance and readability
The code prioritizes computational efficiency while maintaining readability. Key optimizations include:
- Minimizing redundant calculations in recursive filters
- Smart coefficient caching
- Efficient state management
- Vectorized operations where applicable

💮 Enhanced functionality and flexibility
Some filters in this library introduce extended functionality beyond the original publications. For instance, the MESA Adaptive Moving Average (MAMA) and Ehlers’ Combined Bandpass Filter incorporate multiple variations found in the literature, thereby providing traders with flexible tools that can be fine-tuned to different market conditions.


🌸 ——— 3. THE FILTERS ——— 🌸

💮 Hilbert Transform Function
This function implements the Hilbert Transform as utilised by John Ehlers. It converts a real-valued time series into its analytic signal, enabling the extraction of instantaneous phase and frequency information—an essential step in adaptive filtering.
Source: John Ehlers - "Rocket Science for Traders" (2001), "TASC 2001 V. 19:9", "Cybernetic Analysis for Stocks and Futures" (2004)

💮 Homodyne Discriminator
By leveraging the Hilbert Transform, this function computes the dominant cycle period through a Homodyne Discriminator. It extracts the in-phase and quadrature components of the signal, facilitating a robust estimation of the underlying cycle characteristics.
Source: John Ehlers - "Rocket Science for Traders" (2001), "TASC 2001 V. 19:9", "Cybernetic Analysis for Stocks and Futures" (2004)

💮 MESA Adaptive Moving Average (MAMA)
An advanced dual-stage adaptive moving average, this function outputs both the MAMA and its companion FAMA. It combines adaptive alpha computation with elements from Kaufman’s Adaptive Moving Average (KAMA) to provide a responsive and reliable trend indicator.
Source: John Ehlers - "Rocket Science for Traders" (2001), "TASC 2001 V. 19:9", "Cybernetic Analysis for Stocks and Futures" (2004)

💮 BiQuad Filters
A family of second-order recursive filters offering exceptional control over frequency response:
- High-pass filter for detrending
- Low-pass filter for smooth trend following
- Band-pass filter for cycle isolation

The quality factor (Q) parameter allows fine-tuning of the resonance characteristics, making these filters highly adaptable to different market conditions.

Source: Robert Bristow-Johnson's Audio EQ Cookbook, implemented by The_Peaceful_Lizard

💮 Relative Vigor Index (RVI)
This filter evaluates the strength of a trend by comparing the closing price to the trading range. Operating similarly to a band-pass filter, the RVI provides insights into market momentum and potential reversals.
Source: John Ehlers – “Cybernetic Analysis for Stocks and Futures” (2004)

💮 Cyber Cycle
The Cyber Cycle filter emphasises market cycles by smoothing out noise and highlighting the dominant cyclical behaviour. It is particularly useful for detecting trend reversals and cyclical patterns in the price data.
Source: John Ehlers – “Cybernetic Analysis for Stocks and Futures” (2004)

💮 Butterworth High Pass Filter
Inspired by the classical Butterworth design, this filter achieves a maximally flat magnitude response in the passband while effectively removing low-frequency trends. Its design minimises phase distortion, which is vital for accurate signal interpretation.
Source: John Ehlers – “Cybernetic Analysis for Stocks and Futures” (2004)

💮 2-Pole SuperSmoother
Employing a two-pole design, the SuperSmoother filter reduces high-frequency noise with minimal lag. It is engineered to preserve trend integrity while offering a smooth output even in noisy market conditions.
Source: John Ehlers – “Cybernetic Analysis for Stocks and Futures” (2004)

💮 3-Pole SuperSmoother
An extension of the 2-pole design, the 3-pole SuperSmoother further attenuates high-frequency noise. Its additional pole delivers enhanced smoothing at the cost of slightly increased lag.
Source: John Ehlers – “Cybernetic Analysis for Stocks and Futures” (2004)

💮 Adaptive Directional Volatility Moving Average (ADXVma)
This adaptive moving average adjusts its smoothing factor based on directional volatility. By combining true range and directional movement measurements, it remains exceptionally flat during ranging markets and responsive during directional moves.
Source: Various implementations across platforms, unified and optimized

💮 Ehlers Combined Bandpass Filter with Automated Gain Control (AGC)
This sophisticated filter merges a highpass pre-processing stage with a bandpass filter. An integrated Automated Gain Control normalises the output to a consistent range, while offering both regular and truncated recursive formulations to manage lag.
Source: John F. Ehlers – “Truncated Indicators” (2020), “Cycle Analytics for Traders” (2013)

💮 Voss Predictive Filter
A forward-looking filter that predicts future values of a band-limited signal in real time. By utilising multiple time-delayed feedback terms, it provides anticipatory coupling and delivers a short-term predictive signal.
Source: John Ehlers - "A Peek Into The Future" (TASC 2019-08)

💮 Adaptive Autonomous Recursive Moving Average (A2RMA)
This filter dynamically adjusts its smoothing through an adaptive mechanism based on an efficiency ratio and a dynamic threshold. A double application of an adaptive moving average ensures both responsiveness and stability in volatile and ranging markets alike. Very flat response when properly tuned.
Source: alexgrover (2019)

💮 Ultimate Smoother (2-Pole)
The Ultimate Smoother filter is engineered to achieve near-zero lag in its passband by subtracting a high-pass response from an all-pass response. This creates a filter that maintains signal fidelity at low frequencies while effectively filtering higher frequencies at the expense of slight overshooting.
Source: John Ehlers - TASC 2024-04 "The Ultimate Smoother"



Note: This library is actively maintained and enhanced. Suggestions for additional filters or improvements are welcome through the usual channels. The source code contains a list of tested filters that did not make it into the curated collection.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.