Indicator · Pine Script v6 · Own pane

Choppiness Index

by mihakralj

The Choppiness Index is a technical indicator designed to determine whether a market is trending or consolidating.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code64
Settings1inputs
LicenceMIT
Last update8 months ago28 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

64 lines of Pine Script v6 from indicators/dynamics/chop.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

chop.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Choppiness Index", "CHOP", overlay=false)

//@function Calculates Choppiness Index to measure market trendiness
//@param length Lookback period for calculation
//@returns CHOP value between 0 and 100 (lower=trending, higher=choppy)
//@references E.W. Dreiss, Australian commodity trader
//@optimized O(n) with circular buffers for TR sum and high/low tracking
chop(simple int length) =>
    if length <= 1
        runtime.error("Length must be > 1")
    var float sum_tr = 0.0
    var int head = 0
    var int filled = 0
    var array<float> atr_buf = array.new_float(length, na)
    var array<float> high_buf = array.new_float(length, na)
    var array<float> low_buf = array.new_float(length, na)
    float prevClose = nz(close[1], close)
    float tr = math.max(high - low, math.max(math.abs(high - prevClose), math.abs(low - prevClose)))
    float out = array.get(atr_buf, head)
    if not na(out)
        sum_tr -= out
    else
        filled += 1
    array.set(atr_buf, head, tr)
    array.set(high_buf, head, high)
    array.set(low_buf, head, low)
    sum_tr += tr
    int win = math.min(filled, length)
    float hhv = -1e100
    float llv = 1e100
    for k = 0 to win - 1
        int idx = (head - k + length) % length
        float h = array.get(high_buf, idx)
        float l = array.get(low_buf, idx)
        if not na(h)
            hhv := math.max(hhv, h)
        if not na(l)
            llv := math.min(llv, l)
    head := (head + 1) % length
    float price_range = hhv - llv
    float chop_value = na
    if win >= 2 and price_range > 0
        float log_ratio = math.log10(sum_tr / price_range)
        float log_len = math.log10(win)
        chop_value := 100.0 * log_ratio / log_len
        chop_value := math.max(0.0, math.min(100.0, chop_value))
    chop_value

// ---------- Main loop ----------

// Inputs
i_length = input.int(14, "Length", minval=2)

// Calculation
chop_value = chop(i_length)

// Plot
plot(chop_value, "CHOP", color=color.yellow, linewidth=2)
hline(61.8, "High Threshold", color=color.new(color.red, 50), linestyle=hline.style_dashed)
hline(38.2, "Low Threshold", color=color.new(color.green, 50), linestyle=hline.style_dashed)
hline(50, "Midline", color=color.new(color.gray, 70), linestyle=hline.style_dotted)

Overview

Choppiness Index calculates values between zero and one hundred using true range sums and price ranges over a user-defined lookback length. Lower values indicate a trending market, while higher values point to choppy price action. The indicator plots a single line in a separate pane with preset threshold reference lines. The main setting changes the lookback length. As an analytical indicator, it contains no trading execution rules.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptpinescript-indicatorstechnical-analysistradingview-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lengthint14i_length
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

This indicator plots an oscillator in a separate pane. It builds several SuperTrend series across a user-defined factor range and step, using ATR as the band width. On each bar it measures the distance between the close and each SuperTrend output, then groups

Indicator v5 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of AI SuperTrend Clustering Oscillator [LuxAlgo]

Choppiness Index

by mihakralj
99 stars

The script plots the Choppiness Index in a separate pane. It sums true range over a lookback and compares that sum with the highest-high to lowest-low range, then scales the result from 0 to 100. Lower readings indicate a trending market and higher readings in

Indicator v6 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of Choppiness Index

This indicator combines Chaikin Money Flow (CMF), a SuperTrend baseline, and an Average True Range (ATR) calculation inside a separate sub-pane. It calculates a standard 20-period CMF plotted as a line and colored histogram columns around a zero baseline, trac

Indicator v6 TrendVolume
Updated 6 months ago · Apache-2.0 GitHub repository of Institutional View: CMF & SuperTrend

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers