Indicator · Pine Script v6 · On the chart

ADR Up to 10 Days With Targets

by MarvelousShabi· code credited to marvelouss25

This indicator calculates the average daily range from a user-selected lookback of one to ten completed days and rounds it to the instrument tick.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv6current
Lines of code143
Settings18inputs
LicenceMIT
Last update1 year ago7 Aug 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

143 lines of Pine Script v6 from adr-with-targets/adr-indicator.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

adr-indicator.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marvelouss25

//@version=6
indicator("ADR Up to 10 Days With Targets", "ADR", overlay = true)

// Table inputs
var table_group = "Table Settings" // Creates group for all table inputs
days_back = input.int(defval = 5, title = "Days", minval = 1, maxval = 10, step = 1, tooltip = "How many days back you want to calculate", group = table_group)
adr_toggle = input.bool(defval = true, title = 'ADR', inline = "TBT", group = table_group)
previous_days_toggle = input.bool(defval = true, title = 'Previous Days', inline = "TBT", group = table_group)
input_position = input.string(defval = "Top Right", title = "", inline = "TBT", group = table_group, 
     options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"])
input_background_color = input.color(defval = color.white, title = "Backround Color", group = table_group)
input_text_color =  input.color(defval = color.rgb(0, 0, 0), title = "Text Color", group = table_group)
input_frame_border_width= input.int(defval = 1, title = "Frame & Border Width", minval = 1, group = table_group, inline = "FB")
input_frame_border_color = input.color(defval = color.rgb(0, 0, 0), title = "", group = table_group, inline = "FB")

// Sets string values to actual positional values
position_strings_to_values = input_position ==  "Top Left"  ? position.top_left : 
                             input_position ==  "Top Center" ? position.top_center :
                             input_position ==  "Top Right" ? position.top_right :
                             input_position ==  "Middle Left"  ? position.middle_left : 
                             input_position ==  "Middle Center" ? position.middle_center :
                             input_position ==  "Middle Right" ? position.middle_right :
                             input_position ==  "Bottom Left"  ? position.bottom_left : 
                             input_position ==  "Bottom Center" ? position.bottom_center :
                             input_position ==  "Bottom Right" ? position.bottom_right :
                             na

// Calculates average range for specifed days_back
find_average() => math.sum((high - low)[1], days_back) / days_back
daily_range_average = request.security(symbol = syminfo.tickerid, timeframe = "D", expression = find_average(), lookahead = barmerge.lookahead_on) // Applys average function to only daily chart
rounded_average = math.round_to_mintick(daily_range_average) // Rounds daily average to closest tick value

// Creates table to display ADR and 5 previous days
var table adr_table = table.new(position = position_strings_to_values, columns = 1, rows = 2, bgcolor = input_background_color, frame_color = input_frame_border_color,
     frame_width = input_frame_border_width, border_color = input_frame_border_color, border_width = input_frame_border_width)

// Calculates each day range to use in table
day_range_one = request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high[1]- low[1], lookahead = barmerge.lookahead_on)
day_range_two = request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high[2]- low[2], lookahead = barmerge.lookahead_on)
day_range_three = request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high[3]- low[3], lookahead = barmerge.lookahead_on)
day_range_four = request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high[4]- low[4], lookahead = barmerge.lookahead_on)
day_range_five = request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high[5]- low[5], lookahead = barmerge.lookahead_on)

// Creates cells for table
if adr_toggle
    table.cell(adr_table, column = 0, row = 0, text = str.tostring(days_back) + " Day ADR: " + str.tostring(rounded_average))
if previous_days_toggle
    table.cell(adr_table, column = 0, row = 1, text = "Previous Days: " + str.tostring(day_range_one) + "   " + str.tostring(day_range_two) + "   "  
         + str.tostring(day_range_three) + "   " + str.tostring(day_range_four) + "   " + str.tostring(day_range_five)) 

// Inputs for bullish ADR target 
var bullish = "Bullish Target Settings" // Creates group for all bullish target settings
bullish_toggle = input.bool(defval = true, title = "", group = bullish, inline = "GBU")
input_bullish_label = input.string(defval = "Bullish Target", title = "", group = bullish, inline = "GBU")
input_bullish_line_style = input.string(defval = "Solid", title = "Style", options = ["Solid", "Dashed", "Dotted"], group = bullish, inline = "OBU")
input_bullish_line_width =  input.int(defval = 1, title = "", group = bullish, inline = "OBU")
input_bullish_line_color = input.color(defval = color.rgb(0, 0, 0), title = "", group = bullish, inline = "OBU")

