BarIndex

Category: Instructions

Definition and Purpose:

The BarIndex function in ProBuilder language is used to return the index of the current bar, starting from 0 at the beginning of the data loaded into the chart. This function is essential for identifying the position of a bar in historical data, which is particularly useful in developing trading indicators and automated trading strategies.

Syntax:

BarIndex

Example Usage:

To demonstrate how BarIndex can be used, consider a scenario where you want to calculate the number of bars since the start of the trading session. You might use the following code snippet:

currentBarIndex = BarIndex
RETURN currentBarIndex as "Current bar index"

This code will output the index of the current bar, which represents how many bars have occurred since the start of the data loaded into the chart.

Additional Information:

  • The BarIndex function is zero-based, meaning the first bar when the data starts is indexed as 0.
  • This function is particularly useful in loops and conditional statements where the specific position of the bar needs to be referenced.
  • Understanding the bar index can help in analyzing the data effectively, especially when comparing the current bar’s data with historical data.

It’s important to note that BarIndex does not provide information about the time or the content of the bar, such as open, high, low, or close prices. It solely provides the position of the bar in the dataset.

Related Instructions:

  • DateToBarIndex instructions
  • IntradayBarIndex instructions
  • Logo Logo
    Loading...