ADR & ATR Overlay

This indicator will display the following as an overlay on your chart:

  • ADR
  • % of ADR
  • ADR % of Price
  • ATR
  • % of ATR
  • ATR % of Price

Description:

  • ADR : Average Day Range
  • % of ADR : Percentage that the current price move has covered its average.
  • ADR % of Price : The percentage move implied by the average range.
  • ATR : Average True Range
  • % of ATR : Percentage that the current price move has covered its average.
  • ATR % of Price : The percentage move implied by the average true range.

Options:

  • Time Frame
  • Length
  • Smoothing
  • Enable or Disable each value
  • Text Color
  • Background Color

How to use this indicator:
The ADR and ATR can be used to provide information about average price moves to help set targets, stop losses, entries and exits based on the potential average moves.

Example: If the “% of ADR” is reading 100%, then 100% of the asset’s average price range has been covered, suggesting that an additional move beyond the range has a lower probability.

Example: “ADR % of Price” provides potential price movement in percentage which can be used to asses R/R for asset.

Example: ADR (D) reading is 100% at market close but ATR (D) is at 70% at close. This suggests that there is a potential move of 30% in Pre/Post market as suggested by averages.

Notes:
These indicators are available as oscillators to place under your chart through trading view but this indicator will place them on the chart in numerical only format.

Please feel free to modify this script if you like but please acknowledge me, I am only a hobby coder so this takes some time & effort.

May 8

Release Notes

ADR & ATR Overlay

This indicator will display the following as an overlay on your chart:
ADR
% of ADR
ADR % of Price
ATR
% of ATR
ATR % of Price

Description:
ADR : Average Day Range
% of ADR : Percentage that the current price move has covered its average.
ADR % of Price : The percentage move implied by the average range.
ATR : Average True Range
% of ATR : Percentage that the current price move has covered its average.
ATR % of Price : The percentage move implied by the average true range.

Options:
Time Frame
Length
Smoothing
Enable or Disable each value
Text Color
Background Color

How to use this indicator:
The ADR and ATR can be used to provide information about average price moves to help set targets, stop losses, entries and exits based on the potential average moves.

Example: If the “% of ADR” is reading 100%, then 100% of the asset’s average price range has been covered, suggesting that an additional move beyond the range has a lower probability.

Example: “ADR % of Price” provides potential price movement in percentage which can be used to asses R/R for asset.

Example: ADR (D) reading is 100% at market close but ATR (D) is at 70% at close. This suggests that there is a potential move of 30% in Pre/Post market as suggested by averages.

Notes:
These indicators are available as oscillators to place under your chart through trading view but this indicator will place them on the chart in numerical only format.

Please feel free to modify this script if you like but please acknowledge me, I am only a hobby coder so this takes some time & effort.

May 14

Release Notes

Added alert options for ADR / ADR % crossing thresholds.

Example: If the price oscillation covers a user defined percentage of the ADR’s average range the alert can be triggered.

Example: During long periods of low price oscillation you can be alerted to when the price action exceeds specified levels.

May 15

Release Notes

Added ability to change position of the table.

May 15

Release Notes

Added an additional (optional) top row to the table so values aren’t covered by Trading View’s buttons if placed in top right corner.

If you prefer your data in this format (overlays) check out my VOL & AVG Overlay.


// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © abbadon9 [If you modify this script please acknowledge me.]

//@version=6
indicator("ADR & ATR Overlay", shorttitle="ADR/ATR", overlay=true)

// === Inputs ===
lengthInput = input.int(14, title="ADR/ATR Length")
timeframeInput = input.timeframe("D", title="Select Timeframe for ADR & ATR Calculation")
waitForClose = input.bool(true, title="Wait for Daily Bar Close")
adrSmoothingMethod = input.string("SMA", title="ADR Smoothing", options=["SMA", "EMA", "RMA", "WMA"])
atrSmoothingMethod = input.string("RMA", title="ATR Smoothing", options=["SMA", "EMA", "RMA", "WMA"])
show_adr = input(true, title="Show ADR")
show_adr_pct = input(true, title="Show ADR % (Timeframe)")
show_adr_pct_potential = input(true, title="Show ADR % of Price (Potential Move)")
show_atr = input(true, title="Show ATR")
show_atr_pct = input(true, title="Show ATR % (Timeframe)")
show_atr_pct_potential = input(true, title="Show ATR % of Price (Potential Move)")
bg_col = input(color.new(color.black, 100), title="Background Color")
text_col = input(color.white, title="Text Color")

// === New Input: Toggle Extra Top Row ===
addEmptyTopRow = input.bool(true, "Add Empty Top Row")

// === Alert Threshold Inputs ===
adrPctAlertThreshold = input.float(100.0, title="ADR % Alert Threshold")
atrPctAlertThreshold = input.float(100.0, title="ATR % Alert Threshold")

