Choppiness Index (True Range Box) (CHOPTR)
Summary
Choppiness Index with a true-range box: the true range travelled over a window against the span from its highest true high to its lowest true low. Bill Dreiss's form as published in 1993. Log-scaled so that a straight run reads 0 and bars that each fill the whole box read 100. Measures whether the market is trending, not in which direction: low values mean a directional run, high values sideways chop.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive
Formula
TH[j] = max(High[j], Close[j-1]) and TL[j] = min(Low[j], Close[j-1]), the true high and true low. TR[j] = TH[j] - TL[j].
S = SUM( TR[j] ) and R = MAX( TH[j] ) - MIN( TL[j] ), both over j = t-optInTimePeriod+1 .. t.
CHOPTR = 100 * log10( S / R ) / log10( optInTimePeriod ).
The first true range reads the close one bar before the window, so the first value needs optInTimePeriod + 1 bars.
Notes
- The box reaches the close just before each bar. Most charting platforms instead use the window's highest high minus its lowest low; that form is CHOP. The two differ only on bars where the close before the window lies outside the window's high-low range: a gap into the window.
- With every close inside its own bar's high-low range, the value stays within 0 to 100, up to rounding.
- A window with no true range reports 100.
- Dreiss's 3-bar smoothing of the index is not built in; apply a moving average to
outRealto obtain it.
Inputs
inHigh— High price of each barinLow— Low price of each barinClose— Close price of each bar
Outputs
outReal— Choppiness Index value
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 14 | 2–100000 | Number of bars in the window |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ✅ Uses Transcendental i |
| ☐ Input Must Be Positive |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double high[252]; /* your data, oldest first */
double low[252]; /* your data, oldest first */
double close[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_CHOPTR( 0, n - 1, high, low, close, 14, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %f\n", outNBElement, outBegIdx, out[outNBElement - 1] );use ta_lib::Core;
let high = vec![0.0; 252]; // your data, oldest first
let low = vec![0.0; 252]; // your data, oldest first
let close = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.choptr(0, high.len() - 1, &high, &low, &close, 14, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
double[] high = new double[252]; // your data, oldest first
double[] low = new double[252]; // your data, oldest first
double[] close = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.choptr(0, high.length - 1, high, low, close, 14, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + out[r.count() - 1]);using System;
using TALib;
var high = new double[252]; // your data, oldest first
var low = new double[252]; // your data, oldest first
var close = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Choptr(0, high.Length - 1, high, low, close, 14, outReal);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outReal = {outReal[r.Count - 1]}");import { choptr } from 'ta-lib';
const high = new Float64Array(252); // your data, oldest first
const low = new Float64Array(252); // your data, oldest first
const close = new Float64Array(252); // your data, oldest first
const { begIdx, values } = choptr({ high, low, close }, { timePeriod: 14 });
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.8.3 (ta-lib-python 0.8.3).
TA-Lib Definition: choptr.c · choptr.yaml
| Native | File |
|---|---|
| C | ta_CHOPTR.c |
| Rust | choptr.rs |
| Java | Core_CHOPTR.java |
| C# | Core_CHOPTR.cs |
| TypeScript | choptr.ts |
Python: talib.CHOPTR (ta-lib-python 0.8.3 or later), see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Choppiness Index, Dreiss Choppiness Index, True Range Choppiness Index
See Also
References
- Gibbons Burke, "Measuring market choppiness with chaos", Futures, October 1993, pp. 52-53
- Incredible Charts: Choppiness Index