Real Dominance
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ProHorizon

//@version=5
indicator("Real Dominance", format = format.percent)
//set dominance symbols for single stablecoins
var main_symbol = input.symbol("CRYPTOCAP:BTC",title = "Choose ticker of the coin for which we will calculate dominance",tooltip = "Выберите график кэпа монеты для которой считаем реальную доминацию", inline = "Main symbol")
var maincolor = input.color(defval=color.gray,title="",inline = "Main symbol")
var compare_symbol = input.symbol("CRYPTOCAP:BTC.D",title = "Choose dominance ticker for above chosen coin to compare", tooltip = "Выберите график доминации монеты для сравнения", inline = "Comparable symbol")
var comparecolor = input.color(defval=color.red,title="",inline = "Comparable symbol")
var usdc = input.symbol("CRYPTOCAP:USDC",title = "Cap of USDC",group = "Choose another tickers if default will change")
var usdt = input.symbol("CRYPTOCAP:USDT",title = "Cap of USDT",group = "Choose another tickers if default will change")
var tusd = input.symbol("CRYPTOCAP:TUSD",title = "Cap of TUSD",group = "Choose another tickers if default will change")
var dai = input.symbol("CRYPTOCAP:DAI",title = "Cap of DAI",group = "Choose another tickers if default will change")
var busd = input.symbol("GLASSNODE:BUSD_MARKETCAP",title = "Cap of BUSD",group = "Choose another tickers if default will change")
var usdp = input.symbol("CRYPTOCAP:USDP",title = "Cap of USDP",group = "Choose another tickers if default will change")

var gusd = input.symbol("GLASSNODE:GUSD_MARKETCAP",title = "Cap of GUSD",group = "Choose another tickers if default will change")
var eurs = input.symbol("GLASSNODE:EURS_MARKETCAP",title = "Cap of EURS",group = "Choose another tickers if default will change")
var susd = input.symbol("GLASSNODE:SUSD_MARKETCAP",title = "Cap of SUSD",group = "Choose another tickers if default will change")
var usdk = input.symbol("GLASSNODE:USDK_MARKETCAP",title = "Cap of USDK",group = "Choose another tickers if default will change")
var husd = input.symbol("GLASSNODE:HUSD_MARKETCAP",title = "Cap of HUSD",group = "Choose another tickers if default will change")

var total = input.symbol("CRYPTOCAP:TOTAL",title = "Символ общей капы крипты",group = "Choose another tickers if default will change")

var usdd = input.symbol("",title = "Cap of USDD",group = "Tickers are not available for coins below at the moment of publication")
var ustc = input.symbol("",title = "Cap of USTC",group = "Tickers are not available for coins below at the moment of publication")
var tribe = input.symbol("",title = "Cap of TRIBE",group = "Tickers are not available for coins below at the moment of publication")
var frax = input.symbol("",title = "Cap of FRAX",group = "Tickers are not available for coins below at the moment of publication")
var usdj = input.symbol("",title = "Cap of USDJ",group = "Tickers are not available for coins below at the moment of publication")
var lusd = input.symbol("",title = "Cap of LUSD",group = "Tickers are not available for coins below at the moment of publication")
var vusdc = input.symbol("",title = "Cap of vUSDC",group = "Tickers are not available for coins below at the moment of publication")
var usdx = input.symbol("",title = "Cap of USDX",group = "Tickers are not available for coins below at the moment of publication")
var xsgd = input.symbol("",title = "Cap of XSGD",group = "Tickers are not available for coins below at the moment of publication")
var vbusd = input.symbol("",title = "Cap of vBUSD",group = "Tickers are not available for coins below at the moment of publication")
var vai = input.symbol("",title = "Cap of VAI",group = "Tickers are not available for coins below at the moment of publication")
var euroc = input.symbol("",title = "Cap of EUROC",group = "Tickers are not available for coins below at the moment of publication")
var cusd = input.symbol("",title = "Cap of CUSD",group = "Tickers are not available for coins below at the moment of publication")
var ousd = input.symbol("",title = "Cap of OUSD",group = "Tickers are not available for coins below at the moment of publication")
var fei = input.symbol("",title = "Cap of FEI",group = "Tickers are not available for coins below at the moment of publication")
var vusdt = input.symbol("",title = "Cap of vUSDT",group = "Tickers are not available for coins below at the moment of publication")
var sbd = input.symbol("",title = "Cap of SBD",group = "Tickers are not available for coins below at the moment of publication")
var rsv = input.symbol("",title = "Cap of RSV",group = "Tickers are not available for coins below at the moment of publication")
var krt = input.symbol("",title = "Cap of KRT",group = "Tickers are not available for coins below at the moment of publication")
var gyen = input.symbol("",title = "Cap of GYEN",group = "Tickers are not available for coins below at the moment of publication")
var ceur = input.symbol("",title = "Cap of CEUR",group = "Tickers are not available for coins below at the moment of publication")
var bidr = input.symbol("",title = "Cap of BIDR",group = "Tickers are not available for coins below at the moment of publication")
var idrt = input.symbol("",title = "Cap of IDRT",group = "Tickers are not available for coins below at the moment of publication")
var vdai = input.symbol("",title = "Cap of vDAI",group = "Tickers are not available for coins below at the moment of publication")
var float domination = na

