Choppiness Index
All functions · nseries package
Chop
func (s Series) Chop(h, l, c Series, n int) Series
Chop computes the Choppiness Index from a single trailing sum of true ranges. At bar i it computes
100 * log10(sum(TR[j]) / (max(h[j]) - min(l[j]))) / log10(n)
over j = i-n+1 through i, where
TR[j] = max(h[j], c[j-1]) - min(l[j], c[j-1]), j >= 1.
The receiver is ignored. Invalid n, empty high, or mismatched OHLC lengths return an empty Series; otherwise the output has len(h) entries. For n >= 2, the first valid index is n, since index zero has no previous close. Earlier entries, insufficient history, and all entries for n == 1 are zero.
A zero range with otherwise finite active TR and extrema returns zero. Nonfinite values propagate naturally, with NaN taking precedence over that guard, and expire with their affected windows. Boundary gaps to the previous close can produce values above 100; results are not clipped. Formula reference: https://www.tradingview.com/support/solutions/43000501980-choppiness-index-chop/
The output is nominally on a 0 to 100 scale. The warm-up reads 0, not NaN: the first valid index is n and the minimum length is n + 1. 0 reads as a perfect trend, since a value below 38.2 is usually read as trending, so trim (Window(-n)) or mask (SetN(n, math.NaN())) the warm-up first.