Average True Range Percent
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rex_wolfe

// Average True Range Percent - Arthur
// Version 1.0

//@version=5
indicator("Average True Range Percent - Arthur", shorttitle = "ATRP Arthur")

// Get user input
length = input.int(title = "Length", defval = 168, step = 1, minval = 1, tooltip = "Number of periods to apply smoothing.")
smoothing = input.string(title = "Smoothing", defval = "SMA", options=["SMA", "EMA", "WMA"], tooltip = "SMA - simple moving average, EMA - exponential moving average, WMA - weighted moving average.")

// Declare variables
var trp = float(0)
var atrp = float(0)

// Calculate true range percent
trp := ta.tr / hl2 * 100

// Calculate smoothed percentage range
if smoothing == "SMA"
    atrp := ta.sma(trp, length)
else if smoothing == "EMA"
    atrp := ta.ema(trp, length)
else if smoothing == "WMA"
    atrp := ta.wma(trp, length)

// Plot indicator
plot (trp, title = 'True range percent', color = color.new(color.silver, 60), style = plot.style_histogram)
plot(atrp, title = 'Smoothed average true range percent', color = color.new(color.blue, 0), style = plot.style_line)

// Roger, Candy, Elwood, Blacky, Bill. Not yet, Captain Chaos, not yet.