Bars Since¶
Flow · Counter
Bars elapsed since the input condition was last true (0 on the bar it fires, then 1, 2, …). NaN until the first occurrence. Gate entries on event recency ('signal fired ≤ N bars ago').
Bars Since counts how many bars have passed since a condition was last true. On the bar the condition fires it reads 0, then 1 on the next bar, 2 on the one after, and so on — resetting to 0 each time the condition fires again. It turns an event into a "how long ago" number you can gate on.
How it works¶
It watches the wired signal. Whenever the signal is true, the counter resets to 0; on every other bar it increments by one. Before the signal has ever been true there's nothing to count from, so the output is NaN. The result is a plain series you can compare against a threshold. Lookahead-free.
When to use it¶
Use it for recency logic: "only enter if the breakout happened ≤ 5 bars ago," "block re-entries for N bars after a signal," or "measure how stale a setup is." It's the clean way to express time-since-event without hand-rolling a counter, and it pairs naturally with a LessThan to build a freshness gate.
Example¶
Fresh-signal filter: wire your setup trigger into Bars Since, compare the count to a Constant of 5 with LessThan, and And that with your entry — so you only act while the setup is at most 5 bars old.
Tips & gotchas¶
- 0 on the firing bar, then counts up — mind the off-by-one when you threshold it.
- NaN until the first occurrence — no event yet means no count.
- Feeds a series (a count), not a signal — pair with a comparison to get a boolean gate.
Related blocks¶
Inputs¶
| Socket | Type | What to wire in |
|---|---|---|
| In | signal |
Condition to measure recency of. |
Outputs¶
| Output | Type | Plots as | Description |
|---|---|---|---|
| bars | series |
Line · sub-pane | Bars since the condition was last true. |
Reference auto-generated from the block catalog · category Flow.