Create a Choppiness Index chart study
Use a time-based chart. In Edit Studies and Strategies, select Create, name the study ChoppinessIndexCheck, and replace the starter text with the code below. Save the study, add it to the active chart and apply it. The default lookback is 14 bars. The chart version plots CHOP and two separate reference lines.
declare lower;
input length = 14;
Assert(length >= 2, "Length must be at least 2.");
def totalTR = Sum(TrueRange(high, close, low), length);
def windowRange = Highest(high, length) - Lowest(low, length);
plot CHOP = if windowRange > 0 and totalTR > 0
then 100 * Log(totalTR / windowRange) / Log(length)
else Double.NaN;
plot UpperBand = 61.8;
plot LowerBand = 38.2;
CHOP.SetDefaultColor(Color.CYAN);
UpperBand.SetDefaultColor(Color.GRAY);
LowerBand.SetDefaultColor(Color.GRAY);