The indexing operator [] is used to access the previous or future data in an array of data. The square brackets indicate the shift against the current moment. The positive values of the shift represent the values in the past, the negative shift values represent the values in the future. The indexing operator can be applied to fundamental data, function outputs, indicator outputs, variables, etc.

Example 1

input price = close;
input shift = 5;
plot PastPrice = price[shift];
plot FuturePrice = price[-shift];

Draws shifted price plots.

Example 2

plot PastMACD = MACD().Avg[10];

Shows the smoothed MACD value 10 bars ago.

Note that you can also use verbal syntax when referencing historical data. For more information, see the Referencing Historical Data article.