Early Session Trend/Range Day Classifier
Traders often categorize trading days as either "trend days" (directional movement throughout) or "range days" (contained between highs and lows). This indicator classifies the likely character of a day during the opening session by measuring whether price breaks out of its opening range early and with momentum. It is used by intraday and swing traders to adjust position sizing and exit strategies before the session matures.
//@version=6
indicator("Trend vs Range Day Classifier (Early Session)", overlay=true)
// INPUTS
orBars = input.int(60, "Opening Range Bars", minval=10, maxval=300)
showORLevels = input.bool(true, "Show Opening Range Levels")
showSessionZone = input.bool(true, "Highlight OR Period")
// SESSION DETECTION: new session if 30+ min gap or first bar
isNewSession = barstate.isfirst or (time - time[1] > 1800000)
// OPENING RANGE TRACKER (persists across bars within session)
var int sessionBarStart = 0
var float orHigh = 0.0
var float orLow = 0.0
var string classification = "WAIT"
if isNewSession
sessionBarStart := bar_index
orHigh := high
orLow := low
classification := "WAIT"
// BUILD OPENING RANGE: track high/low for first N bars
barsSinceSessionStart = bar_index - sessionBarStart
if barsSinceSessionStart < orBars
orHigh := math.max(orHigh, high)
orLow := math.min(orLow, low)
// CLASSIFY: once OR period completes, check if price already broke out
if barsSinceSessionStart == orBars and classification == "WAIT"
orRange = orHigh - orLow
if close > orHigh
classification := "TREND UP"
else if close < orLow
classification := "TREND DOWN"
else
classification := "RANGE DAY"
// PLOT OPENING RANGE LEVELS
if showORLevels and barsSinceSessionStart <= orBars
plot(orHigh, "OR High", color.new(color.blue, 0), linewidth=2)
plot(orLow, "OR Low", color.new(color.blue, 0), linewidth=2)
// BACKGROUND: color the OR period
if showSessionZone and barsSinceSessionStart < orBars
bgcolor(color.new(color.orange, 85), title="OR Period")
// LABEL: show classification at end of OR
if barsSinceSessionStart == orBars
classColor = classification == "TREND UP" ? color.green :
classification == "TREND DOWN" ? color.red : color.gray
label.new(bar_index, high * 1.01, text=classification,
yloc=yloc.aboveclose, color=classColor, textcolor=color.white,
style=label.style_label_down, size=size.large)
How the code works
The indicator opens by detecting when a new trading session begins. In Pine Script, a new session is marked either by the first bar in the chart or when the time gap between candles exceeds 30 minutes (1,800,000 milliseconds), which flags overnight or multi-day gaps. When a new session is detected, the tracker resets: sessionBarStart captures the bar index, and orHigh and orLow are set to the first bar's high and low.
Over the next N bars (set by input, default 60), the code accumulates the highest high and lowest low, building the opening range. The opening range is the initial price zone where the market establishes equilibrium after the open.
Once the opening range period ends, the indicator compares the close of that final bar to the established OR boundaries. If close is above orHigh, the market has broken out upward early; if below orLow, downward; if still inside, it remains in a range. This breakout direction serves as a heuristic: a breakout at the end of the opening range suggests the market has found direction early, implying a trend day. A close still within the range after the OR period suggests consolidation, implying a range day.
The plots draw the OR high and low as reference lines (blue), the background colors the OR period in orange for visual clarity, and a label displays the final classification when the opening range period completes.
Reading it on a chart
Watch the opening range build as an orange zone with blue boundary lines during the first N bars of the session. Once the opening range closes (the bar count equals orBars), a label appears showing one of three classifications:
- TREND UP: price closed above the OR high at the end of the period, suggesting early directional commitment to the upside.
- TREND DOWN: price closed below the OR low at the end of the period, suggesting early directional commitment to the downside.
- RANGE DAY: price closed within the OR after the period expired, suggesting the market is consolidating and may trade in a band.
Traders typically interpret an early breakout (TREND UP or DOWN) as a signal to enter in the direction of the breakout with a tighter stop above or below the OR. A RANGE DAY classification encourages strategies that profit from mean reversion, such as selling at OR highs or buying at OR lows. The classification is a heuristic only: not all trend days begin with an early breakout, and not all range days stay confined to their opening range for the entire session.
Limitations
This indicator has several material constraints:
-
Heuristic, not prophecy: An early breakout at the end of the opening range does not guarantee the day will trend. Many false breakouts reverse within an hour, and many range days break out after lunch or on news. The indicator captures correlation, not causation. Traders must respect this as one input, not a system.
-
Session boundary detection is fragile: The 30-minute gap rule detects overnight breaks on most assets but may misfire on low-liquidity instruments with irregular trading hours or on markets with after-hours sessions (e.g., crypto, forex). Manual adjustment of the detection logic may be necessary.
-
Opening range length is arbitrary: The default 60 bars assumes a 1-minute chart; on 5-minute or hourly charts, 60 bars spans much longer calendar time. Users must rescale
orBarsfor the chart timeframe they are analyzing. There is no universal "right" opening range; changingorBarschanges the classification result significantly. -
No confirmation of follow-through: A close above the OR high does not confirm the trend will persist. Volume, momentum, news, and market regime all influence whether the market sustains its direction. The indicator shows only the initial breakout signal, not whether it sticks.
-
Overlay clutter: On busy charts with multiple overlays, the OR lines and label may obscure price action. The label can be repositioned manually or toggled off.
-
Repainting concern within the OR period: While the final classification does not repaint after the OR period closes, the OR high and low lines themselves redraw as new bars form within the period. This is by design (they track the range as it builds), but users who rely on early-period signals should be aware that the zone is not finalized until
barsSinceSessionStart == orBars.
Key definitions
Opening Range (OR): The high and low price achieved during the first N bars of a trading session, used as a reference zone for intraday traders to identify breakout levels.
Trend Day: A trading day characterized by sustained directional movement in one direction, typically with minimal pullback or consolidation; contrasts with a range day.
Range Day: A trading day in which price remains largely contained between defined highs and lows with no sustained directional thrust; also called a "choppy" or "sideways" day.
Breakout: A price movement beyond a previously established support or resistance level (e.g., above the OR high) often accompanied by volume or momentum.
Session Start: The opening of regular market hours; detected via time gaps (overnight/multi-day) or the first bar on the chart.
Heuristic: A rule of thumb or practical method that aids decision-making but does not guarantee a correct answer; used in technical analysis to form trading hypotheses rather than definitive signals.
References
-
Tomasini, E. And Jaekle, U., "Trading Systems: A New Approach to System Development and Portfolio Optimisation" (2nd ed.), Harriman House, 2015., Foundational reference on session-based trading systems and opening range methodology.
-
CME Group, "Globex Trading Hours and Session Information", CME Group Education, https://www.cmegroup.com/education/articles-and-reports.html, Primary source on regular market hours and session definitions for US futures.
-
Nison, S., "Japanese Candlestick Charting Techniques: A Contemporary Guide to the Ancient Investment Techniques of the Far East", Prentice Hall, 1991., Early rigorous treatment of intraday opening price action and opening range concepts in technical analysis.
-
Steidlmayer, F. P., "Markets in Profile: Profiting from the Auction Process", Wiley, 2003., Authoritative source on market profile theory and opening range significance within session structure.
-
FINRA, "Equity Market Structure Facts and Figures", FINRA Investor Education, https://www.finra.org/, Regulatory reference on US equities trading session definitions and normal market hours.
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-11-22. Educational research on historical data, not financial advice.
Keep reading
Futures Spread Tracker
Free open-source Pine Script indicator: spread tracker between two related futures contracts. Full code and a plain-English walkthrough.
Breadth Proxy: New Highs/New Lows Index
Free open-source Pine Script indicator: new high/new low breadth proxy for a symbol basket. Full code and a plain-English walkthrough.
Premium and Discount Zones from Rolling Midpoint
Free open-source Pine Script indicator: premium and discount zones from a rolling range midpoint. Full code and a plain-English walkthrough.