Consecutive

Returns how many bars in a row a condition was true.

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
conditionSeries<Boolean>--

Returns: Series<Number>

Consecutive is a built-in function - you can use it directly. Below is an example implementation:

1 function Consecutive(condition):
2 series counter:
3 once: 0
4 then: (counter[1] + 1) if condition else 0