PROTECTED SOURCE SCRIPT
Atualizado

NQ H1 Stats+

366
NQ H1 Stats - Detailed Prob & Excursion Indicator
Overview
NQ H1 Stats - Detailed Prob & Excursion is a specialized statistical overlay indicator for TradingView, tailored for the Nasdaq futures (NQ) on a 1-hour timeframe. It provides real-time insights into the probability of price returning to the hourly open after sweeping the previous hour's high (PHH) or low (PHL), based on historical data segmented by hour 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 traders focusing on liquidity sweeps, or mean-reversion setups, helping to quantify edge based on empirical probabilities and volatility excursions.
The data is hardcoded from extensive historical analysis of NQ behavior (e.g., probabilities range from ~7% to ~91%, with sample sizes up to 2000+ per segment), making it a backtested reference rather than dynamic learning. 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 "meshes" 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 traders assess if a sweep is "high-edge" (e.g., >70% prob of revert) or likely to run (low prob, high excursion), blending historical context with current price action for informed decisions.
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 prob (>70%, green label) as potential fades back to open; low prob (red) may signal runs—use excursion box for targets (e.g., exit at 90th percentile for extremes).
• Time Awareness: Probabilities peak in open hours (e.g., 09:00 ~90%+ for initial sweeps) and drop in off-hours; segments capture momentum shifts (e.g., _2 often lower prob).
• RTH Focus: Enable for cleaner stats during high-liquidity sessions; disable for 24/7 view.
• Visual Filtering: Use high-prob-only in volatile conditions to avoid noise; combine with volume or other indicators for confirmation.
• Alerts Integration: Set TradingView alerts on sweeps; check label for prob/N before acting.
• Chart Setup: Best on 1H or lower NQ charts; adjust text size for readability on mobiles.
• 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 volatility 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/TFs without recoding data.
• Visual Clutter: On busy charts, labels/boxes may overlap—toggle off 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., news) may exceed 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 NQ 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.

Notas de Lançamento
/ Fixed indicator chart by removing unrelated indicators from chart.
Notas de Lançamento
+ Added a new option for Replay Mode. It fetches data correctly if it is selected.

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.