In Pine Script, the bar index is a built-in variable represented as bar_index. It indicates the position or index of the current bar on the chart, starting from 0 for the very first bar. This variable is useful for referencing specific bars or determining the relative position of bars in your script.
for better understanding consider this axis coordinate
X axis is bar-index and we can access to Y axis with Open , Close , high , low
bar_index give us position of last candle in X axis and if you want for example get previous bar-index you can use bar-index[1]