I want to find bar (bar index) which meets some condition related to the current bar. For example, among all bars which minimum prices are greater than current minimum price (yellow rectangle on the illustrations) I want to get bar with minimum (or maximum) price difference with current bar (blue arrows).
I tried to use ta.barssince() and similar funtions. But it seems to me that some sort of "series of series" types is needed to do what I want.
Is it possible to do such things with pine script? Or is using loops the only way?

