Indicators··7 min read

Trend Day vs Range Day Classifier

0 references, link-verifiedEditor of record: Shane CantyStandards review editorial standard · audit log

A trading session typically follows one of two patterns: the market either drifts sideways within a band, or it commits to a directional move away from the opening level. The distinction, called trend versus range, affects how traders approach entries and exits. This indicator uses early session heuristics, measuring directional movement against average volatility in the first N bars, to classify the likely character of the day in real time.

Traders, particularly in intraday timeframes, use trend and range classifications to set expectations for the session's behavior. A range day suggests entries near support and resistance with exits on pullbacks; a trend day suggests entries on directional breakouts with trailing stops. This classifier helps distinguish early, before the entire session resolves.

//@version=6
indicator("Trend Day vs Range Day Classifier", overlay=true)

// User inputs
session_bars = input(5, "Early Session Bars", minval=1, maxval=50)
trend_threshold = input(1.5, "Trend Ratio Threshold", minval=1.0, step=0.1)

// Session tracking variables
var float day_open = na
var int bar_count = 0
var float sess_high = na
var float sess_low = na
var float sum_bar_ranges = 0.0
var bool is_classified = false
var bool is_trend = false

// Reset tracking on new trading day
if barstate.isnew("D")
    day_open := open
    bar_count := 1
    sess_high := high
    sess_low := low
    sum_bar_ranges := high - low
    is_classified := false
else
    // Accumulate early session data
    bar_count := bar_count + 1
    if bar_count <= session_bars
        sess_high := math.max(sess_high, high)
        sess_low := math.min(sess_low, low)
        sum_bar_ranges := sum_bar_ranges + (high - low)

// Classification logic: execute once when early session closes
if bar_count == session_bars and not is_classified
    // Directional movement: max distance from open to any extreme
    dir_up = sess_high - day_open
    dir_down = day_open - sess_low
    dir_move = math.max(dir_up, dir_down)
    
    // Average bar range over the early session
    avg_range = sum_bar_ranges / session_bars
    
    // Ratio: directional move vs. typical volatility
    ratio = avg_range > 0 ? dir_move / avg_range : 0.0
    is_trend := ratio > trend_threshold
    is_classified := true

// Background color: green for trend, orange for range
if is_classified
    bg_color = is_trend ? color.new(color.green, 85) : color.new(color.orange, 85)
    bgcolor(bg_color)

// Label on chart (last bar only)
if barstate.islast and is_classified
    label_text = is_trend ? "TREND DAY" : "RANGE DAY"
    label_color = is_trend ? color.green : color.orange
    label.new(bar_index, high + (high - low) * 0.4, label_text,
              color=color.new(color.black, 0), textcolor=label_color,
              style=label.style_label_center, size=size.large)

How the code works

The indicator resets its state each time a new trading day begins (detected by barstate.isnew("D")). It records the day's opening price and then accumulates the session high, low, and bar ranges for the first N bars, controlled by the "Early Session Bars" input (default 5).

Once N bars have closed, the code calculates two metrics. The directional movement is the greater of the distance from the open to the session high or from the open to the session low, this captures how far price has committed from the starting point. The average range is the sum of all bar ranges divided by N, representing typical volatility in that window.

The ratio divides directional movement by average range. If this ratio exceeds the "Trend Ratio Threshold" (default 1.5), the classifier marks the day as a trend day; otherwise, a range day. Once classified, the background color changes (green for trend, orange for range) and a label appears on the chart. The classification does not update after this point, avoiding repainting.

Reading it on a chart

After the early session bars complete, the entire chart background changes color. Green signals a likely trend day: price has already moved substantially further from the open than is typical for a single bar. Orange signals a likely range day: the opening move, relative to average bar volatility, is modest.

The indicator respects intraday time zones if the chart itself does (e.g., US market hours). On a 5-minute chart with the default input of 5 bars, the classification arrives after 25 minutes of trading. On a 15-minute chart, it arrives after 75 minutes. Traders should monitor the first early-session breakout or the lack thereof: if price gaps away from open and holds the extremes, a trend day classification is likely; if price reverses or consolidates near the open, a range day is likely.

The label updates only on the final bar of the chart, keeping the display clean.

Limitations

This classifier measures only directional commitment in the early session; it does not predict the entire day's outcome. A trend day classification in the first hour does not guarantee the trend will persist, nor does a range day classification preclude a breakout later. Market structure can shift as new information arrives or as institutional buyers and sellers enter.

The heuristic depends heavily on the choice of early-session bars and the threshold ratio. A 5-bar window on a 1-minute chart captures only 5 minutes of data, which may be too granular to reveal true direction; the same window on a 1-hour chart captures hours and may be too coarse. Traders should test both inputs on their intended timeframe. The threshold ratio of 1.5 is arbitrary; some markets or instruments may require 2.0 or 1.2 to match their typical behavior.

The indicator uses only price data from the early session. It ignores volume, order flow, volatility term structure, or gaps from the previous close. On days with significant overnight gaps or news surprises at the open, the classification may contradict the true market regime.

Finally, the indicator classifies regime tendency, not trade opportunity. A range day does not guarantee profitable mean reversion, nor does a trend day guarantee profitable trend-following. Regime classification is a necessary but insufficient input to a trading decision.

Key definitions

Trend day: A trading session in which price moves substantially away from the opening level and maintains that directional bias, characterized by low consolidation and a clear directional winner.

Range day: A trading session in which price oscillates within a relatively narrow band and returns repeatedly to the opening level or nearby support and resistance.

Directional movement: The distance from the opening price to the highest high or lowest low reached during the measured period, capturing commitment away from the open.

Average bar range: The mean of the true range (high minus low) of each bar over the early session, providing a baseline measure of volatility.

Early session: The first N bars of the trading day, typically 1-5 hours depending on chart resolution and market hours.

Repainting: The unwanted behavior in which an indicator's signal changes retroactively on previous bars; this indicator avoids it by classifying once and freezing the result.

References

  • CME Group, "Understanding Market Structure and Microstructure", CME Education (2023). Https://www.cmegroup.com/education
  • Aldridge, I., "High-Frequency Trading: A Practical Guide to Algorithmic Strategies and Systems", Wiley (2013).
  • TradingView, "Pine Script v6 Documentation: Barstate Namespace", TradingView Docs. Https://www.tradingview.com/pine-script-docs/
  • Hasbrouck, J., "Empirical Market Microstructure", Oxford University Press (2007).

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-09. Educational research on historical data, not financial advice.

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. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.