KeltnerChannel

Incremental, causal technical analysis documentation

Summary

KeltnerChannel is RTTA's streaming modern Keltner channel: an EMA of close surrounded by a multiple of Wilder ATR.

Update API

result = rtta.KeltnerChannel(
    span=20.0,
    window_atr=20.0,
    fillna=False,
    multiplier=2.0,
).update(close, high, low)
# result.middle, result.upper, result.lower

advance(...) consumes the same values without materializing a Python result. See KeltnerChannelOriginal for Chester Keltner's earlier typical-price formulation.

Theory Of Operation

The EMA supplies a responsive trend center. ATR measures recent true range, including overnight gaps, so the envelope expands and contracts with volatility.

Recurrence

Let \(s\), \(n\), and \(k\) denote span, window_atr, and multiplier, respectively.

\[\alpha=\frac{2}{s+1},\qquad M_t=\alpha c_t+(1-\alpha)M_{t-1}\]
\[TR_t=\max(H_t-L_t,|H_t-C_{t-1}|,|L_t-C_{t-1}|)\]

ATR is initialized by the running mean of true range through its first \(n\) observations, then follows Wilder smoothing:

\[ATR_t=\frac{(n-1)ATR_{t-1}+TR_t}{n}.\]

The channel is

\[middle_t=M_t,\qquad upper_t=M_t+kATR_t,\qquad lower_t=M_t-kATR_t.\]

With fillna=False, all three fields are NaN until \(\max(\lfloor s\rfloor,\lfloor n\rfloor,1)\) observations have been consumed. With fillna=True, partial EMA and ATR values are returned immediately.

Composed Primitives

EWMA, ATR

Implementation Notes

The recurrence is implemented in src/rtta/indicator.cpp in class KeltnerChannel.

Reference