Indicator · Pine Script v5 · On the chart

ADR % Ranges

by g-moe· code credited to goodgains

This indicator computes the Average Daily Range over the last specified number of days and plots the full ADR level along with one-third of the ADR and an anchor line on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code202
Settings19inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

202 lines of Pine Script v5 from Tradingview/adr-ranges.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

adr-ranges.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("ADR % Ranges", overlay = true, max_lines_count=500)

// @keywords: adr, average-daily-range, daily-range, adr-ranges, intraday-range, range-projection, open-based-levels, one-third-adr, range-bands, range-targets, historical-adr-levels, daily-volatility, previous-daily-ranges, day-trading, rolling-adr, range-extension, session-reset, range-labels, anchor-line, expected-move

// @error catching
if (timeframe.in_seconds() >= timeframe.in_seconds('D'))
    runtime.error('Timeframe cannot be greater than Daily')
// @error catching end


// @inputs
auto_color  = input.bool(true, title = 'Auto Color', group = 'General Settings', inline = '1')

adr_days    = input.int(5, title = 'Days', group = 'ADR Settings', inline = '1', maxval=20, minval = 1)
show_hist   = input.bool(false, title = 'Show Historical ADR Levels', group = 'ADR Settings', inline = '3')
show_table  = input.bool(true, title = 'Show Previous Daily Ranges Table', group = 'ADR Settings', inline = '4')
table_size  = input.string('Small', title = '', options = ['Small', 'Medium', 'Large'], group = 'ADR Settings', inline = '5')
table_x     = input.string('Center', title = '', options = ['Left', 'Center', 'Right'], group = 'ADR Settings', inline = '5')
table_y     = input.string('Bottom', title = '', options = ['Top', 'Middle', 'Bottom'], group = 'ADR Settings', inline = '5')

show_text   = input.bool(true, title = 'Show Text', group = 'Plot Settings', inline = '1')
txt_size    = input.string('Small', title = '', options = ['Small', 'Medium', 'Large'], group = 'Plot Settings', inline = '1')
offset      = input.int(50, title = 'Offset', group = 'Plot Settings', inline = '2', maxval = 100)

