Since

Returns how many bars have passed since a condition was last true, including the bar on which the condition was true.

More specifically:

  • Returns
    0
    if the condition has never been true so far
  • Returns
    1
    if the condition is true on the current bar
  • Returns n if the condition has been false for (n - 1) bars but was true on the bar before that

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
conditionSeries<Boolean>--

Returns: Series<Number>

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

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