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.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
🔵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.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
🔵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.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.