// === Table Position Input ===
tablePosInput = input.string("Bottom Right", title="Table Position", options=["Top Left", "Top Right", "Bottom Left", "Bottom Right"])
tablePos = switch tablePosInput
    "Top Left" => position.top_left
    "Top Right" => position.top_right
    "Bottom Left" => position.bottom_left
    => position.bottom_right

// === Daily High/Low tracking for intraday ADR% ===
var float dayHigh = na
var float dayLow = na
isNewDay = dayofweek != dayofweek[1]

if isNewDay
    dayHigh := high
    dayLow := low
else
    dayHigh := math.max(dayHigh, high)
    dayLow := math.min(dayLow, low)

// === Function to apply smoothing ===
applySmoothing(method, src, len) =>
    (method == "SMA" ? ta.sma(src, len) :
     method == "EMA" ? ta.ema(src, len) :
     method == "RMA" ? ta.rma(src, len) :
     method == "WMA" ? ta.wma(src, len) :
     na)

// === Function to calculate ADR, ATR, TR with selected smoothing ===
calcValues() =>
    highTF = high
    lowTF = low
    closePrevTF = close[1]
    tr = math.max(highTF - lowTF, math.abs(highTF - closePrevTF), math.abs(lowTF - closePrevTF))
    priceRange = highTF - lowTF
    adrSmoothed = applySmoothing(adrSmoothingMethod, priceRange, lengthInput)
    atrSmoothed = applySmoothing(atrSmoothingMethod, tr, lengthInput)
    [adrSmoothed, atrSmoothed, tr]

// === Call function using user-selected timeframe ===
[adr, atr, todayTR] = request.security(syminfo.tickerid, timeframeInput, calcValues(), lookahead=waitForClose ? barmerge.lookahead_on : barmerge.lookahead_off)

// === Percent calculations ===
currentDayRange = dayHigh - dayLow
adrPct = adr != 0 ? (currentDayRange / adr) * 100 : na
adrPctStr = str.tostring(adrPct, "#.##") + "%"

atrPct = atr != 0 ? (todayTR / atr) * 100 : na
atrPctStr = str.tostring(atrPct, "#.##") + "%"

// === ADR/ATR % of Price ===
adrPotentialPct = close != 0 ? (adr / close) * 100 : na
adrPotentialPctStr = str.tostring(adrPotentialPct, "#.##") + "%"

atrPotentialPct = close != 0 ? (atr / close) * 100 : na
atrPotentialPctStr = str.tostring(atrPotentialPct, "#.##") + "%"

// === Table Display ===
var table t = table.new(tablePos, 2, 8, bgcolor=bg_col)

if barstate.islast
    int row = 0
    if addEmptyTopRow
        table.cell(t, 0, row, "", text_color=text_col, bgcolor=bg_col)
        table.cell(t, 1, row, "", text_color=text_col, bgcolor=bg_col)
        row := row + 1
    if show_adr
        table.cell(t, 0, row, "ADR (" + adrSmoothingMethod + ")", text_color=text_col)
        table.cell(t, 1, row, str.tostring(adr, "#.##"), text_color=text_col)
        row := row + 1
    if show_adr_pct
        table.cell(t, 0, row, "% of ADR", text_color=text_col)
        table.cell(t, 1, row, adrPctStr, text_color=text_col)
        row := row + 1
    if show_adr_pct_potential
        table.cell(t, 0, row, "ADR % of Price", text_color=text_col)
        table.cell(t, 1, row, adrPotentialPctStr, text_color=text_col)
        row := row + 1
    if show_atr
        table.cell(t, 0, row, "ATR (" + atrSmoothingMethod + ")", text_color=text_col)
        table.cell(t, 1, row, str.tostring(atr, "#.##"), text_color=text_col)
        row := row + 1
    if show_atr_pct
        table.cell(t, 0, row, "% of ATR", text_color=text_col)
        table.cell(t, 1, row, atrPctStr, text_color=text_col)
        row := row + 1
    if show_atr_pct_potential
        table.cell(t, 0, row, "ATR % of Price", text_color=text_col)
        table.cell(t, 1, row, atrPotentialPctStr, text_color=text_col)

// === Alert Toggles ===
enableAdrAlert = input.bool(true, "Enable ADR Alert")
enableAtrAlert = input.bool(true, "Enable ATR Alert")

// === Alerts ===
alertcondition(enableAdrAlert and adrPct > adrPctAlertThreshold, title="ADR % Exceeds Threshold", message="ADR % exceeded threshold")
alertcondition(enableAtrAlert and atrPct > atrPctAlertThreshold, title="ATR % Exceeds Threshold", message="ATR % exceeded threshold")