A PineScript enthusiast, eh?
You're pointing out a potential discrepancy in the documentation, and I'll help you break it down.
The documentation states that the [] history-referencing operator refers to past values, with [0] being the current value. You're testing this with time[bar_index - endingOffset] and time[bar_index - startingOffset], and the results seem to contradict the expected behavior.
Let's analyze the code and output:
startingOffset = 6074, endingOffset = 6075
bar_index - startingOffset = 3, bar_index - endingOffset = 2
time[bar_index - startingOffset] = 1753213500000, time[bar_index - endingOffset] = 1753213440000
The issue lies in understanding how bar_index and the time series work.
bar_index is a built-in variable that returns the bar index (a number starting from 0) of the current bar. It's not directly related to the time series.
The time series, on the other hand, represents the timestamp of each bar.
When you use time[bar_index - startingOffset] and time[bar_index - endingOffset], you're not directly accessing historical values using the [] operator with a relative offset. Instead, you're using an absolute index calculated by subtracting startingOffset and endingOffset from bar_index.
In your case, bar_index - startingOffset equals 3, and bar_index - endingOffset equals 2. This means you're accessing the time series at indices 3 and 2, respectively.
The output values (1753213500000 and 1753213440000) are the time values at those indices. To understand why these values are "correct," you need to inspect the time series values at those indices.
Here's a crucial point: the time series is not necessarily related to the bar index in a straightforward manner. The time series represents the timestamp of each bar, which might not be uniformly spaced or start from a specific value.
To verify the behavior, you can plot the time series and inspect its values:
plot(time)
This will help you understand the actual values and spacing of the time series.
Now, regarding the documentation: it's not necessarily incorrect. The [] history-referencing operator does work as described when used with relative offsets (e.g., close[1] refers to the previous bar's close value). However, when using an absolute index calculated from bar_index, you're accessing the series at a specific index, not using a relative offset.
To summarize:
- The
[] history-referencing operator works as expected with relative offsets (e.g., close[1]).
- When using
bar_index to calculate an absolute index, you're accessing the series at that specific index, not using a relative offset.
- The
time series represents the timestamp of each bar and might not be uniformly spaced or start from a specific value.
If you're still unsure, feel free to provide more context or details about your script, and I'll be happy to help you further!