OPEN-SOURCE SCRIPT
Frequency Momentum Oscillator [QuantAlgo]

๐ข 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.

๐ข 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ยฎ
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ยฎ
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ยฎ
The normalized frequency components undergo exponential smoothing before calculating spectral balance as the difference between low and high frequency power:
Pine Scriptยฎ
Spectral balance combines with price momentum through directional multiplication, producing a composite signal that integrates frequency characteristics with price direction:
Pine Scriptยฎ
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).

โ 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.



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.
๐ข 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:
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:
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:
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:
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:
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).
โ 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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
๐ Access our best trading & investing tools here (3-day FREE trial): whop.com/quantalgo/
๐ฉ DM if you need any custom-built indicators or strategies.
๐ฉ DM if you need any custom-built indicators or strategies.
Disclaimer
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
๐ Access our best trading & investing tools here (3-day FREE trial): whop.com/quantalgo/
๐ฉ DM if you need any custom-built indicators or strategies.
๐ฉ DM if you need any custom-built indicators or strategies.
Disclaimer
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.