OPEN-SOURCE SCRIPT

Frequency Momentum Oscillator [QuantAlgo]

1 069
🟢 Overview

The Frequency Momentum Oscillator applies Fourier-based spectral analysis principles to price action to identify regime shifts and directional momentum. It calculates Fourier coefficients for selected harmonic frequencies on detrended price data, then measures the distribution of power across low, mid, and high frequency bands to distinguish between persistent directional trends and transient market noise. This approach provides traders with a quantitative framework for assessing whether current price action represents meaningful momentum or merely random fluctuations, enabling more informed entry and exit decisions across various asset classes and timeframes.
imagen
🟢 How It Works

The calculation process removes the dominant trend from price data by subtracting a simple moving average, isolating cyclical components for frequency analysis:
Pine Script®
detrendedPrice = close[dataOffset] - ta.sma(close[dataOffset], frequencyPeriod)

The detrended price series undergoes frequency decomposition through Fourier coefficient calculation across the first 8 harmonics. For each harmonic frequency, the algorithm computes sine and cosine components across the lookback window, then derives power as the sum of squared coefficients:
Pine Script®
for k = 1 to 8 cosSum = 0.0 sinSum = 0.0 for n = 0 to frequencyPeriod - 1 angle = 2 * math.pi * k * n / frequencyPeriod cosSum := cosSum + detrendedPrice[n] * math.cos(angle) sinSum := sinSum + detrendedPrice[n] * math.sin(angle) power = (cosSum * cosSum + sinSum * sinSum) / frequencyPeriod

Power measurements are aggregated into three frequency bands: low frequencies (harmonics 1-2) capturing persistent cycles, mid frequencies (harmonics 3-4), and high frequencies (harmonics 5-8) representing noise. Each band's power normalizes against total spectral power to create percentage distributions:
Pine Script®
lowFreqNorm = totalPower > 0 ? (lowFreqPower / totalPower) * 100 : 33.33 highFreqNorm = totalPower > 0 ? (highFreqPower / totalPower) * 100 : 33.33

The normalized frequency components undergo exponential smoothing before calculating spectral balance as the difference between low and high frequency power:
Pine Script®
smoothLow = ta.ema(lowFreqNorm, smoothingPeriod) smoothHigh = ta.ema(highFreqNorm, smoothingPeriod) spectralBalance = smoothLow - smoothHigh

Spectral balance combines with price momentum through directional multiplication, producing a composite signal that integrates frequency characteristics with price direction:
Pine Script®
momentum = ta.change(close[dataOffset], frequencyPeriod/2) compositeSignal = spectralBalance * math.sign(momentum) finalSignal = ta.ema(compositeSignal, smoothingPeriod)

The final signal oscillates around zero, with positive values indicating low-frequency dominance coupled with upward momentum (trending up), and negative values indicating either high-frequency dominance (choppy market) or downward momentum (trending down).

🟢 How to Use This Indicator

→ Long/Short Signals: the indicator generates long signals when the smoothed composite signal crosses above zero (indicating low-frequency directional strength dominates) and short signals when it crosses below zero (indicating bearish momentum persistence).
imagen
→ Upper and Lower Reference Lines: the +25 and -25 reference lines serve as threshold markers for momentum strength. Readings beyond these levels indicate strong directional conviction, while oscillations between them suggest consolidation or weakening momentum. These references help traders distinguish between strong trending regimes and choppy transitional periods.

→ Preconfigured Presets: three optimized configurations are available with Default (32, 3) offering balanced responsiveness, Fast Response (24, 2) designed for scalping and intraday trading, and Smooth Trend (40, 5) calibrated for swing trading and position trading with enhanced noise filtration.

→ Built-in Alerts: the indicator includes three alert conditions for automated monitoring - Long Signal (momentum shifts bullish), Short Signal (momentum shifts bearish), and Signal Change (any directional transition). These alerts enable traders to receive real-time notifications without continuous chart monitoring.

→ Color Customization: four visual themes (Classic green/red, Aqua blue/orange, Cosmic aqua/purple, Custom) allow chart customization for different display environments and personal preferences.
imagen
imagen
imagen

Exención de responsabilidad

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.