// Inputs for bearish ADR target 
var bearish = "Bearish Target Settings" // Creates group for all bearish target settings
bearish_toggle = input.bool(defval = true, title = "", group = bearish, inline = "GBR")
input_bearish_label = input.string(defval = "Bearish Target", title = "", group = bearish, inline = "GBR")
input_bearish_line_style = input.string(defval = "Solid", title = "Style", options = ["Solid", "Dashed", "Dotted"], group = bearish, inline = "OBR")
input_bearish_line_width =  input.int(defval = 1, title = "", group = bearish, inline = "OBR")
input_bearish_line_color = input.color(defval = color.rgb(0, 0, 0), title = "", group = bearish, inline = "OBR")

// Sets string values to actual style values
bullish_style_strings_to_values = input_bullish_line_style ==  "Solid"  ? line.style_solid : 
                                  input_bullish_line_style ==  "Dashed" ? line.style_dashed :
                                  input_bullish_line_style ==  "Dotted" ? line.style_dotted :
                                  na

bearish_style_strings_to_values = input_bearish_line_style ==  "Solid"  ? line.style_solid : 
                                  input_bearish_line_style ==  "Dashed" ? line.style_dashed :
                                  input_bearish_line_style ==  "Dotted" ? line.style_dotted :
                                  na

// Declares variables used for ADR targets
is_new_day = ta.change(time("D")) != 0 // Checks if first candle of the new day has been made
var int open_time = na  
var int open_bar = na
var float day_high = na
var float day_low = na
var line bullish_target = na
var line bearish_target = na
var label bullish_label = na
var label bearish_label = na

// Creates inital ADR targets
if is_new_day 
    line.delete(bullish_target)
    line.delete(bearish_target)
    label.delete(bullish_label)
    label.delete(bearish_label)
    open_time := time
    open_bar := bar_index
    day_high := high
    day_low := low
    if bullish_toggle
        bullish_target := line.new(first_point = chart.point.from_index(open_bar, day_low + rounded_average), 
             second_point = chart.point.from_index(bar_index, day_low + rounded_average), color = input_bullish_line_color, 
             width = input_bullish_line_width, style = bullish_style_strings_to_values)
        bullish_label := label.new(chart.point.from_index(bar_index, day_low + rounded_average), text = input_bullish_label, 
             textcolor = input_bullish_line_color, style = label.style_label_left, color = color.rgb(255, 255, 255, 100))
    if bearish_toggle
        bearish_target := line.new(first_point = chart.point.from_index(open_bar,day_high - rounded_average), 
             second_point = chart.point.from_index(bar_index, day_high - rounded_average), color = input_bearish_line_color, 
             width = input_bearish_line_width, style = bearish_style_strings_to_values)
        bearish_label := label.new(chart.point.from_index(bar_index, day_high - rounded_average), text = input_bearish_label, 
             textcolor = input_bearish_line_color, style = label.style_label_left, color = color.rgb(255, 255, 255, 100))

// Checks if daily low has changed and updates bullish target accordingly 
if day_low != request.security(symbol = syminfo.tickerid, timeframe = "D", expression = low, lookahead = barmerge.lookahead_on) 
    line.delete(bullish_target)
    label.delete(bullish_label) 
    day_low := request.security(symbol = syminfo.tickerid, timeframe = "D", expression = low, lookahead = barmerge.lookahead_on)
    if bullish_toggle
        bullish_target := line.new(first_point = chart.point.from_index(open_bar, day_low + rounded_average), 
             second_point = chart.point.from_index(bar_index, day_low + rounded_average), color = input_bullish_line_color, 
             width = input_bullish_line_width, style = bullish_style_strings_to_values)
        bullish_label := label.new(chart.point.from_index(bar_index, day_low + rounded_average), text = input_bullish_label, 
             textcolor = input_bullish_line_color, style = label.style_label_left, color = color.rgb(255, 255, 255, 100))

// Checks if daily high has changed and updates bearish target accordingly
if day_high != request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high, lookahead = barmerge.lookahead_on)
    line.delete(bearish_target)
    label.delete(bearish_label)
    day_high := request.security(symbol = syminfo.tickerid, timeframe = "D", expression = high, lookahead = barmerge.lookahead_on)    
    if bearish_toggle
        bearish_target := line.new(first_point = chart.point.from_index(open_bar,day_high - rounded_average), 
             second_point = chart.point.from_index(bar_index, day_high - rounded_average), color = input_bearish_line_color, 
             width = input_bearish_line_width, style = bearish_style_strings_to_values)
        bearish_label := label.new(chart.point.from_index(bar_index, day_high - rounded_average), text = input_bearish_label, 
             textcolor = input_bearish_line_color, style = label.style_label_left, color = color.rgb(255, 255, 255, 100))
        
