PROTECTED SOURCE SCRIPT
GC1! H1 Stats+

GC1! H1 Stats - Detailed Prob & Excursion Indicator
Overview
GC1! H1 Stats - Detailed Prob & Excursion is a specialized statistical overlay indicator for TradingView, tailored for Gold futures (GC1!) on a 1-hour framework. It provides real-time insights into the probability of price returning to the hourly open after sweeping the previous hour’s high (PHH) or previous hour’s low (PHL), based on historical data segmented by hour (0–23) and 20-minute intervals. The indicator visualizes these sweeps with lines, labels, circles, background fills, and “excursion zones” (also called “Magic Boxes”) that highlight median/mean extensions post-sweep, along with percentile lines (75th / 90th / 95th) for gauging potential “pain” or extreme moves. This tool is designed for intraday Gold traders focusing on liquidity sweeps and mean-reversion behavior, helping to quantify edge using empirical probabilities and excursion statistics.
The data is hardcoded from extensive historical analysis of GC1! behavior (e.g., probabilities ranging roughly from ~7% to ~91%, with sample sizes up to 2000+ per segment), making it a backtested reference rather than a dynamic learning model. It emphasizes visual clarity during active hours, with options to filter for Regular Trading Hours (RTH: 09:00–15:59 ET) or high-probability (>70%) events only. Note: This is an educational tool for analyzing market structure; it does not predict future performance or provide trading signals/advice. Past data does not guarantee future results, and users should backtest on current conditions (as of December 2025 data availability) and use at their own risk, in compliance with TradingView’s house rules.
________________________________________
Key Features
• Sweep Detection & Probability Labels: Identifies when price breaks PHH (upside) or PHL (downside), displaying a centered label with probability of returning to the hourly open, sample size (N), time of sweep, and a checkmark (✅) if the open is retested post-sweep.
• Visual Lines & Markers: Draws hourly open (h.o.), PHH, and PHL lines with customizable styles/colors; adds small circles on sweep bars for quick spotting.
• Breakout→Open Background Fill: Shaded zone from sweep bar until price returns to open, visualizing extension duration and retracement.
• Excursion (Pain) Zone - “Magic Box”: Post-sweep box showing median/mean extension percentages, colored dynamically by probability (green high, orange mid, red low); includes dashed lines for 75th/90th/95th percentiles to mark statistical extremes.
• Time-Segmented Data: Probabilities and excursions vary by hour (0–23) and 20-min segments (0–19 min: _0, 20–39: _1, 40–59: _2), capturing intraday nuances (e.g., higher probs in early/late hours).
• Filters for Focus: RTH-only mode hides non-session elements; high-prob-only shows >70% events to reduce noise.
• Alerts: Triggers on PHH/PHL sweeps with messages for chart checks.
________________________________________
How It Works
• Data Foundation: Uses pre-computed maps for probabilities (prob_high_taken/prob_low_taken), sample sizes, and excursions (mean, median, p75/p90/p95 as percentages of open). Data is initialized on the first bar via f_init_high_data() and f_init_low_data(), covering 24 hours with 3 segments each (e.g., key "9_1" for 09:20–09:39). Probabilities represent historical likelihood of price returning to open after sweep; excursions quantify average/rare extensions (e.g., 0.156% mean = 0.156% of open price).
• Period Detection: On new 1H bars (new_period_bar), resets visuals, draws lines for open/PHH/PHL extending 1 hour forward, and labels if enabled. Uses request.security on standard ticker for real OHLC, bypassing chart transformations (e.g., Heikin Ashi).
• Sweep Logic: On each bar, checks if real high > PHH or real low < PHL. If so, fetches segment-specific data (hour + floor(minute/20)), displays probability label centered mid-hour. Skips if filtered (RTH-only or <70% prob).
• Excursion Visualization: If enabled, draws “Magic Box” from 1-min to 58-min into the hour, bounded by mean/median levels (top/bottom adjusted for high/low sweep). Adds percentile lines with labels (e.g., “75%”) at right end. Box color reflects prob strength for quick bias assessment.
• Retest Check: Monitors for open retest post-sweep (high/low cross open, or gap scenarios from prev bar). Adds ✅ to label if hit on subsequent bars (skips sweep bar to avoid false positives). Stops background fill on retest or at 58-min mark.
• Background Fill: Activates on sweep, shades until retest, using user color.
• Cleanup & Performance: Manages labels in arrays, clears on new periods; no excess drawing beyond max counts (500 lines/labels/boxes).
This setup blends statistical backtesting with real-time visualization: hardcoded data provides empirical probabilities/excursions (reducing subjectivity in breakouts), while dynamic elements (lines, fills, boxes) overlay structure on the chart. It helps Gold traders assess if a sweep is “high-edge” (e.g., >70% probability of reverting) or likely to run (low probability, high excursion), pairing historical context with current price action.
________________________________________
Settings and Customization
Inputs are grouped for ease:
1. Settings:
o Show RTH Only (9:00–15:59): Restricts to main session (default: false; tooltip: for RTH-focused stats).
o Show High Prob Only (>70%): Filters low-prob sweeps visually (default: false; tooltip: highlights confidence).
2. Visuals:
o Show Line Labels: Toggle “h.o.” / “phh” / “phl” (default: true).
o Period Open Line Color: Gray 50% (default).
o Previous High/Low Line Colors: Gray 100% (default).
o Open Line Style/Width: Dotted/1 (default; options: Solid/Dotted/Dashed).
3. Breakout→Open Background:
o Show Breakout→Open Background: Toggle fill (default: true).
o Fill Color: Teal 85% (default).
4. Breakout Circles:
o Show Breakout Circles: Toggle (default: true).
o PHH/PHL Break Circle Colors: White 20% (default).
5. Info Label Style:
o Text Size: Small (default; options: Auto/Tiny/Normal/Large/Huge).
o Label Text Color: White (default).
o Low/Mid/High Probability Colors: Red 20% / Orange 20% / Green 20% (default).
6. Excursion (Pain) Zone:
o Show Excursion Zone: Toggle Magic Box (default: true).
o Excursion Box Color: Gray 75% (default; dynamic overrides).
o 75th/90th/95th Percentile Lines: Orange 30% / Red 30% / Dark Red 100% (default).
No additional tables/plots; all elements are lines/labels/boxes for overlay focus.
________________________________________
Usage Tips
• Breakout Trading: Watch for sweeps with high probability (>70%, green label) as potential fades back to open; low probability (red) may signal runs—use the excursion box for targets (e.g., exit at 90th percentile for extremes).
• Time Awareness: Probabilities often peak in key liquidity windows and drop in quieter hours; segments capture momentum shifts (e.g., _2 often lower prob).
• RTH Focus: Enable for cleaner stats during high-liquidity session hours; disable for a 24-hour view.
• Visual Filtering: Use high-prob-only in volatile conditions to reduce noise; combine with volume or other confluence tools for confirmation.
• Alerts Integration: Set TradingView alerts on sweeps; check label for probability/N before acting.
• Chart Setup: Best on 1H or lower GC1! charts; adjust text size for readability on smaller screens.
• Backtesting: Manually review historical sweeps against data maps to validate; update hardcoded values if new data emerges (as of 2025).
________________________________________
Limitations
• Fixed Data: Hardcoded stats may not reflect recent market changes (e.g., post-2025 regime shifts); not adaptive.
• Reactive Only: Detects sweeps after they occur; no predictive signals.
• Timeframe Specific: Locked to 1H logic; may not translate to other assets/timeframes without recoding data.
• Visual Clutter: On busy charts, labels/boxes may overlap—toggle selectively.
• No Live Stats: Sample sizes are historical; real-time N/prob not updated.
• Gaps & Extremes: Handles gaps in retest logic, but rare events (e.g., macro news) may exceed the 95th percentile.
________________________________________
Disclaimer
This indicator is for informational and educational purposes only. Trading involves significant risk of loss and is not suitable for all investors. The hardcoded data represents past Gold futures (GC1!) performance and does not guarantee future outcomes. No claims of profitability are made—results depend on market conditions, user strategy, and risk management. Consult a financial advisor before trading, and backtest extensively. Abiding by TradingView rules, this tool provides no investment recommendations.
Overview
GC1! H1 Stats - Detailed Prob & Excursion is a specialized statistical overlay indicator for TradingView, tailored for Gold futures (GC1!) on a 1-hour framework. It provides real-time insights into the probability of price returning to the hourly open after sweeping the previous hour’s high (PHH) or previous hour’s low (PHL), based on historical data segmented by hour (0–23) and 20-minute intervals. The indicator visualizes these sweeps with lines, labels, circles, background fills, and “excursion zones” (also called “Magic Boxes”) that highlight median/mean extensions post-sweep, along with percentile lines (75th / 90th / 95th) for gauging potential “pain” or extreme moves. This tool is designed for intraday Gold traders focusing on liquidity sweeps and mean-reversion behavior, helping to quantify edge using empirical probabilities and excursion statistics.
The data is hardcoded from extensive historical analysis of GC1! behavior (e.g., probabilities ranging roughly from ~7% to ~91%, with sample sizes up to 2000+ per segment), making it a backtested reference rather than a dynamic learning model. It emphasizes visual clarity during active hours, with options to filter for Regular Trading Hours (RTH: 09:00–15:59 ET) or high-probability (>70%) events only. Note: This is an educational tool for analyzing market structure; it does not predict future performance or provide trading signals/advice. Past data does not guarantee future results, and users should backtest on current conditions (as of December 2025 data availability) and use at their own risk, in compliance with TradingView’s house rules.
________________________________________
Key Features
• Sweep Detection & Probability Labels: Identifies when price breaks PHH (upside) or PHL (downside), displaying a centered label with probability of returning to the hourly open, sample size (N), time of sweep, and a checkmark (✅) if the open is retested post-sweep.
• Visual Lines & Markers: Draws hourly open (h.o.), PHH, and PHL lines with customizable styles/colors; adds small circles on sweep bars for quick spotting.
• Breakout→Open Background Fill: Shaded zone from sweep bar until price returns to open, visualizing extension duration and retracement.
• Excursion (Pain) Zone - “Magic Box”: Post-sweep box showing median/mean extension percentages, colored dynamically by probability (green high, orange mid, red low); includes dashed lines for 75th/90th/95th percentiles to mark statistical extremes.
• Time-Segmented Data: Probabilities and excursions vary by hour (0–23) and 20-min segments (0–19 min: _0, 20–39: _1, 40–59: _2), capturing intraday nuances (e.g., higher probs in early/late hours).
• Filters for Focus: RTH-only mode hides non-session elements; high-prob-only shows >70% events to reduce noise.
• Alerts: Triggers on PHH/PHL sweeps with messages for chart checks.
________________________________________
How It Works
• Data Foundation: Uses pre-computed maps for probabilities (prob_high_taken/prob_low_taken), sample sizes, and excursions (mean, median, p75/p90/p95 as percentages of open). Data is initialized on the first bar via f_init_high_data() and f_init_low_data(), covering 24 hours with 3 segments each (e.g., key "9_1" for 09:20–09:39). Probabilities represent historical likelihood of price returning to open after sweep; excursions quantify average/rare extensions (e.g., 0.156% mean = 0.156% of open price).
• Period Detection: On new 1H bars (new_period_bar), resets visuals, draws lines for open/PHH/PHL extending 1 hour forward, and labels if enabled. Uses request.security on standard ticker for real OHLC, bypassing chart transformations (e.g., Heikin Ashi).
• Sweep Logic: On each bar, checks if real high > PHH or real low < PHL. If so, fetches segment-specific data (hour + floor(minute/20)), displays probability label centered mid-hour. Skips if filtered (RTH-only or <70% prob).
• Excursion Visualization: If enabled, draws “Magic Box” from 1-min to 58-min into the hour, bounded by mean/median levels (top/bottom adjusted for high/low sweep). Adds percentile lines with labels (e.g., “75%”) at right end. Box color reflects prob strength for quick bias assessment.
• Retest Check: Monitors for open retest post-sweep (high/low cross open, or gap scenarios from prev bar). Adds ✅ to label if hit on subsequent bars (skips sweep bar to avoid false positives). Stops background fill on retest or at 58-min mark.
• Background Fill: Activates on sweep, shades until retest, using user color.
• Cleanup & Performance: Manages labels in arrays, clears on new periods; no excess drawing beyond max counts (500 lines/labels/boxes).
This setup blends statistical backtesting with real-time visualization: hardcoded data provides empirical probabilities/excursions (reducing subjectivity in breakouts), while dynamic elements (lines, fills, boxes) overlay structure on the chart. It helps Gold traders assess if a sweep is “high-edge” (e.g., >70% probability of reverting) or likely to run (low probability, high excursion), pairing historical context with current price action.
________________________________________
Settings and Customization
Inputs are grouped for ease:
1. Settings:
o Show RTH Only (9:00–15:59): Restricts to main session (default: false; tooltip: for RTH-focused stats).
o Show High Prob Only (>70%): Filters low-prob sweeps visually (default: false; tooltip: highlights confidence).
2. Visuals:
o Show Line Labels: Toggle “h.o.” / “phh” / “phl” (default: true).
o Period Open Line Color: Gray 50% (default).
o Previous High/Low Line Colors: Gray 100% (default).
o Open Line Style/Width: Dotted/1 (default; options: Solid/Dotted/Dashed).
3. Breakout→Open Background:
o Show Breakout→Open Background: Toggle fill (default: true).
o Fill Color: Teal 85% (default).
4. Breakout Circles:
o Show Breakout Circles: Toggle (default: true).
o PHH/PHL Break Circle Colors: White 20% (default).
5. Info Label Style:
o Text Size: Small (default; options: Auto/Tiny/Normal/Large/Huge).
o Label Text Color: White (default).
o Low/Mid/High Probability Colors: Red 20% / Orange 20% / Green 20% (default).
6. Excursion (Pain) Zone:
o Show Excursion Zone: Toggle Magic Box (default: true).
o Excursion Box Color: Gray 75% (default; dynamic overrides).
o 75th/90th/95th Percentile Lines: Orange 30% / Red 30% / Dark Red 100% (default).
No additional tables/plots; all elements are lines/labels/boxes for overlay focus.
________________________________________
Usage Tips
• Breakout Trading: Watch for sweeps with high probability (>70%, green label) as potential fades back to open; low probability (red) may signal runs—use the excursion box for targets (e.g., exit at 90th percentile for extremes).
• Time Awareness: Probabilities often peak in key liquidity windows and drop in quieter hours; segments capture momentum shifts (e.g., _2 often lower prob).
• RTH Focus: Enable for cleaner stats during high-liquidity session hours; disable for a 24-hour view.
• Visual Filtering: Use high-prob-only in volatile conditions to reduce noise; combine with volume or other confluence tools for confirmation.
• Alerts Integration: Set TradingView alerts on sweeps; check label for probability/N before acting.
• Chart Setup: Best on 1H or lower GC1! charts; adjust text size for readability on smaller screens.
• Backtesting: Manually review historical sweeps against data maps to validate; update hardcoded values if new data emerges (as of 2025).
________________________________________
Limitations
• Fixed Data: Hardcoded stats may not reflect recent market changes (e.g., post-2025 regime shifts); not adaptive.
• Reactive Only: Detects sweeps after they occur; no predictive signals.
• Timeframe Specific: Locked to 1H logic; may not translate to other assets/timeframes without recoding data.
• Visual Clutter: On busy charts, labels/boxes may overlap—toggle selectively.
• No Live Stats: Sample sizes are historical; real-time N/prob not updated.
• Gaps & Extremes: Handles gaps in retest logic, but rare events (e.g., macro news) may exceed the 95th percentile.
________________________________________
Disclaimer
This indicator is for informational and educational purposes only. Trading involves significant risk of loss and is not suitable for all investors. The hardcoded data represents past Gold futures (GC1!) performance and does not guarantee future outcomes. No claims of profitability are made—results depend on market conditions, user strategy, and risk management. Consult a financial advisor before trading, and backtest extensively. Abiding by TradingView rules, this tool provides no investment recommendations.
Script protegido
Esse script é publicada como código fechado. No entanto, você pode gerenciar suas escolhas de bate-papo. Por favor, abra suas Configurações do perfil
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.
Script protegido
Esse script é publicada como código fechado. No entanto, você pode gerenciar suas escolhas de bate-papo. Por favor, abra suas Configurações do perfil
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.