Expand description
Kagi line construction (price → alternating up/down lines).
A Kagi chart discards time and draws a single connected line that keeps
extending in the current direction while price advances, and reverses only
when price retraces from the running extreme by at least the reversal amount
H. Each completed line runs between two consecutive turning points (true
price extrema — the tops/“shoulders” and bottoms/“waists”).
Reversal construction (threshold H, extrema as turning points) follows:
Bogomolov (2013), “Pairs trading based on statistical variability of the
spread process”, Quantitative Finance 13(9): 1411–1430 — which formalises
the Kagi (and Renko) constructions as model-free, time-independent samplers
of a price path driven by a single threshold H: an up-move reverses at the
first price <= running_max − H, a down-move at the first >= running_min + H.
The yin/yang thickness follows the classic charting convention (Nison,
“Beyond Candlesticks”, 1994): the line turns yang (+1, thick/bullish)
when price rises above the prior shoulder, and yin (-1, thin/bearish)
when it falls below the prior waist; it holds its state in between. This is
the machine-readable Kagi signal, kept separate from any visualization.
Two surfaces kept in parity (see the proptest):
- streaming:
KagiBuilder::nextpushes one price, returns a line when the current direction reverses (elseNone); - batch:
kagi_batchfolds the builder over a price slice.
Structs§
- Kagi
Builder - Stateful Kagi builder with a fixed reversal amount
H. - Kagi
Line - One completed Kagi line, running between two consecutive turning points.
directionis +1 (up) / -1 (down);thicknessis +1 (yang), -1 (yin), or 0 (undetermined — no prior shoulder/waist has been broken yet).
Functions§
- kagi_
atr_ batch - ATR-reversal Kagi: reversal amount is
multiplier * atr(a single representative ATR), matching the ATR box convention of the other bar types. - kagi_
batch - Batch Kagi: fold
KagiBuilderover a price slice, returning completed lines.