//calculate dominance using Close data from other stablecoins' caps
domination := 100*request.security(main_symbol, timeframe = timeframe.period, expression = close) / 
 ((request.security(total, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdt, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdc, timeframe = timeframe.period, expression = close)) - 
 (request.security(dai, timeframe = timeframe.period, expression = close)) - 
 (request.security(tusd, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdp, timeframe = timeframe.period, expression = close)) - 
 (request.security(gusd, timeframe = timeframe.period, expression = close)) - 
 (request.security(eurs, timeframe = timeframe.period, expression = close)) - 
 (request.security(susd, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdk, timeframe = timeframe.period, expression = close)) - 
 (request.security(husd, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdd, timeframe = timeframe.period, expression = close)) - 
 (request.security(ustc, timeframe = timeframe.period, expression = close)) - 
 (request.security(tribe, timeframe = timeframe.period, expression = close)) - 
 (request.security(frax, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdj, timeframe = timeframe.period, expression = close)) - 
 (request.security(lusd, timeframe = timeframe.period, expression = close)) - 
 (request.security(vusdc, timeframe = timeframe.period, expression = close)) - 
 (request.security(usdx, timeframe = timeframe.period, expression = close)) - 
 (request.security(xsgd, timeframe = timeframe.period, expression = close)) - 
 (request.security(vbusd, timeframe = timeframe.period, expression = close)) - 
 (request.security(vai, timeframe = timeframe.period, expression = close)) - 
 (request.security(euroc, timeframe = timeframe.period, expression = close)) - 
 (request.security(cusd, timeframe = timeframe.period, expression = close)) - 
 (request.security(ousd, timeframe = timeframe.period, expression = close)) - 
 (request.security(fei, timeframe = timeframe.period, expression = close)) - 
 (request.security(vusdt, timeframe = timeframe.period, expression = close)) - 
 (request.security(sbd, timeframe = timeframe.period, expression = close)) - 
 (request.security(rsv, timeframe = timeframe.period, expression = close)) - 
 (request.security(krt, timeframe = timeframe.period, expression = close)) - 
 (request.security(gyen, timeframe = timeframe.period, expression = close)) - 
 (request.security(ceur, timeframe = timeframe.period, expression = close)) - 
 (request.security(bidr, timeframe = timeframe.period, expression = close)) - 
 (request.security(idrt, timeframe = timeframe.period, expression = close)) - 
 (request.security(vdai, timeframe = timeframe.period, expression = close)) - 
 (request.security(busd, timeframe = timeframe.period, expression = close)))

//draw dominance line
plot(domination, color = maincolor, trackprice = true)
//draw comparable line
plot(request.security(compare_symbol, timeframe = timeframe.period, expression = close), color = comparecolor, trackprice = true)