Summary
RunBarGenerator implements López de Prado tick run bars: a bar closes when the count
of consecutive same-sign ticks (tick rule on close) reaches an integer threshold.
Optional update(close, volume) still completes on tick-count but reports accumulated
run volume as bar_volume.
Update API
import rtta
ind = rtta.RunBarGenerator(threshold=10)
result = ind.update(close) # tick-count runs
result = ind.update(close, volume) # same rule; bar_volume = run volume
# result.bar_open, bar_close, bar_high, bar_low, bar_volume,
# result.direction, result.complete, result.bars
Flat ticks (\(c_t = c_{t-1}\)) do not break the run and do not increment the count. An opposite sign starts a new run at count 1 with OHLC reset to the current close.
Theory Of Operation
Run bars sample when a streak of buyer- or seller-initiated prints ends by length, not
by calendar time. They emphasize persistence of order flow: long same-sign sequences
close bars more often. RTTA's primary definition is tick count; the two-argument
overload accumulates volume for reporting but still thresholds on run_count.
Recurrence
Let \(N^\star = \max(\mathrm{threshold}, 1)\). Tick sign:
If \(s_t \neq 0\):
When \(n \ge N^\star\):
Volume overload: same sign rule; \(V_{\mathrm{run}} \mathrel{+}= v_t^+\) on continuation; completion still requires \(n \ge N^\star\), then \(V_{\mathrm{run}}\leftarrow 0\).
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in class RunBarGenerator.
Default threshold is 10 ticks.