// Ensures ADR targets are at current bar
line.set_second_point(bullish_target, chart.point.from_index(bar_index, day_low + rounded_average))
line.set_second_point(bearish_target, chart.point.from_index(bar_index, day_high - rounded_average))
label.set_point(bullish_label, chart.point.from_index(bar_index, day_low + rounded_average))
label.set_point(bearish_label, chart.point.from_index(bar_index, day_high - rounded_average))

Overview

ADR Up to 10 Days With Targets draws optional bullish and bearish target lines from the current day's range on the price chart and shows a configurable table of the average plus recent daily ranges. Settings control the day count, line styles and colors, table placement, and whether the average or prior days appear. Daily values are requested with lookahead enabled, so displayed ranges can change before the daily bar closes.

Details

Published by

MarvelousShabi on GitHub

Code credit

marvelouss25, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Support & resistance, Screeners & dashboards

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
Daysint5days_back
ADRbooltrueadr_toggle
Previous Daysbooltrueprevious_days_toggle
input_positionstringTop Rightinput_position
Backround Colorcolorcolor.whiteinput_background_color
Text Colorcolorcolor.rgb(0, 0, 0)input_text_color
Frame & Border Widthint1input_frame_border_width
input_frame_border_colorcolorcolor.rgb(0, 0, 0)input_frame_border_color
bullish_togglebooltruebullish_toggle
input_bullish_labelstringBullish Targetinput_bullish_label
StylestringSolidinput_bullish_line_style
input_bullish_line_widthint1input_bullish_line_width
Show all 18 settings
SettingTypeDefaultVariable
input_bullish_line_colorcolorcolor.rgb(0, 0, 0)input_bullish_line_color
bearish_togglebooltruebearish_toggle
input_bearish_labelstringBearish Targetinput_bearish_label
StylestringSolidinput_bearish_line_style
input_bearish_line_widthint1input_bearish_line_width
input_bearish_line_colorcolorcolor.rgb(0, 0, 0)input_bearish_line_color
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

218 stars

This indicator maps market structure and supply and demand zones on the price chart. It marks validated and optional unvalidated swing highs and lows using a pivot length and extra confirmation bars. Consolidation and impulse moves are measured against ATR to

Indicator v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Market Structure + Supply/Demand
56 stars

This indicator marks forex trading sessions and opening ranges on the price chart. It can draw Sydney, Tokyo, Frankfurt, London, and New York session boxes or five- and fifteen-minute opening ranges, plus an optional opening channel and a day-open range. Day r

Indicator v5 Sessions & timeSupport & resistance Repaints
Updated 2 months ago · None stated GitHub repository of Day Trading Booster by DGT

ADR levels

by TamaraKGreen
46 stars

This indicator plots average daily range levels on the price chart, together with optional standard-deviation and Fibonacci levels scaled from that range. Users set the lookback in days, a scale factor, and the visibility, color, and line style of the ADR line

Indicator v5 Support & resistanceVolatility & bands
Updated 7 weeks ago · None stated GitHub repository of ADR levels
41 stars

ATR Matrix calculates Average True Range and a 50-period Simple Moving Average to display multi-tier volatility levels and risk-reward metrics. It project stop levels using negative ATR multiples from an entry price, alongside target levels from 0x to 11x ATR

Indicator v5 Volatility & bandsSupport & resistance

Zen Trading Toolkit

by Zen-Tim
29 stars

This indicator plots average bar range (ABR) measured move targets, opening range boxes, and historical key reference levels directly on the price chart. It projects bullish and bearish targets (0.5x, 1.0x, 1.5x, 2.0x ABR) from the previous session's close, al

Indicator v6 Support & resistanceVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of Zen Trading Toolkit
20 stars

This indicator calculates a base moving average (EMA, SMA, WMA, or HMA) and projects multiple symmetrical envelope bands around it directly on the price chart. Users can adjust the length, source, moving average type, and initial envelope multiplier. Additiona

Indicator v5 Moving averagesVolatility & bands
Updated 1 year ago · None stated GitHub repository of Multiple Moving Average Envelope

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