adr_style   = input.string('Solid', title = 'ADR​​​  ​ ', options = ['Solid', 'Dotted', 'Dashed'], group = 'Plot Settings', inline ='3')
adr_css     = input.color(color.new(#000000, 0), title = '', group = 'Plot Settings', inline ='3')
adr_show    = input.bool(false, title = 'Hide', group = 'Plot Settings', inline = '3')

third_style     = input.string('Dotted', title = '1/3 ADR', options = ['Solid', 'Dotted', 'Dashed'], group = 'Plot Settings', inline ='4')
third_css       = input.color(color.new(#000000, 0), title = '', group = 'Plot Settings', inline ='4')
third_show      = input.bool(false, title = 'Hide', group = 'Plot Settings', inline = '4')

anchor_style    = input.string('Dotted', title = 'Anchor ', options = ['Solid', 'Dotted', 'Dashed'], group = 'Plot Settings', inline ='5')
anchor_css      = input.color(color.new(#000000, 0), title = '', group = 'Plot Settings', inline ='5')
anchor_show     = input.bool(false, title = 'Hide', group = 'Plot Settings', inline = '5')
// @inputs end


// @function manage array
f_array_add_pop(array, new_value) =>
    array.unshift(array, new_value)
    array.pop(array)


// @function line styler
f_line_style(style) =>
    style == 'Solid' ? line.style_solid 
     : style == 'Dotted' ? line.style_dotted 
     : style == 'Dashed' ? line.style_dashed 
     : line.style_solid


// @function line color
f_line_color(_color) =>
    auto_color ? chart.fg_color : _color



// @calculate adr values
// reset = dayofweek != dayofweek[1]
reset = session.islastbar_regular[1]

var float track_highs   = 0.00
var float track_lows    = 0.00
var float today_adr     = 0.00

var adrs    = array.new_float(adr_days, 0.00)

var line adr_pos         = na
var line adr_third_pos   = na
var line adr_anchor      = na
var line adr_third_neg   = na
var line adr_neg         = na

var label adr_pos_lbl         = na
var label adr_third_pos_lbl   = na
var label adr_anchor_lbl      = na
var label adr_third_neg_lbl   = na
var label adr_neg_lbl         = na


track_highs := reset ? high : math.max(high, track_highs[1])
track_lows  := reset ? low : math.min(low, track_lows[1])


lbl_size    = txt_size == 'Small' ? size.tiny : txt_size == 'Medium' ? size.small : size.normal
tablesize   = table_size == 'Small' ? size.tiny : table_size == 'Medium' ? size.small : size.normal


if reset
    // shift values
    f_array_add_pop(adrs, math.round_to_mintick(track_highs[1] - track_lows[1]))
    today_adr := math.round_to_mintick(array.avg(adrs))

    // delete history
    if not show_hist
        line.delete(adr_pos[1])
        line.delete(adr_third_pos[1])
        line.delete(adr_anchor[1])
        line.delete(adr_third_neg[1])
        line.delete(adr_neg[1])

        label.delete(adr_pos_lbl[1])
        label.delete(adr_third_pos_lbl[1])
        label.delete(adr_anchor_lbl[1])
        label.delete(adr_third_neg_lbl[1])
        label.delete(adr_neg_lbl[1])
    else
        line.set_x2(adr_pos, bar_index)
        line.set_x2(adr_neg, bar_index)
        line.set_x2(adr_third_pos, bar_index)
        line.set_x2(adr_third_neg, bar_index)

        label.delete(adr_pos_lbl)
        label.delete(adr_neg_lbl)
        label.delete(adr_third_pos_lbl)
        label.delete(adr_third_neg_lbl)


    // draw new lines
    if not adr_show
        adr_pos := line.new(bar_index, open + today_adr, bar_index+offset, open + today_adr,
         xloc = xloc.bar_index, extend = extend.none,
         color = f_line_color(adr_css), style = f_line_style(adr_style))

        adr_neg := line.new(bar_index, open - today_adr, bar_index+offset, open - today_adr,
         xloc = xloc.bar_index, extend = extend.none,
         color = f_line_color(adr_css), style = f_line_style(adr_style))

        if show_text
            adr_pos_lbl := label.new(bar_index+offset, open + today_adr, text = str.tostring(adr_days) + 'ADR+',
             xloc = xloc.bar_index, size = lbl_size, textalign = text.align_left,
             textcolor = chart.fg_color, color = color.new(#000000,100), style = label.style_label_left)

            adr_neg_lbl := label.new(bar_index+offset, open - today_adr, text = str.tostring(adr_days) + 'ADR-',
             xloc = xloc.bar_index, size = lbl_size, textalign = text.align_left,
             textcolor = chart.fg_color, color = color.new(#000000,100), style = label.style_label_left)


    if not third_show
        adr_third_pos := line.new(bar_index, math.round_to_mintick(open + today_adr*.33), bar_index+offset, math.round_to_mintick(open + today_adr*.33),
         xloc = xloc.bar_index, extend = extend.none,
         color = f_line_color(third_css), style = f_line_style(third_style))

        adr_third_neg := line.new(bar_index, math.round_to_mintick(open - today_adr*.33), bar_index+offset, math.round_to_mintick(open - today_adr*.33),
         xloc = xloc.bar_index, extend = extend.none,
         color = f_line_color(third_css), style = f_line_style(third_style))

        if show_text
            adr_third_pos_lbl := label.new(bar_index+offset, math.round_to_mintick(open + today_adr*.33), text = '1/3ADR+',
             xloc = xloc.bar_index, size = lbl_size, textalign = text.align_left,
             textcolor = chart.fg_color, color = color.new(#000000,100), style = label.style_label_left)

            adr_third_neg_lbl := label.new(bar_index+offset, math.round_to_mintick(open - today_adr*.33), text = '1/3ADR-',
             xloc = xloc.bar_index, size = lbl_size, textalign = text.align_left,
             textcolor = chart.fg_color, color = color.new(#000000,100), style = label.style_label_left)


    if not anchor_show
        line.delete(adr_anchor)
        adr_anchor := line.new(bar_index, 1e20, bar_index, -1e20,
         xloc = xloc.bar_index, extend = extend.none,
         color = f_line_color(anchor_css), style = f_line_style(anchor_style))
    
else
    today_adr := today_adr[1]


    // update lines
    line.set_x2(adr_pos, bar_index+offset)
    line.set_x2(adr_neg, bar_index+offset)
    line.set_x2(adr_third_pos, bar_index+offset)
    line.set_x2(adr_third_neg, bar_index+offset)


    // update labels
    label.set_x(adr_pos_lbl, bar_index+offset)
    label.set_x(adr_neg_lbl, bar_index+offset)
    label.set_x(adr_third_pos_lbl, bar_index+offset)
    label.set_x(adr_third_neg_lbl, bar_index+offset)
// @calculate adr values end


// @table 
var table = table.new(position = position.bottom_center,
     columns = adr_days+1, rows = 1, bgcolor = chart.bg_color,
     frame_color = color.new(chart.fg_color,0), border_color = color.new(chart.fg_color,80),
     frame_width = 2, border_width = 1)


if barstate.islast and show_table
    for i = 0 to adr_days - 1
        table.cell(table, i, 0, text = str.tostring(array.get(adrs, i)), text_size = tablesize,
         text_color = chart.fg_color, bgcolor = chart.bg_color)

    table.cell(table, adr_days, 0, text = str.tostring(adr_days)+'ADR = ' + str.tostring(today_adr), 
         text_size = tablesize, bgcolor = color.new(chart.fg_color, 00), text_color = chart.bg_color)

Overview

ADR % Ranges displays historical ADR levels from prior sessions and a table showing previous daily ranges with customizable size, position, and text options. Auto color mode adjusts plotting colors to match the chart foreground. Users adjust day count, visibility of levels and table, and styling for lines. The script resets calculations at the start of each regular session.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Support & resistance

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.

Settings

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

SettingTypeDefaultVariable
Auto Colorbooltrueauto_color
Daysint5adr_days
Show Historical ADR Levelsboolfalseshow_hist
Show Previous Daily Ranges Tablebooltrueshow_table
table_sizestringSmalltable_size
table_xstringCentertable_x
table_ystringBottomtable_y
Show Textbooltrueshow_text
txt_sizestringSmalltxt_size
Offsetint50offset
ADR​​​  ​ stringSolidadr_style
adr_csscolorcolor.new(#000000, 0)adr_css
Show all 19 settings
SettingTypeDefaultVariable
Hideboolfalseadr_show
1/3 ADRstringDottedthird_style
third_csscolorcolor.new(#000000, 0)third_css
Hideboolfalsethird_show
Anchor stringDottedanchor_style
anchor_csscolorcolor.new(#000000, 0)anchor_css
Hideboolfalseanchor_show
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

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

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