Docs

ta.barssince

Count the bars since a condition last held, such as the last up bar.

itm
ta.barssince(condition)

Bars since the condition was last true: 0 on the bar it is true.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
conditionSeriesbool--The condition to time.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
1 bar.
Missing values
na until the condition has been true at least once.

Example

itm
ta.barssince(close > open)
itm
plot(ta.barssince(close > open), "Bars since up bar")