Webby's Tight Indicator
// 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's Tight Indicator", shorttitle = 'Webby\'s Tight')

//inputs
upColor     = input.color(color.blue, 'Positive Ratio Color')
downColor   = input.color(color.red, 'Negative Ratio Color')
showEma     = input.bool(true, 'Show EMA')
showHiLo    = input.bool(false, 'Show Highest / Lowest Ratio')

//short atrs
short1    = ta.atr(3)
short2    = ta.atr(5)
short3    = ta.atr(8)
shortAvg  = (short1 + short2 + short3) / 3

//long atrs
long1   = ta.atr(55)
long2   = ta.atr(89)
long3   = ta.atr(144)
longAvg = (long1 + long2 + long3) / 3

// calculations
ratio   = (longAvg - shortAvg) / math.max(longAvg, shortAvg)
ema     = ta.ema(ratio, 5)

//colors
histCol = ratio > 0 ? upColor : downColor
emaCol  = ema > ema[1] ? color.green : color.red

//plots
plot(ratio, 'Ratio', color= histCol, style = plot.style_histogram)
plot(showEma ? ema : na, 'Ema of Ratio', color = emaCol)

//highest lowest
var label hLab = na 
var label lLab = na

highest = ta.highest(ratio,251)
lowest = ta.lowest(ratio,251)

if ratio == highest and showHiLo
    (hLab[1]).delete()
    hLab := label.new(bar_index, ratio, style = label.style_xcross ,size = size.tiny, color=color.green)
if ratio == lowest and showHiLo
    (lLab[1]).delete()
    lLab := label.new(bar_index, ratio, style = label.style_xcross ,size = size.tiny, color=color.green)

