OPEN-SOURCE SCRIPT
Goertzel Algorithm [LB]

🔬 Concept
The Goertzel Algorithm, developed by Gerald Goertzel in 1958, is a digital signal processing technique that efficiently computes individual terms of the Discrete Fourier Transform (DFT). Unlike a full FFT which calculates all frequency bins, the Goertzel Algorithm targets a single predetermined frequency — making it the optimal tool for detecting the presence and power of a specific cycle period within a price series.
📐 Mathematical Foundation
The algorithm implements a second‑order recursive filter with a resonance at the target frequency. For a target period T, the normalized angular frequency is :
ω = 2π / T
The recurrence relation is applied to each sample x[n] in the window :
Q[n] = x[n] + 2·cos(ω)·Q[n-1] - Q[n-2]
After processing N samples, the complex DFT coefficient is extracted without storing intermediate values :
Re = Q[N-1] - Q[N-2]·cos(ω)
Im = Q[N-2]·sin(ω)
The output is the squared magnitude (power) of that frequency component :
Power = Re² + Im²
This approach requires only one multiply and two additions per sample, making it substantially lighter than a full FFT when monitoring a single cycle.
🎯 What Problem Does It Solve ?
Classic oscillators and moving averages operate blindly across all frequencies, mixing signal and noise. FFT‑based indicators attempt spectral analysis but compute hundreds of unnecessary frequency bins, wasting computational resources and introducing lag. The Goertzel Algorithm isolates the exact cycle period the trader wants to monitor, delivering pure frequency‑domain intelligence with minimal overhead.
📊 How To Interpret
Power rising and sustained at high levels → the target cycle period is strongly present in the price action ; the market is respecting the chosen rhythm.
Power declining toward zero → the target cycle has faded ; the market is no longer oscillating at that frequency.
Sharp power spike → the cycle has suddenly emerged ; potential entry signal when a known period (e.g., 20‑bar) becomes active.
Compare multiple instances with different periods → add the indicator twice with different target periods (e.g., 10 and 20 bars) to see which cycle dominates.
⚙️ Parameters
Target Period (bars) – the exact cycle length to detect ; typical values are 10, 20, 50, or any dominant cycle observed on the chart.
Analysis Window Length – number of bars over which the algorithm computes the power ; longer windows give more frequency resolution but slower response.
Source – price data used as input (close, HLC3, etc.).
📚 Reference
Goertzel G., "An Algorithm for the Evaluation of Finite Trigonometric Series", The American Mathematical Monthly, Vol. 65, No. 1, pp. 34‑35, January 1958.
Proakis J.G. & Manolakis D.G., "Digital Signal Processing : Principles, Algorithms, and Applications", Chapter 6 – Efficient Computation of the DFT, Prentice Hall, 1996.
The Goertzel Algorithm, developed by Gerald Goertzel in 1958, is a digital signal processing technique that efficiently computes individual terms of the Discrete Fourier Transform (DFT). Unlike a full FFT which calculates all frequency bins, the Goertzel Algorithm targets a single predetermined frequency — making it the optimal tool for detecting the presence and power of a specific cycle period within a price series.
📐 Mathematical Foundation
The algorithm implements a second‑order recursive filter with a resonance at the target frequency. For a target period T, the normalized angular frequency is :
ω = 2π / T
The recurrence relation is applied to each sample x[n] in the window :
Q[n] = x[n] + 2·cos(ω)·Q[n-1] - Q[n-2]
After processing N samples, the complex DFT coefficient is extracted without storing intermediate values :
Re = Q[N-1] - Q[N-2]·cos(ω)
Im = Q[N-2]·sin(ω)
The output is the squared magnitude (power) of that frequency component :
Power = Re² + Im²
This approach requires only one multiply and two additions per sample, making it substantially lighter than a full FFT when monitoring a single cycle.
🎯 What Problem Does It Solve ?
Classic oscillators and moving averages operate blindly across all frequencies, mixing signal and noise. FFT‑based indicators attempt spectral analysis but compute hundreds of unnecessary frequency bins, wasting computational resources and introducing lag. The Goertzel Algorithm isolates the exact cycle period the trader wants to monitor, delivering pure frequency‑domain intelligence with minimal overhead.
📊 How To Interpret
Power rising and sustained at high levels → the target cycle period is strongly present in the price action ; the market is respecting the chosen rhythm.
Power declining toward zero → the target cycle has faded ; the market is no longer oscillating at that frequency.
Sharp power spike → the cycle has suddenly emerged ; potential entry signal when a known period (e.g., 20‑bar) becomes active.
Compare multiple instances with different periods → add the indicator twice with different target periods (e.g., 10 and 20 bars) to see which cycle dominates.
⚙️ Parameters
Target Period (bars) – the exact cycle length to detect ; typical values are 10, 20, 50, or any dominant cycle observed on the chart.
Analysis Window Length – number of bars over which the algorithm computes the power ; longer windows give more frequency resolution but slower response.
Source – price data used as input (close, HLC3, etc.).
📚 Reference
Goertzel G., "An Algorithm for the Evaluation of Finite Trigonometric Series", The American Mathematical Monthly, Vol. 65, No. 1, pp. 34‑35, January 1958.
Proakis J.G. & Manolakis D.G., "Digital Signal Processing : Principles, Algorithms, and Applications", Chapter 6 – Efficient Computation of the DFT, Prentice Hall, 1996.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.