PROTECTED SOURCE SCRIPT

Phase Coherence Index (PCI) — Hilbert Prototype v0.1

26
Phase Coherence Index (PCI) — Hilbert Prototype v0.1

✨ Concept:
The Phase Coherence Index (PCI) measures the degree of phase alignment among multiple trend components derived from band-filtered price signals.
In simpler terms, PCI quantifies how “in-sync” short, mid, and long-term market oscillations are.

A high PCI (values near 100) means the market’s cyclical components are moving together — a state of phase alignment that typically accompanies sustained, directional trends.
A low PCI (values near 0) indicates phase disorder or divergence between timeframes — often seen during transitions, chop, or volatility compression phases.

✨ How it works:

1. Multi-Band Extraction
The price series is decomposed into three frequency bands using a simple EMA-difference

bandpass filter:
  • Short-term band
  • Mid-term band
  • Long-term band


2. Hilbert Quadrature Approximation
For each band, a Hilbert-style quadrature signal (Q) is estimated using an Ehlers-inspired FIR kernel with coefficients h0=0.0962 and h1=0.5769.
The original bandpass (I) and its quadrature (Q) form a complex phasor that carries instantaneous phase information.

3. Phase Extraction
The arctangent of Q/I gives the phase angle (−π to π).
Each band’s phase represents the “timing” of its oscillation relative to price movement.

4. Coherence Calculation

All three band phases are converted to unit phasors (cos φ, sin φ).
The average of these phasors is taken, and the magnitude of the resulting vector defines the PCI value:

PCI = |mean_phasor| × 100

  • PCI = 100 → perfect phase alignment
  • PCI = 0 → complete phase randomness


5. Smoothing and Regime Coloring

The raw PCI is lightly smoothed by EMA to stabilize readings.
A simple SuperTrend regime filter (ATR length 5, factor 6) colors the PCI line:

  • Green: uptrend regime
  • Red: downtrend regime
  • Gray: low-coherence or neutral zone


✨ How to interpret PCI

High PCI (≥70):
  • Indicates strong phase coherence — multi-timeframe alignment, stable directional energy.
  • Often coincides with trend persistence or mature momentum phases.


Low PCI (≤30):
  • Suggests phase dispersion or regime transition — signals are desynchronized across bands.
  • Common near reversals, volatility compressions, or sideways congestion.


Cross-phase Transitions:
  • Rapid drops in PCI often precede periods of uncertainty or trend fatigue.
  • Rising PCI after a contraction suggests emerging order or trend formation.


✨ Visualization
PCI Line:
Displays phase coherence magnitude (0–100).
Color changes dynamically with SuperTrend regime.

Dotted Reference Levels:
70 (high coherence), 30 (low coherence), 50 (midline).

Optional Label:
When PCI is high, a text label appears indicating whether the average phase bias leans bullish or bearish.

✨ Practical Use
  • Combine PCI with momentum or volatility tools (e.g., RSI, ATR, DFI) to detect when multiple timeframes become synchronized.
  • Use PCI drops (<30) as early warnings for possible trend exhaustion or market disorder.
  • Use PCI rises (>70) as confirmation of trend continuation or emerging coherence.


✨ Limitations
  • PCI measures phase alignment, not directional bias. It should be combined with a directional filter (e.g., SuperTrend, slope, or moving average).
  • The Hilbert approximation is not a true analytic signal, but a real-time proxy optimized for stability.
  • PCI is best interpreted as a structural context indicator rather than a direct entry signal.



✨ Educational intent
This script is designed for quantitative study and visualization of phase alignment, not for direct trading advice.
It demonstrates how Hilbert-style phasors and vector averaging can reveal coherence across timescales — a foundational concept for spectral, cyclical, and structural analysis.


✨ Disclaimer
This script is provided for educational purposes only.
It does not constitute financial advice.
Trading involves risk; use at your own discretion.


© 2025 Trading Playground Labs — “Phase Coherence Index (Hilbert Prototype v0.1)

───────────────────────────────
📘 한국어 설명 (Korean translation below)
───────────────────────────────

Phase Coherence Index (PCI) — Hilbert Prototype v0.1 (한국어 설명)

✨ 개념

Phase Coherence Index (PCI) 는 여러 주기의 추세 구성 요소들 간에 위상의 정합 정도를 측정하는 지표입니다.
쉽게 말하면, 시장의 단기·중기·장기 진동(사이클)들이 서로 얼마나 “같은 박자”로 움직이는지를 수치화한 것입니다.

PCI 값이 100에 가까울수록 시장의 주기적 구성 요소들이 함께 움직이고 있다는 뜻이며,
이는 일반적으로 지속적인 방향성 추세(trend persistence) 상태를 의미합니다.
반대로 PCI 값이 0에 가까울수록 각 주기의 움직임이 서로 엇박자 상태로 흐르며,
이는 전환기(chop), 혼돈(chaos), 혹은 압축(squeeze) 상태를 반영합니다.

