Stable Coin Dominance RSI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DamonAndTheSea

//@version=5
indicator("Stable Coin Dominance RSI")

//Inputs
rsiLengthInput = input.int(14, minval=1, title="RSI Length")
includesUSDCInput = input.bool(true, "USDC", group="Included Stables")
includesUSDTInput = input.bool(true, "USDT", group="Included Stables")
includesBTC = input.bool(true, "BTC", group="Included Crypto")
includesALTS = input.bool(true, "ALTS", group="Included Crypto")

//Collect candle data for stables and total crypto market cap
usdc = request.security('CRYPTOCAP:USDC', timeframe.period, expression=close)
usdt = request.security('CRYPTOCAP:USDT', timeframe.period, expression=close)
btc = request.security('CRYPTOCAP:BTC', timeframe.period, expression=close)
total2 = request.security('CRYPTOCAP:TOTAL2', timeframe.period, expression=close)

//Calculate dominance and rsi
dom = ((includesUSDCInput == true ? usdc : 0) + (includesUSDTInput == true ? usdt : 0)) / 
     ((includesBTC == true ? btc : 0) + (includesALTS == true ? total2 : 0))
rsi = ta.rsi(dom, rsiLengthInput)

//UI
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
plot(rsi, color=color.fuchsia)