Combined Spot Volume | Crypto v1.1 [kAos]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Script by @eAkosKovacs
//@version=5
indicator('Combined Spot Volume | Crypto v1.1 [kAos]', 'CSV v1.1 [kAos]', precision=0, scale=scale.right)

i_showMa = input(true, 'Show Volume MA', inline = '0')
i_ma_period = input(20, '   Period', inline = '0')
i_showExchanges = input(false, 'Plot individual exchanges')

exchange_1 = input.string('BITFINEX' , 'Exchange 1', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_2 = input.string('COINBASE' , 'Exchange 2', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_3 = input.string('BITSTAMP' , 'Exchange 3', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_4 = input.string('KRAKEN'   , 'Exchange 4', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_5 = input.string('BINANCE'  , 'Exchange 5', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_6 = input.string('GEMINI'   , 'Exchange 6', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_7 = input.string('BYBIT'    , 'Exchange 7', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_8 = input.string('KUCOIN'   , 'Exchange 8', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )
exchange_9 = input.string('OKEX'     , 'Exchange 9', inline = '1', group = 'If the Table shows "NaN" than check the spelling of the exchange or the "Tradingpair" might not be availabe on that exchange.' )

base = syminfo.basecurrency
fiat = syminfo.currency

exchange_1_volume =     request.security(exchange_1 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_2_volume =     request.security(exchange_2 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_4_volume =     request.security(exchange_4 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_3_volume =     request.security(exchange_3 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_5_volume =     request.security(exchange_5 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_6_volume =     request.security(exchange_6 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_7_volume =     request.security(exchange_7 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_8_volume =     request.security(exchange_8 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
exchange_9_volume =     request.security(exchange_9 + ':' + base + fiat, timeframe.period, volume, ignore_invalid_symbol = true)
Chart_volume      =     volume 

if syminfo.prefix ==  exchange_1 or syminfo.prefix == exchange_2 or syminfo.prefix == exchange_3 or syminfo.prefix == exchange_4 or syminfo.prefix == exchange_5 
     or syminfo.prefix == exchange_6 or syminfo.prefix == exchange_7 or syminfo.prefix == exchange_8 or syminfo.prefix == exchange_9
    Chart_volume := 0.0

//Combining volime
Combined_volume = nz(exchange_1_volume) + nz(exchange_2_volume) + nz(exchange_3_volume) + nz(exchange_4_volume) + nz(exchange_5_volume) +
                  nz(exchange_6_volume) + nz(exchange_7_volume) + nz(exchange_8_volume) + nz(exchange_9_volume) + (syminfo.prefix == 'INDEX' ? 0 : nz(Chart_volume))

volumeMA = ta.sma(Combined_volume, i_ma_period)

//Plot histogram
color_hist = ta.change(close) < 0 ? color.new(color.red, 0) : color.new(color.teal, 0)

plot(i_showExchanges ? na : Combined_volume, 'Combined Volume', style=plot.style_histogram, linewidth=3, color=color_hist)
plot(i_showExchanges ? na : i_showMa ? volumeMA : na, 'Volume MA', color.new(color.orange, 0))

exchange_1_color =  color.new(color.white, 70)
exchange_2_color =  color.new(color.blue, 70)
exchange_3_color =  color.new(color.green, 70)
exchange_4_color =  color.new(color.purple, 70)
exchange_5_color =  color.new(color.yellow, 70)
exchange_6_color =  color.new(color.gray, 70)
exchange_7_color =  color.new(color.orange, 70)
exchange_8_color =  color.new(color.teal, 70)
exchange_9_color =  color.new(color.red, 70)
Chart_color      =  color.new(color.silver, 70)

//Plot individual exchanges
plot(i_showExchanges ? exchange_1_volume : na, 'Volume Exchange 1' , exchange_1_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_2_volume : na, 'Volume Exchange 2' , exchange_2_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_3_volume : na, 'Volume Exchange 3' , exchange_3_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_4_volume : na, 'Volume Exchange 4' , exchange_4_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_5_volume : na, 'Volume Exchange 5' , exchange_5_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_6_volume : na, 'Volume Exchange 6' , exchange_6_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_7_volume : na, 'Volume Exchange 7' , exchange_7_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_8_volume : na, 'Volume Exchange 8' , exchange_8_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? exchange_9_volume : na, 'Volume Exchange 9' , exchange_9_color,  linewidth=2, style=plot.style_areabr)
plot(i_showExchanges ? Chart_volume      : na, 'Volume Chart'      , Chart_color     ,  linewidth=2, style=plot.style_areabr)

var table info_table = table.new(position.bottom_right, 3, 4)

table.cell(info_table, 0, 0, text = exchange_1 + '\n ' + str.tostring(exchange_1_volume, '#.#####'), bgcolor = exchange_1_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 0, 1, text = exchange_2 + '\n ' + str.tostring(exchange_2_volume, '#.#####'), bgcolor = exchange_2_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 0, 2, text = exchange_3 + '\n ' + str.tostring(exchange_3_volume, '#.#####'), bgcolor = exchange_3_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 1, 0, text = exchange_4 + '\n ' + str.tostring(exchange_4_volume, '#.#####'), bgcolor = exchange_4_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 1, 1, text = exchange_5 + '\n ' + str.tostring(exchange_5_volume, '#.#####'), bgcolor = exchange_5_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 1, 2, text = exchange_6 + '\n ' + str.tostring(exchange_6_volume, '#.#####'), bgcolor = exchange_6_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 2, 0, text = exchange_7 + '\n ' + str.tostring(exchange_7_volume, '#.#####'), bgcolor = exchange_7_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 2, 1, text = exchange_8 + '\n ' + str.tostring(exchange_8_volume, '#.#####'), bgcolor = exchange_8_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)
table.cell(info_table, 2, 2, text = exchange_9 + '\n ' + str.tostring(exchange_9_volume, '#.#####'), bgcolor = exchange_9_color , text_color = color.white, text_halign = text.align_center, text_size = size.small)

var label chart_vol_label = na
if Chart_volume != 0
    //table.cell(info_table, 2, 3, text = 'Chart volume: ' + str.tostring(Chart_volume, '#.#####'), bgcolor = Chart_color, text_color = color.white, text_halign = text.align_left, text_size = size.normal)
    chart_vol_label := label.new(bar_index + 5, Combined_volume, text = syminfo.tickerid + ' \n' +  str.tostring(Chart_volume, '#.#####'), style = label.style_label_left, color = Chart_color, textcolor = color.white, size = size.small)
    label.delete(chart_vol_label[1])