Summary
CDL3WhiteSoldiers is RTTA's streaming detector for the Three white soldiers candlestick pattern.
Three advancing bullish bodies with opens inside the prior body and limited upper shadows.
Output follows the TA-Lib convention: +100 for a bullish match, -100
for a bearish match, and 0 when the pattern does not fire.
Update API
value = rtta.CDL3WhiteSoldiers(fillna=True).update(open, high, low, close)
# +100 bullish match, -100 bearish match (when directional), 0 no match
batch = rtta.CDL3WhiteSoldiers(fillna=True).batch(open, high, low, close)
update(...) consumes one OHLC bar. advance(...) uses the same inputs without
returning a Python value. Scalar batch(open, high, low, close) matches sequential
update on a fresh instance. With fillna=False, values are NaN until at least
3 bar(s) have been seen; with fillna=True (default), unmatched bars return 0.
Theory Of Operation
Candlestick patterns are short causal labels on bar geometry. They do not forecast returns by themselves; they tag structure (indecision, rejection, engulfing pressure, multi-bar reversals) that you can combine with trend, volatility, or volume context.
On every bar the engine forms:
A bar is bullish when \(C_t \ge O_t\) and bearish when \(C_t < O_t\). Bars are stored in a short ring; age \(0\) is the newest bar, age \(1\) the prior bar, and so on.
Shared predicates used below:
\(\overline B\) is the average body over the last up to five ring bars; \(\overline R\) is the average range over the same window.
For hammer-family patterns, a light prior trend uses the previous close versus the SMA of the two closes before it:
Recurrence
Push \((O_t,H_t,L_t,C_t)\) into the ring. Detection runs only when the ring has at least 3 bar(s).
Emit \(+100\) when \(a,b,c\) are all bullish,
If the predicate fails, emit \(0\). The C++ path is \(O(1)\) per update (fixed ring, no full-window rescan beyond a few bars).
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in class CDL3WhiteSoldiers,
built on shared CdlHistory / cdl:: geometry helpers. Thresholds are
streaming-friendly geometric rules; they are not a line-by-line port of every
TA-Lib average-body lookback table.
