Indicator · Pine Script v5 · On the chart

Inverse Choppiness Index

by ryangaraygay

This indicator calculates the Choppiness Index to gauge market consolidation versus trending conditions.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code44
Settings7inputs
LicenceMIT
Last update1 year ago10 Apr 2025

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

44 lines of Pine Script v5 from inverse-choppines-index.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

inverse-choppines-index.pine
//@version=5
indicator(title="Inverse Choppiness Index", shorttitle="TREND", format=format.price, precision=2, overlay = true)

length = input.int(14, minval=1)
ci = 100 * math.log10(math.sum(ta.atr(1), length) / (ta.highest(length) - ta.lowest(length))) / math.log10(length)
inverse_ci = (ci * -1) + 50
offset = input.int(0, "Offset",  minval = -500, maxval = 500)

var color_veryhigh = input.color(color.new(color.black, 30), "very high")
var color_high = input.color(color.new(color.gray, 30), "high")
var color_low = input.color(color.new(color.blue, 30), "low")
var color_verylow = input.color(color.new(color.green, 30), "very low")

color_ci = ci > 61.8 ? color_veryhigh: (ci > 50 ? color_high : (ci > 38.2 ? color_low : color_verylow))

// plot(inverse_ci, "CHOP", color=color_ci, offset = offset, style = plot.style_columns)
// bgcolor(inverse_ci < 0 ? color.new(color.gray, 90) : color.white)

// Define the coordinates for the rectangle
var int x1 = na
var float y1 = na
var int x2 = na
var float y2 = na

// Coordinates for the rectangle (these could be based on your logic)
x1 := bar_index[length] // starting x-coordinate
y1 := ta.highest(length) // starting y-coordinate
x2 := bar_index // ending x-coordinate
y2 := ta.lowest(length) // ending y-coordinate

// Create a filled rectangle
var box rect = na

string my_session = input.session("0830-1500", title='NYSession')
timeinrange(res, sess) => not na(time(res, sess)) ? true : false
in_session = timeinrange(timeframe.period, my_session)


// Create new filled rectangle
// if inverse_ci < 0
if ci > 50 and in_session
    // if (na(rect) == false)
    //     box.delete(rect)
    rect := box.new(left=x1, top=y1, right=x2, bottom=y2, border_width=0, bgcolor=color.new(color.gray, 95))

Overview

When the Choppiness Index indicates high choppiness above a threshold of 50 during a defined trading session, the script plots a transparent rectangle over the price chart spanning the highest high and lowest low of the lookback period. Users can adjust the calculation length, session time filter, and threshold color preferences.

Details

Published by

ryangaraygay on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands, Sessions & time

Markets

Any symbol

Timeframes

M15-H1

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.

Settings

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

SettingTypeDefaultVariable
lengthint14length
Offsetint0offset
very highcolorcolor.new(color.black, 30)color_veryhigh
highcolorcolor.new(color.gray, 30)color_high
lowcolorcolor.new(color.blue, 30)color_low
very lowcolorcolor.new(color.green, 30)color_verylow
NYSessionsession0830-1500my_session
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

92 stars

This indicator classifies the market into gamma regime types (negative gamma trend, positive gamma mean-reversion, or transition) by calculating a composite score based on daily ATR ratios, session VWAP crossover frequencies, and opening range displacement. It

Indicator v5 Volatility & bandsTrend
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev GEX Regime & Trap

42H Map

by aurorascarlet1102
4 stars

42H Map calculates custom time cycle structures and session ranges directly on the price chart. It partitions market action into forty-two-hour cycles, ten-and-a-half-hour micro-sessions, half-week periods, and quarter-month segments to track highs, lows, and

Indicator v5 Sessions & timeSupport & resistance
Updated 3 months ago · None stated GitHub repository of 42H Map

This indicator plots several linear regression channels on the price chart. Each channel can be hidden or drawn as a channel, bands, or both, and its lookback is anchored to price, volume, oscillator extremes, calendar periods, sessions, or corporate events. P

Indicator v6 TrendVolatility & bands
Updated 8 months ago · None stated GitHub repository of Multi-Anchored Linear Regression Channels [TANHEF]

4x4 Futures Ghost Matrix

by knectardev
1 stars

This indicator generates intraday trading signals by combining dual-sigma standard deviation bands, Heikin Ashi candle vectors, and a four-bar confluence score. It triggers long and short signals during defined trading sessions using either mean-reversion boun

Indicator v5 Volatility & bandsMean reversion
Updated 9 months ago · None stated GitHub repository of 4x4 Futures Ghost Matrix

Gold Dominator Pro

by thanvish21
1 stars

Gold Dominator Pro is a multi-indicator overlay designed primarily for gold trading. It combines higher-timeframe exponential moving averages with momentum oscillators like RSI, MACD, and StochRSI, alongside volatility tools such as ATR, Bollinger Bands, and A

Indicator v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Gold Dominator Pro

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