[Pine Script Implementation of HT_DCPHASE](https://github.com/mihakralj/pinescript/blob/main/indicators/cycles/ht_dcphase.pine)
## Overview and Purpose
The Hilbert Transform Dominant Cycle Phase (HT_DCPHASE) is an advanced cycle analysis indicator developed by John Ehlers that identifies the current phase position within the dominant market cycle. By applying Hilbert Transform mathematics to price data, this indicator extracts the phase angle of the dominant cycle, revealing where the market currently sits within its cyclical pattern. This information is invaluable for timing entries and exits, as it shows whether the cycle is in accumulation, markup, distribution, or markdown phases.
HT_DCPHASE works by computing the In-phase (I) and Quadrature (Q) components through Hilbert Transform analysis, then calculating the phase angle as the arctangent of Q/I. The result is a continuous phase measurement in radians ranging from -π to π, providing a precise indication of cycle position. This makes it particularly useful for identifying cycle turning points and anticipating trend changes before they become apparent in price action.
## Core Concepts
* **Phase Angle**: Measures position within cycle using arctangent of Q/I components; ranges from -π to π radians
* **Hilbert Transform**: Mathematical technique that creates 90-degree phase-shifted version of price for quadrature analysis
* **I and Q Components**: In-phase and Quadrature components represent cycle's position in two-dimensional phase space
* **Cycle Position**: Phase angle indicates whether market is in trough (-π), peak (0), or transition phases (±π/2)
* **Adaptive Bandwidth**: Uses dominant cycle period to adjust filter bandwidth for optimal detrending
## Common Settings and Parameters
| Parameter | Default | Function | When to Adjust |
**Pro Tip:** HT_DCPHASE is most effective when used in conjunction with HT_DCPERIOD to understand both the cycle length and current position. Phase crossings through zero often correspond to significant trend changes. The indicator works best on instruments with clear cyclical behavior - sideways or ranging markets provide cleaner signals than strongly trending markets.
## Calculation and Mathematical Foundation
**Simplified explanation:**
HT_DCPHASE applies Hilbert Transform mathematics to extract the phase angle of the dominant market cycle, indicating the current position within the cycle.
Where `Hilbert_FIR` is a finite impulse response filter with coefficients [0.0962, 0.5769, 0, -0.5769, -0.0962].
> 🔍 **Technical Note:** The phase calculation uses arctangent to convert the I and Q components from Cartesian to polar coordinates. The dominant cycle period (calculated from Re and Im) is used to adapt the filter bandwidth, ensuring the phase measurement tracks the actual market cycle rather than noise or shorter-term fluctuations.
## Interpretation Details
HT_DCPHASE provides cycle phase analysis through several interpretive lenses:
* **Phase Position:**
* Phase ≈ -π: Cycle trough (potential buy zone)
* Phase ≈ -π/2: Rising from trough (early uptrend)
* Phase ≈ 0: Cycle peak (potential sell zone)
* Phase ≈ π/2: Declining from peak (early downtrend)