INVITE-ONLY SCRIPT

Cycle Spectrum Analyzer

267
Cycle Spectrum Indicator — Short Description

This indicator computes a visual Fourier cycle spectrum from the input price data to reveal the market’s dominant cyclical behaviour. The price series is first detrended using a Hodrick–Prescott filter, after which a specialized Fourier analysis variant extracts the cycle components.

The resulting spectrum displays peaks that represent the dominant cycles present in the data, where each peak’s cycle length and amplitude indicate the strength and duration of the underlying rhythm. The most significant peaks are ranked, highlighting the top cycles currently driving market movement. Each detected cycle also includes a phase value, describing the cycle’s position at the most recent bar (e.g., topping, bottoming, rising, falling).

The indicator can be used to:
  1. Identify the top 3 dominant cycles with their length and phase.
  2. Analyze the current market state by interpreting these phases.
  3. Feed the dominant cycle lengths—often half the primary cycle—into other technical indicators for improved parameter tuning.
  4. Project cycles forward to estimate upcoming turning points and anticipate potential trend shifts.

Additional Explanation of the included visual example image

Left Area – The Theoretical “Perfect Cycle”
The left part of the illustration presents a theoretical, perfectly smooth sine-wave cycle. This serves as a reference model to explain the core cycle parameters:
  • Cycle Length – The full wavelength of one complete oscillation (from trough to trough or peak to peak).
  • Phase – The current position within that cycle, expressed both numerically and as an easy-to-read text label such as Bottom_Departure, Uptrend_Neutral, Approaching Top, or Top_Departure.
The diagram highlights visually how a cycle progresses through bottoming, rising, peaking, and declining phases, matching the phase descriptions used in the indicator’s output. This helps translate raw phase angles into intuitive market-state labels (e.g., recovery, boom, topping, recession).

Right Area – The Price Series Used for Analysis

On the right, the actual price chart (e.g., Dow Jones Industrial Average) is displayed. This is the dataset from which the Fourier cycle spectrum is computed.

At the bottom of this chart section, a purple bar indicates the amount of historical data included in the cycle analysis. Because Fourier-based methods depend strongly on sample size, this visual cue shows how far back the indicator collected and processed data before generating the spectrum.

Bottom Area – The Cycle Spectrum Output Pane

The lower pane contains the Cycle Spectrum Analyzer output:
  • It displays the cycle spectrum at the most recent bar, where each green peak corresponds to a detected cycle.
  • Peak height = amplitude (strength) of the cycle
  • Peak position (horizontal) = dominant cycle length
  • The largest peaks represent the strongest cycles currently present in the detrended price series.
Next to the spectrum, a ranked table lists the Top 3 dominant cycles, showing:
  • Rank (1 = strongest)
  • Cycle Length (in bars)
  • Phase Description (interpreting where that cycle is right now)
This concise summary allows users to quickly understand:
  • Which cycles are strongest,
  • How long they are,
  • And whether they are currently bottoming, topping, rising, or falling.
How the Indicator Works & How It Can Be Adjusted

Calculation Only at the Last Bar
The indicator performs its full Fourier-based cycle decomposition exclusively on the most recent bar. This ensures that the spectrum always reflects the current market state without repeatedly recalculating historical spectra. The result is an efficient, real-time snapshot of the dominant cycles influencing the price at the latest point in time.

Works on Any Symbol and Any Timeframe
Because the analysis operates directly on the provided price series, the indicator is compatible with all markets and all timeframes—stocks, indices, forex, crypto, futures, and intraday charts alike.
The detected cycle lengths always refer to the selected chart’s bar interval (e.g., 240-bar cycle on a 1h chart ≈ 240 hours; same cycle on a daily chart ≈ 240 days).

Adjustable Historical Lookback (Default: 1100 Bars)
The accuracy of cycle detection depends on the amount of historical data used. The indicator provides a parameter allowing you to specify how many past bars should be included in the Fourier calculation.
  • Standard value: 1100 bars
  • Increasing the lookback allows detection of longer cycles, but may dilute short-term characteristics.
  • Decreasing it focuses on shorter and medium-term cycles, increasing responsiveness but reducing visibility of long-duration rhythms.
By tuning this lookback parameter and choosing an appropriate timeframe, traders can adapt the cycle spectrum to match their analytical style—short-term, medium-term, or long-term cycle interpretation.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.