How to retrieve an offset from a past event? Pine Script V5

Viewed 145

SomethingHappens[0] happens in the present so it happens at same candle as close[0].

But SomethingHappens[1] (if I'm not wrong that we can address events in a series this way) happened in the time of close[x] where x is anything, e.g. 2, 329 …, etc. – it changes all the time as the chart flows. We want to know what's that x in this close[x] to address the candle of that SomethingHappens[1].

Is there a way to retrieve that offset?

1 Answers

It sounds like you can use ta.barssince() for this.

x = ta.barssince(SomethingHappens)
Related