Webby's RS Line
// 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(title = 'Webby\'s RS Line')

// inputs
index       = input.symbol(title='Index to Compare', defval='SPX')
upColor     = input.color(color.blue, 'RS Line Above 21 Color')
downColor   = input.color(color.red, 'RS Line Below 21 Color')
emaWidth    = input.int(title='EMA\'s Line Width', defval=1, minval=1, maxval=5)

//calculations
spx     = request.security(index, timeframe.period, low)
rs      = (low / spx) * 100
ema     = ta.ema(rs,21)
dist    = ((rs - ema) / rs) * 100
ema1    = ta.ema(dist, 3)
ema2    = ta.ema(dist, 13)

//colors
histCol = dist > 0 ? upColor : downColor
ema1Col = ema1 > ema1[1] ? color.lime : color.maroon
ema2Col = ema2 > ema2[1] ? color.green : color.red

//plots
plot(dist, 'Distance', color = histCol, style = plot.style_histogram, linewidth = 2)
plot(ema1, color = ema1Col, linewidth = emaWidth)
plot(ema2, color = ema2Col, linewidth = emaWidth)



