Adaptive Fourier Transform CCI [QuantAlgo]🟢 Overview
The Adaptive Fourier Transform CCI reimagines the classic Commodity Channel Index by replacing its fixed lookback period with one that continuously adjusts to the market's own rhythm. Rather than measuring price deviation against an arbitrary static length, it first isolates the cyclical component of price action through a Discrete Fourier Transform, identifies which cycle period currently holds the most spectral energy, and then tunes the CCI calculation to that dominant period. The result is a momentum oscillator calibrated to the frequency structure of the instrument being traded, naturally tightening during fast, high-frequency regimes and widening during slower, drawn-out cycles without requiring manual timeframe adjustments.
🟢 How It Works
Before any cycle detection occurs, raw price is conditioned through two sequential filters. A high-pass filter strips the slow-moving trend component from the close, leaving only the oscillating portion of price action:
hp := 0.5 * (1 + a1) * (close - close ) + a1 * hp
That residual is then passed through a Super Smoother filter, which removes short-term noise from the cycle signal without introducing the lag that standard moving averages add at this stage:
filt := c1 * (hp + hp ) / 2 + c2 * filt + c3 * filt
This cleaned signal is what the Discrete Fourier Transform (DFT) operates on. The DFT scans across a range of candidate cycle periods and measures how much price energy is concentrated at each one. The period where that energy is strongest is selected as the dominant cycle. An EMA smooths the period output to prevent erratic length switching between bars, and the result is scaled by the Length Multiplier to derive the final adaptive CCI lookback:
adaptiveLen = clamp(round(dominantPeriod × lengthMult), 5, 60)
The CCI is then calculated using the standard Lambert formula over that adaptive length, measuring how far typical price has deviated from its mean relative to its average absolute deviation. An optional output smoothing MA reduces bar-to-bar noise before the final value is plotted.
🟢 Signal Interpretation
▶ Overbought (Above Upper Level, Red): When the Adaptive Fourier Transform CCI (AFT-CCI) rises above the upper threshold, price has deviated significantly above its cycle-adaptive mean. The reading reflects momentum extended relative to the market's current detected rhythm rather than a fixed arbitrary baseline. The signal carries more weight when the dominant cycle is stable and the DFT is locked onto a consistent frequency rather than switching between periods.
▶ Oversold (Below Lower Level, Green): When the AFT-CCI falls below the lower threshold, price has moved an equivalent distance below its cycle-adaptive mean. In strongly trending conditions the AFT-CCI can remain in either zone for extended periods, so the threshold levels should be read as zones of extension rather than automatic reversal points.
▶ Neutral Zone (Between Levels, Grey): When the AFT-CCI sits between the upper and lower thresholds, price deviation relative to the detected cycle is within normal range. Zero-line crosses within this zone indicate the adaptive mean is being reclaimed, which can serve as early directional context before a full threshold break develops.
▶ Zero Line: The zero line represents the adaptive mean itself. A cross above zero indicates typical price has moved above the cycle-adaptive mean; a cross below indicates the opposite. These crosses are lower-conviction reads on their own but become more meaningful when followed by a threshold break in the same direction.
🟢 Features
▶ Preconfigured Presets: Two parameter sets sit alongside the default configuration. "Fast Response" compresses the DFT window and cycle search range while raising the length multiplier, producing faster adaptation suited to intraday charts from 5-minute to 1-hour. "Smooth Trend" expands the window and search range while lowering the multiplier, establishing a more stable cycle read suited to daily and weekly position trading.
▶ Built-in Alerts: Six alert conditions cover the full range of meaningful oscillator events. Separate alerts fire on entering and exiting both overbought and oversold territory, capturing threshold breaks in both directions. Two additional alerts trigger on bullish and bearish zero-line crosses, enabling directional monitoring without requiring constant chart observation.
▶ Visual Customisation: Six colour presets, Classic, Aqua, Cosmic, Cyber, Neon, and Custom, apply consistently across the signal line, glow layers, and threshold level lines so the overbought and oversold colours remain coherent regardless of which preset is active. The optional neon glow effect uses three layered plots at increasing transparency to give the signal line visual depth and make threshold breaks immediately readable at a glance.
อินดิเคเตอร์ Pine Script®






















