Summary
RunBarGenerator implements a constant-threshold form of López de Prado tick
run bars. Buy and sell ticks accumulate in separate totals throughout the bar;
the bar closes when the dominant side reaches threshold. An intervening tick
of the opposite sign does not erase the earlier side's evidence.
Update API
ind = rtta.RunBarGenerator(threshold=10)
result = ind.update(close)
result = ind.update(close, volume) # same tick-count stopping rule
# result.bar_open, bar_close, bar_high, bar_low, bar_volume,
# result.direction, result.complete, result.bars
The one-argument overload reports the dominant tick count in bar_volume.
The volume overload still stops on dominant tick count, but reports the volume
accumulated by the dominant side.
Theory Of Operation
Run bars sample persistent order-flow imbalance rather than a consecutive streak. A sequence such as buy, sell, buy, buy contains three buy ticks and one sell tick; it is not reset by the sell. The adaptive formulation estimates the expected bar length and buy probability. RTTA exposes the underlying dominant side statistic with a fixed threshold, which is predictable and suitable when the caller estimates or retunes the threshold externally.
Recurrence
The tick rule is
Before any nonzero sign has been observed, a flat tick remains unclassified. For the active bar, maintain
The bar completes when
On completion, direction is \(+1\) when \(N_t^+\ge N_t^-\), otherwise
\(-1\); complete and bars are 1. OHLC covers every price assigned to the
bar, including sign changes. Side totals and OHLC reset for the next bar, while
the last price and last nonzero tick sign carry across the boundary.
For update(close, volume), \(V^+\) and \(V^-\) are also accumulated with
\(v_t^+=\max(v_t,0)\), solely to report
\(\max(V^+,V^-)\) as bar_volume.
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in
class RunBarGenerator. The first observation seeds price and OHLC but has no
tick direction.
