OPEN-SOURCE SCRIPT
Garman-Klass-Yang-Zhang Regime Map [forexobroker]

Garman-Klass-Yang-Zhang Regime Map [forexobroker] combines three of the most efficient single-bar volatility estimators — the overnight gap return, the open-to-close drift term, and Rogers-Satchell intraday variance — into one GKYZ sigma with a drift-correction constant k. Each bar's GKYZ value is then ranked against its rolling 100-bar percentile and the regime is colored Low (green), Medium (yellow), or High (red) directly on the price chart. The unique angle is using a research-grade variance estimator instead of plain ATR, then trading the transitions — not the levels — of the regime ribbon.
🔶 ALGORITHM
1. Three components per bar: overnight gap log(open/prev close)^2, open-to-close log(close/open)^2, Rogers-Satchell log(H/C) log(H/O) + log(L/C) log(L/O).
2. Drift-correction k = 0.34 / (1.34 + (N+1)/(N-1)) (Yang-Zhang scaling); GKYZ per-bar variance = gap + k oc + (1-k) RS.
3. Rolling GKYZ variance over volatility window (default 20) divided by N, then sqrt; this is sigma_GKYZ.
4. Sigma_GKYZ is ranked across a percentile window (default 100); thresholds default to 33 and 66.
5. Regime classification: Low if below 33rd percentile, Medium if between, High if above 66th.
6. Signals fire on transitions, not on levels: a Low->Medium->High ladder over three confirmed bars is a momentum-direction breakout entry; a High-then-Low contraction (regime hit 2 within the last five bars and is now 0) is a counter-momentum mean-reversion entry.
🔶 SIGNAL LOGIC
- Buy: (Low->Medium->High three-bar ladder AND close > close[momentum lookback]) OR (recent High then current Low AND prior momentum was bearish) AND session filter passes AND position is not already long AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: (Low->Medium->High three-bar ladder AND close < close[momentum lookback]) OR (recent High then current Low AND prior momentum was bullish) AND session filter passes AND position is not already short AND cooldown bars elapsed AND barstate.isconfirmed.
The ladder is a breakout pattern, the spike-back is a mean-reversion pattern, both gated by direction.
🔶 INPUTS
- GKYZ Calculation group: volatility window default 20, percentile window default 100, Low/High percentile defaults 33/66.
- Signal Logic group: momentum lookback default 5, cooldown bars default 15.
- Filters group: session restriction (default 0000-2400).
- Visual group: regime ribbon toggle, dashboard, 3-layer glow, three regime colors, buy and sell colors.
🔶 ALERTS
GKYZ Buy, GKYZ Sell, GKYZ Any Signal, GKYZ Enter High, GKYZ Enter Low, GKYZ Ladder Up, GKYZ Spike Back, GKYZ Regime Change, GKYZ Vol Up, GKYZ Vol Down, GKYZ Webhook JSON.
🔶 LIMITATIONS
- GKYZ assumes log-OHLC are jointly normal; very large gaps or limit moves can produce occasional outliers that dominate the variance term.
- The percentile window classifies the current bar relative to a 100-bar history; on a brand-new regime that lasts longer than the window, the script will eventually re-rank the new baseline and stop firing fresh entries.
- The ladder pattern needs three consecutive confirmed bars to transition Low->Medium->High; sharp single-bar moves that skip Medium will not fire that path.
- Defaults are tuned for NQ and other index futures on intraday timeframes; instruments with persistent overnight gaps inflate the gap term and bias the regime high.
- The spike-back path uses the highest regime over the last five bars, so an isolated High bar followed by a brief retracement can register as a contraction even if the broader regime is still elevated.
🔶 ALGORITHM
1. Three components per bar: overnight gap log(open/prev close)^2, open-to-close log(close/open)^2, Rogers-Satchell log(H/C) log(H/O) + log(L/C) log(L/O).
2. Drift-correction k = 0.34 / (1.34 + (N+1)/(N-1)) (Yang-Zhang scaling); GKYZ per-bar variance = gap + k oc + (1-k) RS.
3. Rolling GKYZ variance over volatility window (default 20) divided by N, then sqrt; this is sigma_GKYZ.
4. Sigma_GKYZ is ranked across a percentile window (default 100); thresholds default to 33 and 66.
5. Regime classification: Low if below 33rd percentile, Medium if between, High if above 66th.
6. Signals fire on transitions, not on levels: a Low->Medium->High ladder over three confirmed bars is a momentum-direction breakout entry; a High-then-Low contraction (regime hit 2 within the last five bars and is now 0) is a counter-momentum mean-reversion entry.
🔶 SIGNAL LOGIC
- Buy: (Low->Medium->High three-bar ladder AND close > close[momentum lookback]) OR (recent High then current Low AND prior momentum was bearish) AND session filter passes AND position is not already long AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: (Low->Medium->High three-bar ladder AND close < close[momentum lookback]) OR (recent High then current Low AND prior momentum was bullish) AND session filter passes AND position is not already short AND cooldown bars elapsed AND barstate.isconfirmed.
The ladder is a breakout pattern, the spike-back is a mean-reversion pattern, both gated by direction.
🔶 INPUTS
- GKYZ Calculation group: volatility window default 20, percentile window default 100, Low/High percentile defaults 33/66.
- Signal Logic group: momentum lookback default 5, cooldown bars default 15.
- Filters group: session restriction (default 0000-2400).
- Visual group: regime ribbon toggle, dashboard, 3-layer glow, three regime colors, buy and sell colors.
🔶 ALERTS
GKYZ Buy, GKYZ Sell, GKYZ Any Signal, GKYZ Enter High, GKYZ Enter Low, GKYZ Ladder Up, GKYZ Spike Back, GKYZ Regime Change, GKYZ Vol Up, GKYZ Vol Down, GKYZ Webhook JSON.
🔶 LIMITATIONS
- GKYZ assumes log-OHLC are jointly normal; very large gaps or limit moves can produce occasional outliers that dominate the variance term.
- The percentile window classifies the current bar relative to a 100-bar history; on a brand-new regime that lasts longer than the window, the script will eventually re-rank the new baseline and stop firing fresh entries.
- The ladder pattern needs three consecutive confirmed bars to transition Low->Medium->High; sharp single-bar moves that skip Medium will not fire that path.
- Defaults are tuned for NQ and other index futures on intraday timeframes; instruments with persistent overnight gaps inflate the gap term and bias the regime high.
- The spike-back path uses the highest regime over the last five bars, so an isolated High bar followed by a brief retracement can register as a contraction even if the broader regime is still elevated.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.