OPEN-SOURCE SCRIPT

Initial Balance Statistical Mapping

773
Initial Balance Statistical Mapping

Overview

The Initial Balance (Enhanced) indicator is a sophisticated trading tool designed specifically for NQ (Nasdaq-100 E-mini Futures) during New York trading hours. It provides data-driven insights based on comprehensive analysis of 12 years of 1-minute price data (2013-2025), offering traders probabilistic forecasts for intraday price movement based on the market's behavior during the critical first hour of trading.

What is Initial Balance?
Initial Balance (IB) refers to the price range established during the first hour of the New York cash session (9:30-10:30 AM ET). This concept, pioneered by legendary trader Peter Steidlmayer as part of Market Profile theory, represents a critical period where the market establishes its initial value area for the day.

The IB high and low create key reference points that professional traders use throughout the session to:

Identify potential support and resistance levels
Gauge market directional bias
Set realistic profit targets
Assess market volatility and range expectations

Statistical Foundation
This indicator is built on rigorous statistical analysis of 12+ years of NQ futures data (over 3,000 trading sessions), examining:

Opening Range Patterns: 5-minute and 15-minute opening ranges
Initial Balance Characteristics: Directional bias, extreme formation sequence, and closing position
Breakout Behavior: Which IB boundary breaks first and subsequent price action
Midpoint Dynamics: Probability and timing of midpoint retests
Session Outcomes: Correlation between IB patterns and daily close direction
Extension Targets: Historical percentile-based price projections beyond IB boundaries

The statistical combinations tracked include:

IB direction (bullish vs bearish) × Extreme formed first (high vs low) × Close position (above vs below midpoint)
Post-break behavior (confirmation, reversal, or range-bound)
Conditional probabilities for over 16 unique market scenarios

Visual Components
1. IB Box
A shaded rectangular area highlighting the first hour's price range:

Top boundary: IB High
Bottom boundary: IB Low
Midpoint line: The 50% level of the IB range
Customizable colors for the fill, border, and midpoint

2. Extension Levels
Percentile-based price targets above and below the IB boundaries, calculated from historical extension data:
Above IB High:

25th percentile: +0.14% extension
Median (50th): +0.31% extension (default display)
75th percentile: +0.60% extension
90th percentile: +1.00% extension

Below IB Low:

25th percentile: -0.16% extension
Median (50th): -0.38% extension (default display)
75th percentile: -0.79% extension
90th percentile: -1.37% extension

These levels represent targets that historically occur at the specified frequency. For example, the median extension suggests that 50% of the time, the market extends at least this amount beyond the IB boundary when it breaks out.

3. Statistics Table
A dynamic information panel displaying real-time probabilities and historical context (detailed in "Interpreting the Statistics Table" section below).

Input Parameters

Calculation Period
IB Period: Default 0930-1030 (9:30-10:30 AM ET)

Defines the time window for Initial Balance calculation
Should match the first hour of NY cash session


Regular Trading Hours: Default 0930-1600 (9:30 AM - 4:00 PM ET)

Extension lines only display during these hours
Statistics table appears during RTH only
Prevents visual clutter during overnight sessions

Display Options

Show IB Box: Toggle the shaded IB range rectangle
Only Show Current IB: When enabled, previous days' IB boxes are removed (keeps chart clean)
Show Extension Labels: Display percentile labels on extension lines
Show [25th/Median/75th/90th] Extensions: Individual toggles for each extension level

Colors

IB Box Color: Customize the shaded range fill (default: semi-transparent blue)
Box Border Color: Border line color (default: gray)
Midpoint Color: Midpoint line color (default: gray)
Extension Color: All extension lines and labels (default: blue)

Styling

Line Style: Choose Solid, Dashed, or Dotted for IB box borders and midpoint
Extension Line Style: Separate style control for extension levels
Extension Line Width: 1-4 pixels thickness
Extension Label Size: Tiny/Small/Normal/Large/Huge

Statistics Table

Table Position: 9 placement options (corners, edges, center)
Table Size: Auto/Tiny/Small/Normal/Large/Huge
Sessions for IB Stats: Number of previous sessions (5-250) to calculate rolling IB range statistics

