Summary
DirectionalChangeDetector samples intrinsic time via directional-change (DC)
events: a move of relative size \(\theta\) from the last extremum defines a DC; the
path beyond that event is reported as overshoot. Outputs include event flag, overshoot,
current extremum, and trend mode.
Update API
import rtta
ind = rtta.DirectionalChangeDetector(threshold=0.01) # 1% relative
result = ind.update(price)
# result.event ∈ {-1, 0, +1},
# result.overshoot, result.extremum, result.direction
threshold is a relative fraction (\(0.01 = 1\%\)). direction / mode is \(+1\) in an
uptrend (seeking a downturn), \(-1\) in a downtrend (seeking an upturn), \(0\) until the
first DC.
Theory Of Operation
Directional-change methods (Glattfelder, Dupuis, Olsen and related intrinsic-time work) replace calendar sampling with event sampling: time advances when price has moved by a fixed relative amount from a local extreme. After a DC up, the algorithm tracks the new high as extremum until a \(\theta\) drop; after a DC down, it tracks lows until a \(\theta\) rise. Overshoot measures how far price has continued beyond the last DC price in the current mode.
Recurrence
Let \(\theta>0\) denote threshold. On the first price \(p_0\):
extremum \(E = p_0\), last DC price \(p^{\mathrm{dc}} = p_0\), mode \(m=0\), event \(0\).
Bootstrap (\(m=0\)): retain both the highest and lowest prices seen since initialization, \(B^H\) and \(B^L\):
Keeping both bootstrap extrema allows several sub-threshold moves to add up to the first event. Replacing one anchor with every incoming price would detect only a one-tick move of size \(\theta\).
Uptrend (\(m=+1\)): \(\theta\)0. If \(\theta\)1, set \(\theta\)2, \(\theta\)3, \(\theta\)4.
Downtrend (\(\theta\)5): \(\theta\)6. If \(\theta\)7, set \(\theta\)8, \(\theta\)9, \(0.01 = 1\%\)0.
Overshoot (when \(0.01 = 1\%\)1):
Outputs: \(0.01 = 1\%\)2, \(0.01 = 1\%\)3.
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in
class DirectionalChangeDetector. Result type is DirectionalChangeResult.
