Indicator · Pine Script v6 · Own pane

Theil Index (THEIL)

by mihakralj

The Theil Index indicator measures statistical inequality and distribution entropy in a price series over a specified lookback period.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code47
Settings2inputs
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

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

theil.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Theil Index (THEIL)", "THEIL", overlay=false, precision=6)

//@function Calculates Theil's T Index for a series over a lookback period.
//@param src series float Input data series (must be positive values).
//@param len simple int Lookback period (must be > 0).
//@returns series float The Theil's T Index, or na if data is not suitable.
theil_t_index(series float src, simple int len) =>
    if len <= 0
        float(na)
    float sum_src = 0.0
    int n_valid = 0
    float[] values_arr = array.new_float()
    for i = 0 to len - 1
        val = src[i]
        if not na(val) and val > 0
            array.push(values_arr, val)
            sum_src += val
            n_valid += 1
    if n_valid == 0
        float(na)
    float mean_val = sum_src / n_valid
    if mean_val <= 0
        float(na)
    float theil_sum = 0.0
    for i = 0 to n_valid - 1
        xi = array.get(values_arr, i)
        ratio = xi / mean_val
        if ratio > 0
            theil_sum += ratio * math.log(ratio)
    float theil_t = na
    if n_valid > 0
        theil_t := theil_sum / n_valid
    
    theil_t

// Inputs
i_source = input.source(close, title="Source (must be positive values)")
i_length = input.int(14, title="Lookback Period", minval=1)

// Calculation
theil_value = theil_t_index(i_source, i_length)

// Plot
plot(theil_value, "Theil T Index", color=color.new(color.yellow, 0, color=color.yellow, linewidth=2), linewidth=2)

Overview

Theil Index (THEIL) iterates through recent bars, calculates the mean price, and computes the sum of logarithmic price-to-mean ratios. Higher values reflect greater price dispersion across the lookback window. The script plots the resulting index as a line in a separate pane. Settings allow users to adjust the input source series and the lookback length.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

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
Source (must be positive values)sourceclosei_source
Lookback Periodint14i_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 calculates the distribution of close-to-close percentage changes using rate of change on closing prices. It bins percentage changes into intervals of 0.25 percent increments from negative to positive values and plots a normalized cumulative hist

Indicator v4 Volatility & bands
Updated 10 days ago · GPL-3.0 GitHub repository of Close-to-Close % Change Distribution

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
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

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