Higher values = more stable averages
Lower values = more responsive to recent market conditions
Default: 50 sessions


Interpreting the Statistics Table
The statistics table is the analytical core of this indicator, providing probabilities derived from 12 years of historical NQ data. It updates in real-time as the trading day progresses.

Section 1: IB Characteristics
IB Direction

Bullish (green): IB close > IB open
Bearish (red): IB close < IB open
This reflects whether the first hour closed higher or lower than it opened

Extreme First

High First: The IB high was established before the IB low during the first hour
Low First: The IB low was established before the IB high
This sequence often indicates early momentum direction

Close Position

Above Midpoint: IB close is above the midpoint of the IB range
Below Midpoint: IB close is below the midpoint
This shows where buying/selling pressure finished within the range

Section 2: Historical Pattern & Probabilities
Historical Pattern

Shows the number of sessions (out of 3,000+) that match the current IB combination
Example: "151 sessions" means this exact pattern (e.g., Bullish + High First + Close Above Mid) occurred 151 times
Larger sample sizes (>100) provide more reliable probabilities
Smaller samples (<50) should be interpreted with appropriate caution

Next Break

Predicts which IB boundary will break first:

HIGH: Price likely to exceed IB high before IB low
LOW: Price likely to breach IB low before IB high
Neither: Higher probability that both boundaries remain intact for the session


Shows the highest probability outcome with its percentage
Based on what actually happened in similar historical sessions

Midpoint Retest

Probability that price will return to the IB midpoint at some point during the session
Initially shows "PENDING" status (orange)
Updates to "✓ CONFIRMED" (green) when the midpoint is touched after IB formation
Calculated based on sessions where price left the midpoint (>0.1% threshold) and returned
Average/median time to retest is tracked in the underlying data

Session Close

Highlighted row (green background): The key predictive metric
Predicts whether the NY cash session (9:30 AM - 4:00 PM ET) will close:

Bullish: Close > IB open (green)
Bearish: Close < IB open (red)


Shows the probability of the more likely outcome
This is arguably the most actionable statistic for directional bias

Section 3: IB Range Statistics
Current Range

The actual point value of today's IB range (IB High - IB Low)
Useful for comparing to historical norms

Mean (X/Yd)

Average IB range over the lookback period
"X/Y" indicates X sessions were captured out of Y lookback days
May be less than lookback if some days had incomplete data or early closures

Percentile Rank (color-coded cell)

Shows where today's IB range ranks relative to recent sessions:

Blue tint (<20th percentile): Unusually narrow range - expect potential expansion
Light gray (20-60th): Normal range
Dark gray (60-80th): Above average range
Red tint (>80th percentile): Unusually wide range - may indicate high volatility or potential consolidation


Format: "92nd" means today's range is larger than 92% of the last n sessions (n is defined by the lookback period)

Section 4: Post-Break Analysis (Dynamic Section)
This section appears only after the IB high or IB low is broken, replacing the standard table with expanded statistics.

━ IB HIGH BROKEN ━ or ━ IB LOW BROKEN ━

Orange header indicates which boundary was exceeded
Triggers when price definitively breaks through IB high or low

Historical Breaks

Number of times this specific pattern (IB direction + close position + break direction) occurred historically
Example: "1134 times" means this combination has broken the IB high 1,134 times in the dataset

Mid Retest Prob

Probability that price will return to test the IB midpoint after breaking out
Critical for entry/re-entry decisions and stop placement
Percentages typically range from 40-65% depending on the pattern

If Retest Occurs:
Shows three potential outcomes if the midpoint is retested after the break:

Bounce Back UP/DOWN (Confirmation - green text)

After breaking IB high and retesting midpoint → bounces back up (confirms bullish breakout)
After breaking IB low and retesting midpoint → bounces back down (confirms bearish breakdown)
This is the "successful retest" scenario traders often look for


Reverse to LOW/HIGH (Reversal - red text)

After breaking IB high and retesting → reverses and breaks IB low (failed breakout)
After breaking IB low and retesting → reverses and breaks IB high (failed breakdown)
The "trap" scenario that catches breakout traders


Stays in Range (neutral text)

