DateToBarIndex

Category: Instructions

DateToBarIndex is a function in the ProBuilder language used in ProRealTime trading software. This function is designed to convert a specified date and time into a bar index. This is particularly useful when you want to reference a specific point in time on a chart for graphical annotations or calculations, rather than using the bar number directly.

Syntax:

DateToBarIndex(yyyyMMddHHmmss)

The function accepts various date and time formats, including:

  • YYYY
  • YYYYMM
  • YYYYMMDD
  • YYYYMMDDHH
  • YYYYMMDDHHMM
  • YYYYMMDDHHMMSS

Example Usage:

To draw a text label at the close price of the first trading bar of January 1, 2020:

DRAWTEXT("Start of 2020", DateToBarIndex(20200101), close)

In another example, to draw a segment from the first trading bar of 2020 to a user-defined date, highlighting the highest price in the last 54 bars from the latter date:

defparam drawonlastbaronly = true
mydate = 20210630
drawsegment(DateToBarIndex(20200101), close, DateToBarIndex(mydate), highest[54](high))
drawtext("#mydate#", DateToBarIndex(mydate), highest[54](high), dialog, bold, 30) coloured(255,0,0)
return

This function is essential for creating dynamic and time-specific indicators or graphical elements on historical data charts. By converting dates to bar indices, users can easily position their graphical elements accurately without manually counting bars.

Related Instructions:

  • BarIndex instructions
  • Logo Logo
    Loading...