Returns the bars elapsed since condition was last true: 0 on a true bar, na before the first one.
ta.barssince counts up by one each bar and resets to 0 whenever condition is true. The count includes the current bar, so the answer on the bar where the condition holds is 0.
Until the condition has been true once, the result is na. Compare against a number only after checking for na, for example nz(ta.barssince(cond), 9999).
Syntax
ta.barssince(condition: series bool) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| condition | series bool | required | Boolean series. Each true bar resets the count to zero. |
Returns
series int: bars since the condition last held, or na until it first holds.
Remarks
- Compare with
ta.valuewhen, which reports a value from the last true bar rather than a distance.
Example
//@version=6
indicator("Bars since cross")
fast = ta.ema(close, 8)
slow = ta.ema(close, 21)
since = ta.barssince(ta.cross(fast, slow))
plot(since, "Bars", color = color.blue, style = plot.style_columns)See also
Runs on Sidechair