Webby % Off 52 Week
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amphibiantrading

//@version=5
indicator("Webby % Off 52 Week", shorttitle = '% Off High')
//input
lineCol = input.color(color.blue, '% Off Line Color')
z1Col   = input.color(color.green, 'Zone 1 (0-8%) Background Color')
z2Col   = input.color(color.yellow, 'Zone 2 (8-15%) Background Color')
z3Col   = input.color(color.red, 'Zone 3 (16-25%) Background Color')
off     = input.bool(true, 'Cut off at 25%', tooltip = 'If selected anything more than 25% off the high will be drawn at 25% to keep the scaling and plot in the zones')

//caluclations
yearhigh = ta.highest(high, 251)
distAway = ((close-yearhigh) / yearhigh) * 100
if distAway < -25 and off
    distAway := -25

//plots
plot(distAway, '% Off High', lineCol)

//hlines for fill zones
z1Top = hline(0, 'Z1', color.new(color.green,100))
z1Btm = hline(-8.0, 'Z1', color.new(color.green,100))
z2Top = hline(-8.1, 'Z2', color.new(color.yellow,100))
z2Btm = hline(-15.0, 'Z2', color.new(color.yellow,100))
z3Top = hline(-15.1, 'Z3', color.new(color.red,100))
z3Btm = hline(-25.0, 'Z3', color.new(color.red,100))

//fill the zones
fill(z1Top, z1Btm, z1Col)
fill(z2Top, z2Btm, z2Col)
fill(z3Top, z3Btm, z3Col)

