Indicator · Pine Script v6 · On the chart

Quantile (QUANTILE)

by mihakralj

This indicator calculates and plots a specified statistical quantile of a price series over a rolling lookback window using linear interpolation.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code54
Settings3inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 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

54 lines of Pine Script v6 from lib/statistics/quantile/quantile.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

quantile.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Quantile (QUANTILE)", shorttitle="QUANTILE", overlay=true, precision=8)

//@function Calculates the quantile of a series over a lookback period using linear interpolation.
//@param src {series float} The source series to calculate the quantile from.
//@param len {simple int} The lookback period. Must be greater than 0.
//@param q_level {simple float} The quantile level to calculate (between 0.0 and 1.0).
//@returns {series float} The calculated quantile value, or na if insufficient data.
quantile(series float src, simple int len, simple float q_level) =>
    if len <= 0
        runtime.error("Period must be greater than 0.")
    if q_level < 0.0 or q_level > 1.0
        runtime.error("Quantile Level must be between 0.0 and 1.0.")
    var float[] values_arr = array.new_float(0)
    array.clear(values_arr)
    for i = 0 to len - 1
        if not na(src[i])
            array.push(values_arr, src[i])
    int n_valid = array.size(values_arr)
    if n_valid == 0
        na
    else if n_valid == 1
        array.get(values_arr, 0)
    else
        array.sort(values_arr)
        if q_level == 0.0
            array.min(values_arr)
        else if q_level == 1.0
            array.max(values_arr)
        else
            float rank = q_level * (n_valid - 1)
            int k_floor = int(math.floor(rank))
            int k_ceil = int(math.ceil(rank))
            if k_floor == k_ceil
                array.get(values_arr, k_floor)
            else
                float val_floor = array.get(values_arr, k_floor)
                float val_ceil = array.get(values_arr, k_ceil)
                val_floor + (rank - k_floor) * (val_ceil - val_floor)

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

// Inputs
i_source = input.source(close, title="Source")
i_length = input.int(14, title="Period", minval=1)
i_quantile_level = input.float(0.25, title="Quantile Level (0.0-1.0)", minval=0.0, maxval=1.0, step=0.01)

// Calculate Quantile
quantile_value = quantile(i_source, i_length, i_quantile_level)

// Plot
plot(quantile_value, title="Quantile", color=color.new(color.yellow, 0, color=color.yellow, linewidth=2), linewidth=2)

Overview

Quantile (QUANTILE) draws directly on the price chart as an overlay line. Users can adjust the input source, the lookback period, and the quantile level between zero and one. The script serves strictly as an analytical tool without generating automated trading signals, entry triggers, or trade exit rules.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

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

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosei_source
Periodint14i_length
Quantile Level (0.0-1.0)float0.25i_quantile_level
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

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

1833 Tracker

by Allen1212
303 stars

1833 Tracker is an overlay indicator that visualizes historical buy and sell transactions executed by ARK Invest ETFs for the stock on the main price chart. It displays trade dates using green buy and red sell labels positioned relative to price bars, indicati

Indicator v4
Updated 2 years ago · None stated GitHub repository of 1833 Tracker

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