Price retests midpoint but then remains between the midpoint and the opposite IB extreme
No additional breakout in either direction
Consolidation/balance scenario



Example Interpretation:
━ IB HIGH BROKEN ━
Historical Breaks: 1134 times
Mid Retest Prob: 44.9%

If Retest Occurs:
Bounce Back UP : 41.3% (confirms the high break)
Reverse to LOW : 39.1% (breaks IB low instead)
Stays in Range : 19.6% (consolidates)
This tells you:

This pattern has broken the IB high 1,134 times historically
There's a 44.9% chance price will retest the midpoint after breaking
IF it retests, there's roughly an equal chance it bounces back up (41.3%) or reverses to break the low (39.1%)
Only 19.6% of retests result in consolidation
This would be a high-risk breakout due to the near-equal probability of confirmation vs. reversal

How the Statistics Are Calculated
Data Collection Methodology
The Python analysis script processes:

12+ years of 1-minute NQ futures data (2013-2025)
3,000+ trading sessions
Only NY cash session data (9:30 AM - 4:00 PM ET)
Adjusted for early closures (holidays, half days)

Conditional Probability Framework
The indicator uses a nested conditional probability structure:
Level 1: IB Direction

Bullish (close > open) vs Bearish (close < open)

Level 2: IB Extreme Sequence

High First vs Low First
Determined by which extreme was reached first during IB formation

Level 3: IB Close Position

Close Above Midpoint vs Close Below Midpoint
Where within the range did the IB close?

Level 4: Break Direction

Which boundary broke first after IB?
High Breaks / Low Breaks / Neither

Level 5: Midpoint Retest Behavior (post-break)

Did midpoint get retested after break?
If yes: Confirmed / Reversed / Stayed in Range

This creates specific combinations like:

"Bullish IB + Low First + Close Above Mid" → 76.7% bullish session close (1,281 historical occurrences)
"Bearish IB + High First + Close Below Mid" → 73.9% breaks low first (1,127 occurrences)

Extension Percentile Calculations
For each session, the maximum extension beyond each IB boundary is measured:

High Extension: (Session High - IB High) / IB High × 100
Low Extension: (IB Low - Session Low) / IB Low × 100

These extensions are collected across all sessions, and percentiles are calculated:

25th percentile: 25% of sessions extend at least this far
50th percentile (Median): 50% of sessions extend at least this far
75th percentile: 75% of sessions extend at least this far
90th percentile: 90% of sessions extend at least this far

Note: Sessions with no extension (price never exceeded the IB boundary) are included in the dataset as zero-extension values. This is statistically important because it means:

The median extension of +0.31% above IB high means 50% of ALL sessions (including those that never broke the high) extended at least this far
This is a conservative, realistic measure of actual market behavior

IB Range Percentile Rank
The rolling percentile rank compares today's IB range to the previous N sessions (default 50):

Collect IB ranges for the past 50 sessions
Count how many of those ranges were smaller than today's range
Divide by total sessions and multiply by 100

Example: If 34 of the past 50 sessions had smaller IB ranges than today:

Percentile = (34/50) × 100 = 68th percentile
Today's range is larger than 68% of recent sessions

Real-Time Validation & Updates
The statistics table evolves as the trading day progresses:
Pre-IB Formation (9:30-10:30 AM)

Table shows "PENDING" for all fields in orange
No predictions yet, as IB hasn't formed
Useful as a reminder that IB is still forming

IB Formation Complete (10:30 AM)

All IB characteristics are determined and displayed
Historical pattern sample size is shown
Probabilities are populated based on the specific IB combination
"Midpoint Retest" shows expected probability with "PENDING" status

During Trading Session (10:30 AM - 4:00 PM)

Midpoint Retest status updates from "PENDING" to "✓ CONFIRMED" if midpoint is touched
Table remains stable showing initial probabilities
Extension levels continue to be displayed

After IB Breakout

Entire table is dynamically rebuilt when IB high or low is broken
Post-break statistics section is added
Shows refined probabilities specific to the break direction
Midpoint retest probability is now specific to post-break behavior

End of Session (4:00 PM)

Table is removed from chart
IB box and extensions remain visible for reference
Resets for next trading session

Practical Trading Applications
1. Directional Bias

