OPEN-SOURCE SCRIPT
Updated Initial Balance & deviations

Initial Balance & Deviations
What It Does
The "Initial Balance & Deviations" indicator is a powerful tool designed to help traders visualize and analyse the Initial Balance (IB)—the price range established during the first hour of a trading session (default: 8:30–9:30 AM)—along with key extensions and statistical insights. It plots the high (IBH) and low (IBL) of the IB period, calculates a midpoint (50%), and offers customizable Fibonacci levels and extended deviation zones (e.g., IBH x2, IBL x2). Additionally, it tracks historical IB range data and breakouts, displaying this in an optional stats table to provide context for market behaviour.
This indicator is perfect for day traders who want to identify potential support/resistance levels, breakout zones, or reversal points based on the opening range dynamics of a session.
How It Works
Initial Balance Calculation: The indicator identifies the highest high (IBH) and lowest low (IBL) during a user-defined session (default: 8:30–9:30 AM). It then calculates the range (IBΔ) and midpoint (50%).
Levels and Extensions:
Plots IBH and IBL as main levels.
Adds optional Fibonacci levels (default: 0.214, 0.236, 0.786, 0.800) within the IB range.
Extends beyond the IB with deviation levels (e.g., IBH + IBΔ, IBL - IBΔ, up to x2 or x3).
Visual Customization: Users can toggle lines, labels, shaded IB zones, and line styles (solid, dashed, dotted) or adjust colors and widths to suit their chart.
Historical Analytics: Tracks IB ranges over time and monitors breakouts (high-only, low-only, both, or none), presenting stats like max/min/average range, standard deviation, and breakout frequency in a table.
Dynamic Display: Lines extend (right, left, both, or none) from the IB period, with options to show only the current session’s levels or zones for a cleaner chart.
Key Features
Flexible Session Timing: Adjust the IB calculation period to match your market or strategy (e.g., 9:30–10:30 AM for NYSE open).
Custom Levels: Toggle Fibonacci levels, extra deviations (x2, x3), and intermediate lines (50%) on or off.
Stats Table: Displays IB range trends and breakout stats for deeper market insight.
Visual Clarity: Shaded IB areas, adjustable label sizes, and line styles make it easy to read.
Limitations & Tips
Timeframe Dependency: Works best on intraday timeframes (e.g., 1-min, 5-min). On daily or higher timeframes, the session logic may not apply as intended since it’s designed around a daily IB concept.
Session Alignment: Ensure your chart’s timezone matches the session you’re analyzing (e.g., Eastern Time for US markets). Misaligned timezones can skew results.
Historical Data: The stats table builds accuracy over time. With limited chart history (e.g., fewer than 10 sessions), breakout and range stats may not fully reflect market tendencies.
Breakout Detection: Breakouts are evaluated assuming a full trading day (1440 minutes on intraday charts). On shorter sessions or incomplete data, results might be less reliable.
Customization Balance: Too many levels enabled (e.g., all Fibonacci and extensions) can clutter the chart. Start with defaults and tweak based on your needs.
Performance: On very low timeframes with maxed-out settings (e.g., all levels, labels, and shading), the indicator might slow down older systems due to the number of objects drawn.
How to Use It
Add the indicator to your chart and adjust the session time if needed.
Use IBH and IBL as potential breakout or reversal zones. Watch for price reactions at Fibonacci levels or extended deviations.
Check the stats table to gauge whether today’s IB range is unusually large or small compared to historical norms, which can signal volatility or consolidation.
Combine with other tools (e.g., volume, momentum) for confirmation—don’t rely on IB levels alone.
This indicator is a versatile starting point for understanding opening range dynamics. Play with the settings, test it on your market, and adapt it to your trading style!
What It Does
The "Initial Balance & Deviations" indicator is a powerful tool designed to help traders visualize and analyse the Initial Balance (IB)—the price range established during the first hour of a trading session (default: 8:30–9:30 AM)—along with key extensions and statistical insights. It plots the high (IBH) and low (IBL) of the IB period, calculates a midpoint (50%), and offers customizable Fibonacci levels and extended deviation zones (e.g., IBH x2, IBL x2). Additionally, it tracks historical IB range data and breakouts, displaying this in an optional stats table to provide context for market behaviour.
This indicator is perfect for day traders who want to identify potential support/resistance levels, breakout zones, or reversal points based on the opening range dynamics of a session.
How It Works
Initial Balance Calculation: The indicator identifies the highest high (IBH) and lowest low (IBL) during a user-defined session (default: 8:30–9:30 AM). It then calculates the range (IBΔ) and midpoint (50%).
Levels and Extensions:
Plots IBH and IBL as main levels.
Adds optional Fibonacci levels (default: 0.214, 0.236, 0.786, 0.800) within the IB range.
Extends beyond the IB with deviation levels (e.g., IBH + IBΔ, IBL - IBΔ, up to x2 or x3).
Visual Customization: Users can toggle lines, labels, shaded IB zones, and line styles (solid, dashed, dotted) or adjust colors and widths to suit their chart.
Historical Analytics: Tracks IB ranges over time and monitors breakouts (high-only, low-only, both, or none), presenting stats like max/min/average range, standard deviation, and breakout frequency in a table.
Dynamic Display: Lines extend (right, left, both, or none) from the IB period, with options to show only the current session’s levels or zones for a cleaner chart.
Key Features
Flexible Session Timing: Adjust the IB calculation period to match your market or strategy (e.g., 9:30–10:30 AM for NYSE open).
Custom Levels: Toggle Fibonacci levels, extra deviations (x2, x3), and intermediate lines (50%) on or off.
Stats Table: Displays IB range trends and breakout stats for deeper market insight.
Visual Clarity: Shaded IB areas, adjustable label sizes, and line styles make it easy to read.
Limitations & Tips
Timeframe Dependency: Works best on intraday timeframes (e.g., 1-min, 5-min). On daily or higher timeframes, the session logic may not apply as intended since it’s designed around a daily IB concept.
Session Alignment: Ensure your chart’s timezone matches the session you’re analyzing (e.g., Eastern Time for US markets). Misaligned timezones can skew results.
Historical Data: The stats table builds accuracy over time. With limited chart history (e.g., fewer than 10 sessions), breakout and range stats may not fully reflect market tendencies.
Breakout Detection: Breakouts are evaluated assuming a full trading day (1440 minutes on intraday charts). On shorter sessions or incomplete data, results might be less reliable.
Customization Balance: Too many levels enabled (e.g., all Fibonacci and extensions) can clutter the chart. Start with defaults and tweak based on your needs.
Performance: On very low timeframes with maxed-out settings (e.g., all levels, labels, and shading), the indicator might slow down older systems due to the number of objects drawn.
How to Use It
Add the indicator to your chart and adjust the session time if needed.
Use IBH and IBL as potential breakout or reversal zones. Watch for price reactions at Fibonacci levels or extended deviations.
Check the stats table to gauge whether today’s IB range is unusually large or small compared to historical norms, which can signal volatility or consolidation.
Combine with other tools (e.g., volume, momentum) for confirmation—don’t rely on IB levels alone.
This indicator is a versatile starting point for understanding opening range dynamics. Play with the settings, test it on your market, and adapt it to your trading style!
Release Notes
Updated to include median, max and mean extensionsRelease Notes
The extended levels are derived from the IB range (high minus low) and historical price action after the IB period.
Initial Balance Calculation:
The IB is calculated during the user-defined session (e.g., 8:30–9:30).
The highest high (ib_high) and lowest low (ib_low) within this period form the IB range (ib_delta = ib_high - ib_low).
This range is stored in an array (delta_history) for historical analysis.
Fibonacci Levels:
User-defined Fibonacci levels (default: 0.214, 0.236, 0.786, 0.800) are applied to the IB range.
These are calculated as ib_low + (ib_high - ib_low) * fib_level and plotted as intermediate levels between IB high and low.
Mean and Median Extensions:
After the IB session ends, the indicator tracks the maximum high (current_high_ext) and minimum low (current_low_ext) reached until the next IB session begins.
Extensions are calculated as:
High extension = current_high_ext - ib_high
Low extension = ib_low - current_low_ext
These values are stored in arrays (high_extensions and low_extensions).
The mean (array.avg) and median (array.median) of these historical extensions are plotted above ib_high and below ib_low.
Standard Deviation (SD) Levels:
SD is calculated for the high and low extension arrays (high_sd = array.stdev(high_extensions), low_sd = array.stdev(low_extensions)).
Levels at 1, 2, 3, and 4 SDs are optionally plotted:
High SD levels = ib_high + mean_high_ext + (high_sd * n)
Low SD levels = ib_low - mean_low_ext - (low_sd * n)
Users can toggle visibility for each SD level (e.g., show_sd1, show_sd2).
Dynamic SD Levels (Z-Score Threshold):
If the current high or low extension’s Z-score exceeds a user-defined threshold (default: 2.0), a dynamic SD line is plotted at the current extension level in orange.
Z-score = (current_extension - mean_extension) / sd_extension.
How to Interpret the Z-Score Table
The Z-score table (enabled by show_z_score_table) provides statistical measures of how extreme the current IB range and extensions are compared to historical data. It appears in a customizable position (default: Bottom Left) and includes:
IB Range Z-Score:
Formula: (ib_delta - mean_delta) / sd_delta
Interpretation:
Measures how far the current IB range deviates from the historical average in terms of standard deviations.
Positive values indicate a larger-than-average range; negative values indicate a smaller range.
Highlighted in red if |Z-score| > 2, signalling a statistically significant deviation (outside ~95% of historical ranges).
High Ext Z-Score:
Formula: (high_ext_value - mean_high_ext) / high_sd
Interpretation:
Shows how unusual the current high extension is compared to historical highs.
A high positive value (e.g., >2) suggests a rare upward breakout; red text flags significance.
Low Ext Z-Score:
Formula: (low_ext_value - mean_low_ext) / low_sd
Interpretation:
Indicates the rarity of the current low extension.
A high positive value (e.g., >2) suggests a significant downward move; red text highlights extremes.
Breakout Probability:
Formula: (total_breaks / total_sessions) * 100, adjusted by IB Z-score if negative.
Interpretation:
Estimates the likelihood of a breakout beyond IB high or low based on historical breakouts.
Adjusted upward if the IB range is unusually small (negative Z-score), reflecting higher breakout potential.
How to Interpret Stats in the Tables
The IB Stats table (enabled by show_delta_analytics) provides detailed statistics about the IB and extensions:
IB Max, Average, Min, and Today’s Range:
Values from delta_history (max, avg, min) and the current ib_delta.
Interpretation: Compare today’s range to historical extremes and averages to gauge its significance.
IB Range Standard Deviation and Median:
SD (array.stdev(delta_history)) and median (array.median(delta_history)).
Interpretation: SD shows historical range volatility; median offers a central tendency less skewed by outliers.
Breakout Statistics:
Total IB high breaks, low breaks, both-side breaks, and no breaks.
Interpretation: Historical frequency of breakouts helps assess whether the current session aligns with past trends.
Mean and Median Extensions:
High and low extension averages and medians from high_extensions and low_extensions.
Interpretation: These indicate typical extension distances, useful for setting price targets or stop-loss levels.
How to Use the Indicator
Setup:
Adjust the IB session (e.g., 8:30–9:30) to match your market’s opening period.
Customize Fibonacci levels, SD levels, and Z-score threshold via inputs.
Enable/disable visuals (e.g., show_extensions, show_z_score_table) based on preference.
Trading Applications:
Support/Resistance: Use IB high/low and Fibonacci levels as key price zones.
Breakout Trading: Monitor extensions and breakout probability. A high Z-score (>2) or dynamic SD line suggests a significant move.
Reversion Trading: If the IB range Z-score is extreme (e.g., >2 or <-2), expect potential mean reversion.
Release Notes
Updated to show stats by day of weekRelease Notes
Tidied up the extension lines a bit and also changed the standard deviation levels to reflect the SD of the IB range, rather than the SD of the extended levelsRelease Notes
Tidied the display up a bit to make it cleanerOpen-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.