✨ 작동 원리

1. 다중 밴드 추출

가격 데이터를 3개의 주파수 대역으로 분리합니다.

  • 단기 (short-term band)
  • 중기 (mid-term band)
  • 장기 (long-term band)


각 대역은 빠른 EMA와 느린 EMA의 차이(EMA difference)로 얻은 단순한 밴드패스로 계산됩니다.

2. Hilbert 직교 성분 근사

각 밴드에 대해 Ehlers 계열 FIR 필터를 이용한 Hilbert 근사 신호(Q)를 계산합니다.
원본 밴드패스 신호(I)와 Q를 결합하면 복소 위상(phasor) 를 구성할 수 있고,
이를 통해 각 대역의 순간 위상(instantaneous phase) 을 추정합니다.

3. 위상 계산
Q/I의 아크탄젠트 값을 구하면 위상각 φ(−π ~ π)가 도출됩니다.
이 위상은 해당 주기의 진동 타이밍을 나타냅니다.

4. 위상 정합(Phase Coherence) 계산
각 밴드의 위상을 단위 페이저 벡터 (cos φ, sin φ)로 변환합니다.
세 벡터의 평균을 구하고, 그 평균 벡터의 크기를 0~100 스케일로 변환한 값이 PCI입니다.

PCI = |평균 페이저| × 100

  • PCI = 100 → 완전한 위상 일치
  • PCI = 0 → 완전한 위상 무질서


5. 스무딩 및 추세 컬러링
계산된 PCI는 EMA로 약간 평활화되어 안정적으로 표시됩니다.
또한, SuperTrend 레짐 필터(ATR=5, Factor=6) 로 추세 방향에 따라 색이 바뀝니다:

  • 초록색: 상승 추세
  • 빨간색: 하락 추세
  • 회색: 저정합 / 중립 구간



✨ 해석 방법

PCI ≥ 70 (높은 정합)
여러 타임프레임이 같은 방향으로 동기화되어 있는 상태입니다.
이는 추세 지속성, 모멘텀 유지, 구조적 안정 상태를 의미합니다.

PCI ≤ 30 (낮은 정합)
각 주기 간 위상 불일치가 심해지며, 시장이 방향을 잃거나 변곡점에 근접한 상황입니다.
보통 조정기, 변동성 축소, 횡보 국면에서 자주 나타납니다.

급격한 변동 (Phase Transition)
PCI가 급격히 하락하는 구간은 추세 피로(trend fatigue) 또는 혼돈 국면 진입의 신호일 수 있으며,
이후 PCI가 상승하기 시작하면 새로운 질서(추세 형성) 가 시작될 가능성을 의미합니다.


✨ 시각화 구성

PCI 라인:
위상 정합도의 크기(0~100)를 표시합니다.
SuperTrend 방향에 따라 색이 동적으로 변합니다.

점선 기준선:
70(높은 정합), 50(중간), 30(낮은 정합) 기준으로 시각화됩니다.

평균 위상 라벨:
PCI가 높을 때, 평균 위상의 방향이 상승(bullish) 인지 하락(bearish) 인지를 라벨로 표시합니다.


✨ 활용 방법

  • RSI, ATR, DFI 등 다른 모멘텀/변동성 지표와 함께 사용하면, 복수 타임프레임 동기화 구간을 탐지할 수 있습니다.
  • PCI 하락(30 이하)은 추세 피로 또는 혼돈 진입의 신호로, PCI 상승(70 이상)은 질서 회복 또는 추세 지속의 신호로 해석할 수 있습니다.
  • 추세 전환, 조정, 또는 모멘텀 재편성 구간을 감지하는 데 유용합니다.


✨ 한계점

  • PCI는 방향성(Direction)을 직접 측정하지 않고, 구조적 정합(Alignment) 만 측정합니다. 따라서 반드시 방향 필터(SuperTrend, MA 기울기 등)와 함께 해석해야 합니다.
  • Hilbert 근사는 완전한 복소 해석 신호가 아니라, 실시간 안정성을 중시한 근사 모델입니다.
  • PCI는 진입 시그널용보다는 시장 구조 인식용 보조 지표로 적합합니다.



✨ 교육적 목적

이 스크립트는 위상 정합(phase coherence) 개념의 시각화와 정량적 연구를 위한 목적으로 설계되었습니다.
힐버트 변환 기반 위상 벡터(phasor) 와 벡터 평균화(vector averaging) 의 개념을 통해
시장의 다중 시간 구조 간 일관성(coherence)을 탐색할 수 있습니다.


✨면책

이 지표는 교육 목적으로만 제공됩니다.
투자 조언이 아니며, 모든 트레이딩 결정의 책임은 사용자에게 있습니다.

© 2025 Trading Playground Labs — Phase Coherence Index (Hilbert Prototype v0.1)
Developed for structural & spectral analysis of market phase alignment.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.