Use the "Session Close" prediction to establish your directional bias for the day
Higher percentages (>70%) suggest stronger historical edge
Consider trading with the bias rather than against it

2. Breakout Trading

"Next Break" probability helps anticipate which boundary is more likely to break
Wait for confirmation, but prepare for the higher-probability direction
Use extension levels as initial profit targets

3. Mean Reversion

High "Midpoint Retest" probabilities (>80%) suggest mean reversion opportunities
After a break, if retest probability is high, consider waiting for the pullback
Post-retest statistics help determine whether to fade or trade with the move

4. Risk Management

Wide IB ranges (>75th percentile) may suggest:

Higher volatility day requiring wider stops
Potential for consolidation or smaller extensions
More challenging trading conditions


Narrow IB ranges (<25th percentile) may suggest:

Compressed volatility ready to expand
Potential for larger extensions when breakouts occur
Clearer directional moves

5. Trade Filtering

Use the statistics to avoid low-probability setups
If "Session Close" and "Next Break" align (both bullish or both bearish), confidence is higher
Conflicting signals suggest a more balanced, range-bound day

6. Exit Strategy

Extension percentiles provide logical profit targets:

Conservative: 25th percentile (smaller move, higher hit rate)
Moderate: 50th percentile (median expectation)
Aggressive: 75th-90th percentile (larger move, lower hit rate)


After a midpoint retest, use the post-retest probabilities to decide whether to hold or exit

Important Notes & Disclaimers
Timeframe Specificity

This indicator is designed exclusively for NQ futures
Statistics are derived from NY cash session hours only (9:30 AM - 4:00 PM ET)
Do not use on other instruments or timeframes without independent validation
The IB period should always be set to the first hour of the NY session

Statistical Interpretation

Probabilities are not certainties - a 70% probability means 30% of the time the opposite occurs
Sample size matters - combinations with <50 occurrences should be treated with caution
Market conditions evolve - the 12-year dataset includes various market regimes, but future behavior may differ
Past performance ≠ future results - these statistics are educational and analytical tools, not guarantees

Best Practices

Use this indicator as one component of a comprehensive trading plan
Combine with price action, volume analysis, and market context
Paper trade strategies based on these statistics before risking real capital
Keep a trading journal to track how probabilities play out in real-time
Adjust position sizing based on probability strength and your risk tolerance

Data Quality

Statistics are based on continuous NQ futures data (rollover-adjusted)
Early session closures, half days, and holidays are included in the dataset
Gaps and overnight moves are not considered in the analysis (only RTH data)
The indicator auto-detects early closures and adjusts the RTH end time accordingly

Technical Requirements

Platform: TradingView (Pine Script v5)
Instrument: NQ (Nasdaq-100 E-mini Futures) recommended; adaptable to ES or YM with separate validation
Timeframe: Works on any intraday timeframe (1-min, 5-min, 15-min, etc.)

Lower timeframes (1-5 min) recommended for precision


Session Settings: Chart timezone should be set to "America/New_York" or equivalent for accurate IB timing
Data Requirements: Sufficient historical data to populate IB range statistics (minimum 50 sessions)

Version History & Updates
Current Version: Enhanced Initial Balance with Conditional Statistics (v1.0)
Key Features:

12-year statistical foundation (2013-2025)
16+ conditional pattern combinations
Dynamic post-break analysis
Real-time midpoint retest validation
Percentile-based extension targets
Rolling IB range analysis
Comprehensive statistics table

Conclusion
The Initial Balance (Enhanced) indicator transforms 12 years of market data into actionable, probabilistic insights for NQ traders. By understanding the historical behavior of specific IB patterns, traders can:

Make more informed directional decisions
Set realistic profit targets based on statistical extension frequencies
Anticipate mean reversion opportunities with midpoint retest probabilities
Manage risk with context-aware range analysis
Avoid low-probability setups and focus on higher-edge opportunities

This is not a "black box" system or a magic formula. It's a transparent, data-driven framework that provides historical context to inform your trading decisions. The statistics table doesn't tell you what will happen - it tells you what has historically happened when similar patterns emerged, allowing you to trade with probabilistic edges rather than guesses.

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.