Translate an index into bars ago
Use barsAgo = currentIndex - targetIndex. A target must have occurred, and the resulting nonnegative offset must fit the relevant history buffer. Do not treat a series as an array whose positions stay fixed. The following values assume the script is executing at bar_index 100.
| Expression | Meaning | Result at index 100 |
|---|---|---|
| bar_index | Current dataset coordinate | 100 |
| bar_index - 3 | Coordinate three bars earlier | 97 |
| bar_index[3] | Value of bar_index three bars earlier | 97, when that history exists |
| close[3] | Close three bars earlier | Close from index 97 |
| close[97] | Close 97 bars earlier | Close from index 3 |
| close[0] | Current close series value | Current price until this bar closes |