Returns how many bars back the highest value of source in the last length bars occurred, as 0 or a negative number.
ta.highestbars returns 0 when the highest value in the window is on the current bar, -1 when it was one bar ago, and so on to -(length - 1). When several bars tie for the highest value, the most recent one wins.
With a single argument, ta.highestbars(length), the source is high. Early bars, before the window is full, return na.
Syntax
ta.highestbars(source: series int/float, length: series int) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series to scan. Leave it out, passing only the length, to scan high. |
| length | series int | required | Number of bars in the window. A whole number of 1 or more. |
Returns
series int: the bar offset of the window's highest value: 0 for the current bar, negative for earlier ones.
Remarks
- Use the negative offset to read the bar itself: close[-
ta.highestbars(high, 10)] is the close on the highest-high bar.
Example
//@version=6
indicator("Bars since high")
back = -ta.highestbars(high, 20)
plot(back, "Bars since 20-bar high", color = color.orange, style = plot.style_columns)See also
Runs on Sidechair