Instructions/probuilder · probacktest · proorder · proscreener

IntradayBarIndex

IntradayBarIndex in ProBuilder counts the bars printed since the start of the trading day, starting at 0, and accepts an offset to read previous sessions.

Syntax

probuilder
IntradayBarIndex
IntradayBarIndex[N]

Parameters

NameTypeDefaultDescription
Ninteger0Optional bar offset. IntradayBarIndex[1] reads the value as it was one bar ago.

How it works

IntradayBarIndex numbers the bars of each trading session. The first bar after the daily open carries index 0, the next bar 1, and so on until the session ends, at which point the counter restarts for the next day. On the 50th bar of the day the value is 49.

The count depends on the chart timeframe. On a 5-minute chart of a market open for 8 hours, the index runs from 0 to 95; on a 1-hour chart of the same market it runs from 0 to 7. Code that gates behavior on a specific index therefore encodes an assumption about the timeframe, which is worth stating in a comment.

The optional bracket offset follows the usual series convention, reading the value from a previous bar. Where BarIndex counts bars since the beginning of loaded data and never resets, IntradayBarIndex is the session-relative counterpart, making it the natural tool for logic tied to the open, such as skipping the volatile first bars of the day or measuring position within the session.

Examples

Example 1, Displaying the session bar count (Indicator)

probuilder
// Index of the current bar within today's session, first bar = 0
RETURN IntradayBarIndex

The plot climbs by one on each bar of the day and drops back to 0 when a new session begins, which also makes session boundaries visible at a glance.

Example 2, Skipping the first bars of the day (ProOrder)

probuilder
// Only trade once 4 bars of the session have completed
IF IntradayBarIndex >= 4 AND NOT ONMARKET THEN
  IF close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
  ENDIF
ENDIF

The outer condition blocks entries during the first four bars after the open, a common way to avoid the erratic price action around the session start.

Example 3, Marking each session open (Indicator)

probuilder
// Draw a vertical line on the first bar of every trading day
IF IntradayBarIndex = 0 THEN
  DRAWVLINE(BarIndex) COLOURED(128, 128, 128)
ENDIF
RETURN

Testing for index 0 identifies the first bar of the day, and DRAWVLINE marks it on the chart, producing a visual grid of session boundaries.

Common errors and gotchas

  • Zero-based count. The first bar of the day is 0, not 1. A condition like IntradayBarIndex = 1 fires on the second bar of the session.
  • Timeframe-dependent values. The same index refers to different clock times on different timeframes. Moving a script from a 5-minute to a 15-minute chart silently changes what IntradayBarIndex >= 4 means.
  • Confusion with BarIndex. BarIndex counts from the start of loaded history and never resets; IntradayBarIndex resets daily. Swapping them produces conditions that are true either almost always or almost never.
  • Non-intraday charts. On daily or higher timeframes every bar is the first bar of its day, so the value is not meaningful. Restrict its use to intraday timeframes.
  • BarIndex, bar count since the start of loaded data, without daily resets.
  • BarsSince, bars elapsed since a condition was last true.
  • TIME, current bar time, an alternative way to anchor intraday logic.
  • CurrentTime, clock time of the machine running the platform.
  • CurrentHour, hour component of the current time.
  • Today, date constant for the current day.
  • OpenTime, opening time of the current bar.