OPEN-SOURCE SCRIPT
Session Opening Bar Range

Session Opening Bar Range (OBR) - Advanced Opening Range Indicator with Statistical Analysis
Overview
The Session First Bar Range (FBR) indicator is a comprehensive tool that captures and projects key levels based on the first bar of a user-defined trading session. Unlike traditional daily opening range indicators, this script allows traders to focus on specific session windows (New York RTH, London, Asia, etc.) and analyze price behavior relative to the initial momentum established in that session's opening bar.
What makes this indicator unique is its combination of three distinct projection methodologies: statistical analysis based on historical range data, Fibonacci extensions, and fixed-point rotation levels commonly used by institutional traders. To our knowledge, this is the only opening range indicator that incorporates statistical standard deviation levels calculated from historical first bar ranges, making it both a technical and probabilistic tool.
Core Concept
The opening range concept is based on the principle that the initial price action of a trading session often sets the tone for the remainder of that session.
Professional traders have long observed that:
The first bar's high and low act as key reference points
Price often respects or breaks these levels with significance
Expansion beyond the opening range tends to occur in measurable increments
This indicator takes these observations and enhances them with:
Historical probability analysis - "Based on the last 60 sessions, price typically extends X standard deviations beyond the opening range"
Proportional projections - Fibonacci-based extensions showing where measured moves typically target
Fixed-point rotations - Institutional rotation levels (e.g., 65 points for NQ, 15 points for ES)
How It Works
Session Detection & First Bar Capture
The indicator uses Pine Script's time() function with timezone support to precisely detect when a trading session begins. When the first bar of the selected timeframe occurs within the session window, the script captures:
High (H): The high of the first bar
Low (L): The low of the first bar
Mid (M): The midpoint (hl2) of the first bar
Critical Detail: These levels are fixed from the first bar only - they do not update as the session progresses. This differs from many "opening range" indicators that use a time period (e.g., first 30 minutes). Here, you select the bar timeframe (default 5-minute), and only that single first bar's range is captured.
Statistical Level Calculation
The indicator maintains a rolling array of the last N session's first bar ranges (default: 60 sessions). For each new session, it calculates:
Average Range: Mean of historical first bar ranges
Standard Deviation: Volatility of those ranges
Projection Levels: High/Low ± (Average Range + Std Dev × Multiplier)
This provides probability-based levels. For example, a +2σ level suggests: "Historically, price extending this far beyond the opening range is a 2-standard-deviation event (approximately 95th percentile)."
Fibonacci Extensions
Using the first bar range as the base unit (100%), the indicator projects Fibonacci levels:
100% extension: One full range above the high / below the low
1.618x extension: (Default) Golden ratio projection
2.618x, 3.618x extensions: Additional Fibonacci levels
Calculation: Range = H - L, then Target = H + (Range × Multiplier) for upside projections.
OR Rotation Levels
These are fixed-point increments from the first bar's high and low. Unlike percentage-based methods, rotations use absolute point values:
NQ traders often use 65-point increments
ES traders often use 15-point increments
Gold/bonds use different values
The indicator draws 5 levels above the high (R+1 through R+5) and 5 below the low (R-1 through R-5), each separated by your specified point increment.
Features:
Session Options
Pre-configured Sessions:
New York RTH (9:30am - 4:00pm)
New York Futures (8:00am - 5:00pm)
London (2:00am - 8:00am)
Asia (7:00pm - 2:00am)
Midnight to 5pm
ZB/Gold/Silver OR (8:20am - 4:00pm)
CL OR (9:00am - 4:00pm)
Custom Session: Define your own start/end times in HHMM format
Timezone Support: All sessions respect the selected timezone (default: America/New_York)
Customizable Timeframe
Select any timeframe for the first bar (1min, 5min, 15min, etc.)
Default: 5-minute bars
Important: This is the timeframe for the first bar capture, independent of your chart's timeframe
Display Options
Historical Ranges: Show/hide past session ranges (with configurable limit to manage performance)
Line Styles: Choose between Solid, Dashed, or Dotted for range lines and midline
Label Position: Left or Right side of range
Show Prices: Optionally display actual price values on labels
Custom Colors: Fully customizable colors for all components
Statistical Levels
Lookback Period: Number of historical sessions to analyze (default: 60)
Two Multiplier Levels: Default 1σ and 2σ, fully adjustable
Separate styling: Different line styles (dashed vs dotted) for each sigma level
Optional Labels: Show/hide sigma notation labels
Fibonacci Extensions
Four Extension Levels: 100%, 1.618x, 2.618x, 3.618x (all customizable)
Bidirectional: Projections both above and below the opening range
Optional Labels: Toggle percentage/multiplier labels
OR Rotation Levels
Configurable Increment: Set the point value for your instrument
Five Levels Each Direction: R±1 through R±5
Dynamic Labels: Show both rotation number and point value (e.g., "R+1 (65)")
Three Line Styles: Solid, Dashed, or Dotted
How to Use
Setup
Add the indicator to your chart
Select your trading session from the dropdown
Set the timeframe for first bar capture (typically 5-15 minutes)
Configure which projection methods you want to see (Statistical, Fibonacci, and/or Rotations)
For Day Traders
Scenario: Trading NQ during New York RTH
Session: Select "New York RTH (9:30am - 4:00pm)"
Timeframe: 5-minute (captures 9:30-9:35 bar)
Enable: OR Rotations with 65-point increments
Strategy:
Watch for acceptance/rejection at rotation levels
Use R+1/R-1 as initial profit targets
R+2/R-2 as extended targets
Statistical levels show when price is in "outlier" territory
and rotation levels
Performance Notes
The indicator limits objects to stay within TradingView's constraints (500 max)
If you enable all features, reduce "Maximum Historical Ranges" to prevent slowdown
Typical configuration: 10-20 historical ranges with all features enabled works well
Settings Guide
Session Settings
Session: Choose from pre-configured sessions or "Custom"
Custom Session Start/End: HHMM format (e.g., "0930" for 9:30am)
Timezone: Critical for accurate session detection
Opening Bar Format
Timeframe: The bar size for capturing the first bar's range
Show Midline: Toggle the mid-point line
Show Historical Ranges: Display previous sessions (recommended: leave ON)
Maximum Historical Ranges: Limit history to manage performance (1-500)
Range Style / MidLine Style: Solid, Dashed, or Dotted
Position: Label placement (Left or Right)
Show Prices: Include actual price values on labels
Statistical Levels
Lookback Periods: How many historical first bar ranges to analyze (default: 60)
Std Dev Multiplier 1/2: The sigma levels to project (default: 1.0 and 2.0)
All visual settings (colors, line width, label size)
Fibonacci Extensions
Show Fib Extensions: Enable/disable Fibonacci projections
Measured Move Extensions 1-4: The multipliers (default: 1.618, 2.618, 3.618, 4.618)
Visual customization options
OR Rotations
Rotation Increment: The point value for your instrument
NQ: 65 points
ES: 15 points
Adjust for other instruments based on their typical rotation behavior
Show Rotation Labels: Display level numbers and point values
Visual customization options
Use Cases
Gap Trading: When price gaps away from previous day's close, the first bar range shows the initial gap acceptance/rejection zone
Breakout Confirmation: Price breaking and holding above the first bar high with volume suggests trend day potential. Rotation levels provide measured targets.
Reversal Identification: Price reaching +2σ statistical level = rare event, potential exhaustion
Range Bound Days: Price oscillating between first bar high/low suggests range-bound session; trade reversals at extremes
Institutional Level Awareness: OR Rotations at 65 points (NQ) align with levels professional traders watch
Technical Notes
The indicator uses request.security() with lookahead=barmerge.lookahead_on to ensure the first bar levels are captured correctly
All drawing objects (lines, labels, fills) are managed in arrays with automatic cleanup to prevent memory issues
The statistical calculations use array.avg() and array.stdev() for accurate probability estimates
Rotation levels use individual line variables (like Fibonacci) rather than loops for reliability
Summary
This indicator is original in its combination of three distinct methodologies for projecting levels from a session's opening range:
Statistical Analysis - No other opening range indicator (to our knowledge) calculates standard deviation projections from historical first bar ranges
Time-Based Session Flexibility - Most OR indicators use only daily or fixed time periods; this allows any custom session window
Multiple Projection Methods - Traders can use statistical, Fibonacci, AND rotation levels together or separately
Overview
The Session First Bar Range (FBR) indicator is a comprehensive tool that captures and projects key levels based on the first bar of a user-defined trading session. Unlike traditional daily opening range indicators, this script allows traders to focus on specific session windows (New York RTH, London, Asia, etc.) and analyze price behavior relative to the initial momentum established in that session's opening bar.
What makes this indicator unique is its combination of three distinct projection methodologies: statistical analysis based on historical range data, Fibonacci extensions, and fixed-point rotation levels commonly used by institutional traders. To our knowledge, this is the only opening range indicator that incorporates statistical standard deviation levels calculated from historical first bar ranges, making it both a technical and probabilistic tool.
Core Concept
The opening range concept is based on the principle that the initial price action of a trading session often sets the tone for the remainder of that session.
Professional traders have long observed that:
The first bar's high and low act as key reference points
Price often respects or breaks these levels with significance
Expansion beyond the opening range tends to occur in measurable increments
This indicator takes these observations and enhances them with:
Historical probability analysis - "Based on the last 60 sessions, price typically extends X standard deviations beyond the opening range"
Proportional projections - Fibonacci-based extensions showing where measured moves typically target
Fixed-point rotations - Institutional rotation levels (e.g., 65 points for NQ, 15 points for ES)
How It Works
Session Detection & First Bar Capture
The indicator uses Pine Script's time() function with timezone support to precisely detect when a trading session begins. When the first bar of the selected timeframe occurs within the session window, the script captures:
High (H): The high of the first bar
Low (L): The low of the first bar
Mid (M): The midpoint (hl2) of the first bar
Critical Detail: These levels are fixed from the first bar only - they do not update as the session progresses. This differs from many "opening range" indicators that use a time period (e.g., first 30 minutes). Here, you select the bar timeframe (default 5-minute), and only that single first bar's range is captured.
Statistical Level Calculation
The indicator maintains a rolling array of the last N session's first bar ranges (default: 60 sessions). For each new session, it calculates:
Average Range: Mean of historical first bar ranges
Standard Deviation: Volatility of those ranges
Projection Levels: High/Low ± (Average Range + Std Dev × Multiplier)
This provides probability-based levels. For example, a +2σ level suggests: "Historically, price extending this far beyond the opening range is a 2-standard-deviation event (approximately 95th percentile)."
Fibonacci Extensions
Using the first bar range as the base unit (100%), the indicator projects Fibonacci levels:
100% extension: One full range above the high / below the low
1.618x extension: (Default) Golden ratio projection
2.618x, 3.618x extensions: Additional Fibonacci levels
Calculation: Range = H - L, then Target = H + (Range × Multiplier) for upside projections.
OR Rotation Levels
These are fixed-point increments from the first bar's high and low. Unlike percentage-based methods, rotations use absolute point values:
NQ traders often use 65-point increments
ES traders often use 15-point increments
Gold/bonds use different values
The indicator draws 5 levels above the high (R+1 through R+5) and 5 below the low (R-1 through R-5), each separated by your specified point increment.
Features:
Session Options
Pre-configured Sessions:
New York RTH (9:30am - 4:00pm)
New York Futures (8:00am - 5:00pm)
London (2:00am - 8:00am)
Asia (7:00pm - 2:00am)
Midnight to 5pm
ZB/Gold/Silver OR (8:20am - 4:00pm)
CL OR (9:00am - 4:00pm)
Custom Session: Define your own start/end times in HHMM format
Timezone Support: All sessions respect the selected timezone (default: America/New_York)
Customizable Timeframe
Select any timeframe for the first bar (1min, 5min, 15min, etc.)
Default: 5-minute bars
Important: This is the timeframe for the first bar capture, independent of your chart's timeframe
Display Options
Historical Ranges: Show/hide past session ranges (with configurable limit to manage performance)
Line Styles: Choose between Solid, Dashed, or Dotted for range lines and midline
Label Position: Left or Right side of range
Show Prices: Optionally display actual price values on labels
Custom Colors: Fully customizable colors for all components
Statistical Levels
Lookback Period: Number of historical sessions to analyze (default: 60)
Two Multiplier Levels: Default 1σ and 2σ, fully adjustable
Separate styling: Different line styles (dashed vs dotted) for each sigma level
Optional Labels: Show/hide sigma notation labels
Fibonacci Extensions
Four Extension Levels: 100%, 1.618x, 2.618x, 3.618x (all customizable)
Bidirectional: Projections both above and below the opening range
Optional Labels: Toggle percentage/multiplier labels
OR Rotation Levels
Configurable Increment: Set the point value for your instrument
Five Levels Each Direction: R±1 through R±5
Dynamic Labels: Show both rotation number and point value (e.g., "R+1 (65)")
Three Line Styles: Solid, Dashed, or Dotted
How to Use
Setup
Add the indicator to your chart
Select your trading session from the dropdown
Set the timeframe for first bar capture (typically 5-15 minutes)
Configure which projection methods you want to see (Statistical, Fibonacci, and/or Rotations)
For Day Traders
Scenario: Trading NQ during New York RTH
Session: Select "New York RTH (9:30am - 4:00pm)"
Timeframe: 5-minute (captures 9:30-9:35 bar)
Enable: OR Rotations with 65-point increments
Strategy:
Watch for acceptance/rejection at rotation levels
Use R+1/R-1 as initial profit targets
R+2/R-2 as extended targets
Statistical levels show when price is in "outlier" territory
and rotation levels
Performance Notes
The indicator limits objects to stay within TradingView's constraints (500 max)
If you enable all features, reduce "Maximum Historical Ranges" to prevent slowdown
Typical configuration: 10-20 historical ranges with all features enabled works well
Settings Guide
Session Settings
Session: Choose from pre-configured sessions or "Custom"
Custom Session Start/End: HHMM format (e.g., "0930" for 9:30am)
Timezone: Critical for accurate session detection
Opening Bar Format
Timeframe: The bar size for capturing the first bar's range
Show Midline: Toggle the mid-point line
Show Historical Ranges: Display previous sessions (recommended: leave ON)
Maximum Historical Ranges: Limit history to manage performance (1-500)
Range Style / MidLine Style: Solid, Dashed, or Dotted
Position: Label placement (Left or Right)
Show Prices: Include actual price values on labels
Statistical Levels
Lookback Periods: How many historical first bar ranges to analyze (default: 60)
Std Dev Multiplier 1/2: The sigma levels to project (default: 1.0 and 2.0)
All visual settings (colors, line width, label size)
Fibonacci Extensions
Show Fib Extensions: Enable/disable Fibonacci projections
Measured Move Extensions 1-4: The multipliers (default: 1.618, 2.618, 3.618, 4.618)
Visual customization options
OR Rotations
Rotation Increment: The point value for your instrument
NQ: 65 points
ES: 15 points
Adjust for other instruments based on their typical rotation behavior
Show Rotation Labels: Display level numbers and point values
Visual customization options
Use Cases
Gap Trading: When price gaps away from previous day's close, the first bar range shows the initial gap acceptance/rejection zone
Breakout Confirmation: Price breaking and holding above the first bar high with volume suggests trend day potential. Rotation levels provide measured targets.
Reversal Identification: Price reaching +2σ statistical level = rare event, potential exhaustion
Range Bound Days: Price oscillating between first bar high/low suggests range-bound session; trade reversals at extremes
Institutional Level Awareness: OR Rotations at 65 points (NQ) align with levels professional traders watch
Technical Notes
The indicator uses request.security() with lookahead=barmerge.lookahead_on to ensure the first bar levels are captured correctly
All drawing objects (lines, labels, fills) are managed in arrays with automatic cleanup to prevent memory issues
The statistical calculations use array.avg() and array.stdev() for accurate probability estimates
Rotation levels use individual line variables (like Fibonacci) rather than loops for reliability
Summary
This indicator is original in its combination of three distinct methodologies for projecting levels from a session's opening range:
Statistical Analysis - No other opening range indicator (to our knowledge) calculates standard deviation projections from historical first bar ranges
Time-Based Session Flexibility - Most OR indicators use only daily or fixed time periods; this allows any custom session window
Multiple Projection Methods - Traders can use statistical, Fibonacci, AND rotation levels together or separately
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.