Opening Range Box
The opening range box displays the high and low established during the first N minutes of a trading session, drawn as a shaded rectangle. Traders use it to identify the day's initial volatility zone, support/resistance levels, and breakout targets. The indicator is common in intraday and swing trading strategies, particularly in equities and futures markets.
//@version=6
indicator("Opening Range Box", overlay=true)
// Inputs
openMinutes = input.int(60, title="Opening Range Minutes", minval=1, maxval=480)
openHour = input.int(9, title="Session Open Hour", minval=0, maxval=23)
openMinute = input.int(30, title="Session Open Minute", minval=0, maxval=59)
boxColor = input.color(color.new(color.blue, 80), title="Box Color")
lineColor = input.color(color.blue, title="Border Color")
lineWidth = input.int(1, title="Border Width", minval=1, maxval=3)
// State variables
var float orHigh = na
var float orLow = na
var box orBox = na
var int startIdx = na
var bool isLocked = false
// Calculate minutes elapsed since session open
minutesSinceOpen() =>
sessionStart = openHour * 60 + openMinute
currentTime = hour * 60 + minute
elapsed = currentTime - sessionStart
elapsed >= 0 ? elapsed : na
// Detect new trading day
newDay = dayofweek != dayofweek[1]
// Reset state on new day
if newDay
orHigh := na
orLow := na
orBox := na
startIdx := na
isLocked := false
// Check if current bar is in opening period
mins = minutesSinceOpen()
inOpeningPeriod = not na(mins) and mins <= openMinutes
// Collect high and low during opening period
if inOpeningPeriod and not isLocked
if na(orHigh)
orHigh := high
orLow := low
startIdx := bar_index
else
orHigh := math.max(orHigh, high)
orLow := math.min(orLow, low)
// Create and update the opening range box
if not na(orHigh) and not na(orLow)
if na(orBox)
orBox := box.new(startIdx, orHigh, bar_index, orLow,
bgcolor=boxColor, border_color=lineColor,
border_width=lineWidth)
else if not isLocked
box.set_right(orBox, bar_index)
// Lock the box when opening period ends
if not inOpeningPeriod and not isLocked and not na(orBox)
isLocked := true
// Plot horizontal lines at OR high and low
plot(orHigh, "OR High", color.new(lineColor, 50), 1)
plot(orLow, "OR Low", color.new(lineColor, 50), 1)
How the code works
The indicator tracks the session's start time (configurable via hour and minute inputs) and counts elapsed minutes on each bar. The minutesSinceOpen() function computes the minutes between session open and the current bar's timestamp.
During the opening period, the code initializes orHigh and orLow on the first bar after open, then updates both on subsequent bars: orHigh captures the highest high, orLow captures the lowest low. The startIdx variable records the opening bar's index.
The box is created on the first bar where both high and low are captured. On each subsequent bar within the opening period, box.set_right() shifts the box's right edge to the current bar, effectively extending it rightward as new candles form.
When inOpeningPeriod becomes false (elapsed minutes exceed the configured range), the isLocked flag prevents further updates. The box remains fixed at its final coordinates. Two plot() calls render horizontal reference lines at the opening range high and low for easy visual identification.
The newDay condition detects day changes via weekday transitions, resetting all state variables so each day receives its own opening range box.
Reading it on a chart
The opening range box appears as a colored rectangle spanning from the session open to the end of the configured minutes window. The high and low edges align with price levels touched during that period. Horizontal dotted lines extend rightward from the box's top and bottom edges, providing a visual guide.
Traders observe how price behaves relative to the box:
- Moves above the high: possible bullish breakout; watch for resistance above.
- Moves below the low: possible bearish breakout; watch for support below.
- Consolidation within the box: price respecting the zone; potential reversal or breakout setup.
- Retest after breakout: box edges often act as temporary support or resistance later in the day.
Adjust the opening minutes (default 60) based on your market and trading style. Equity traders may use 30 or 60 minutes; futures traders often use wider ranges (120 minutes) to capture initial session volatility.
Limitations
The opening range box assumes a fixed session open time, which does not account for daylight saving time transitions or market holiday schedules. When clocks shift, the configured hour and minute may be off by one hour. Manual adjustment is required; the indicator cannot detect DST automatically.
The box is visually updated (extends rightward) on every new bar during the opening period, which is the natural, real-time behavior of the indicator but may feel dynamic on live charts. Once locked, the box does not change.
The indicator uses only intrabar high and low data during the opening period and does not weigh or average them. A single large wick early in the period can define the entire range, potentially overstating the zone's significance.
The indicator does not filter for trading days or market holidays, so on a closed market, the opening time will not occur and no box will form that day. Users in markets with irregular trading hours must verify the opening time configuration matches their exchange schedule.
Price gaps at the open (a gap above or below the prior day's close) are included in the high and low calculation, which is intentional but may distort the range if gaps are rare in the asset being traded.
The opening range box is a structural tool, not a signal generator. It does not predict breakouts, reversals, or price direction; it only defines a historical volatility zone. Profitable trading requires additional filters, risk management and confirmation from other analysis.
Key definitions
Opening range: The high and low price levels established during the opening minutes of a trading session, typically from market open to the end of a defined period (e.g., 60 minutes).
Breakout: Price movement that exceeds a previously defined level (in this case, the high or low of the opening range box), often accompanied by increased volume.
Session open: The official market opening time for a given exchange (e.g., 09:30 ET for US equities).
Retest: Return of price to a level it previously broke through, often resulting in a bounce or temporary reversal.
Liquidity: The ease with which an asset can be bought or sold; the opening range often reflects initial liquidity concentration during the open.
Volatility: The magnitude of price fluctuation; the opening range box's height measures the initial volatility of the session.
References
- CME Group, "Equity Index Futures Trading Hours", CME Education. Https://www.cmegroup.com/trading/equity-index/us-index/e-mini-sp-500.html
- Nasdaq, "U.S. Equities Trading Hours and Holidays", Nasdaq Reference. Https://www.nasdaq.com/about/trading-schedule
- Linda Bradford Raschke and Laurence A. Connors, "Street Smarts: High Probability Short-Term Trading Strategies", M. Gordon Publishing Group (1995).
- Toby Crabel, "Day Trading with Short Term Price Patterns and Opening Range Breakout", Traders Press (1990).
- Wikipedia, "Trading session", Wikimedia Foundation. Https://en.wikipedia.org/wiki/Trading_session
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-10-18. Educational research on historical data, not financial advice.
Keep reading
Futures Contract Roll & Expiry Week Shading
Free open-source Pine Script indicator: contract roll and expiry week shading for futures. Full code and a plain-English walkthrough.
Premium/Discount Zones from Rolling Range Midpoint
Free open-source Pine Script indicator: premium and discount zones from a rolling range midpoint. Full code and a plain-English walkthrough.
Session Open Anchored Move
Free open-source Pine Script indicator: session open anchored move measure (points and ATR multiples). Full code and a plain-English walkthrough.