Total Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pascorp

//@version=5
indicator("Total Volume")
sym1    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 1")
sym2    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 2")
sym3    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 3")
sym4    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 4")
sym5    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 5")
sym6    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 6")
sym7    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 7")
sym8    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 8")
sym9    = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 9")
sym10   = input.symbol(defval='BINANCE:BTCUSDT', title="Symbol 10")

n       = input.int(defval=5, maxval=10, minval=1, title='Number exchange')
mode    = input.string(defval='Sum', title='Type of algo', options=['Sum', 'Avg', 'Highest Volume-Weighted', 'Max'])

clrMode = input.string(defval='Highest Volume Exchange', title='Color histogram by', options=['Highest Volume Exchange', 'Classic', 'No Color'])
plotBase = input(true, title='Plot volume of the current exchange/broker')

vol1 = request.security(sym1, timeframe.period, volume)
vol2 = request.security(sym2, timeframe.period, volume)
vol3 = request.security(sym3, timeframe.period, volume)
vol4 = request.security(sym4, timeframe.period, volume)
vol5 = request.security(sym5, timeframe.period, volume)
vol6 = request.security(sym6, timeframe.period, volume)
vol7 = request.security(sym7, timeframe.period, volume)
vol8 = request.security(sym8, timeframe.period, volume)
vol9 = request.security(sym9, timeframe.period, volume)
vol10 = request.security(sym10, timeframe.period, volume)

volumeSum = switch n
    1 => vol1
    2 => vol1 + vol2 
    3 => vol1 + vol2 + vol3
    4 => vol1 + vol2 + vol3 + vol4
    5 => vol1 + vol2 + vol3 + vol4 + vol5
    6 => vol1 + vol2 + vol3 + vol4 + vol5 + vol6
    7 => vol1 + vol2 + vol3 + vol4 + vol5 + vol6 + vol7 
    8 => vol1 + vol2 + vol3 + vol4 + vol5 + vol6 + vol7 + vol8
    9 => vol1 + vol2 + vol3 + vol4 + vol5 + vol6 + vol7 + vol8 + vol9
    10=> vol1 + vol2 + vol3 + vol4 + vol5 + vol6 + vol7 + vol8 + vol9 + vol10
    
maxVol = array.new_float(0,0)

if n>=1
    array.push(maxVol, vol1)
    
if n>=2
    array.push(maxVol, vol2)
    
if n>=3
    array.push(maxVol, vol3)
    
if n>=4
    array.push(maxVol, vol4)
    
if n>=5
    array.push(maxVol, vol5)
    
if n>=6
    array.push(maxVol, vol6)
    
if n>=7
    array.push(maxVol, vol7)
    
if n>=8
    array.push(maxVol, vol8)
    
if n>=9
    array.push(maxVol, vol9)
    
if n>=10
    array.push(maxVol, vol10)

totVol = switch mode
    'Sum'                       => volumeSum
    'Avg'                       => volumeSum/n
    'Highest Volume-Weighted'   => (volumeSum + array.max(maxVol)) /(n+1)
    'Max'                       => array.max(maxVol)
    
col1 = color.white
col2 = color.red
col3 = color.green
col4 = color.yellow
col5 = color.fuchsia    
col6 = color.purple
col7 = color.aqua
col8 = color.lime
col9 = color.orange
col10 = color.olive

colorHistExchange = switch array.max(maxVol)
    vol1 => col1
    vol2 => col2
    vol3 => col3
    vol4 => col4
    vol5 => col5
    vol6 => col6
    vol7 => col7
    vol8 => col8
    vol9 => col9
    vol10=> col10
    
clrHist =  switch clrMode
    'Highest Volume Exchange'   => colorHistExchange
    'Classic'                   => close>open? color.green: color.red
    'No Color'                  => color.blue
    
plot(plotBase? volume: na , style=plot.style_histogram, color=color.new(color.orange,50), linewidth=4)
plot(totVol, style=plot.style_histogram, color=clrHist, linewidth=2)


// ——————————————————————————————————————————————————————————————————
// >>>>>>>>>>>>>>>>>>>>>>>>>    Table    <<<<<<<<<<<<<<<<<<<<<<<<<<<<
// ——————————————————————————————————————————————————————————————————
showTab     = input(true, title='Helping table', group='Table', inline='0')

tabLoc      = input.string('Bottom Left', 'Location', options=['Top Right', 'Bottom Right', 'Top Left', 'Bottom Left'], group='Table', inline='1')

txtSize     = input.string('Tiny', 'Size', options=['Tiny', 'Small', 'Normal', 'Large'], group='Table', inline='1')
txtCol      = input.color(color.gray, 'Color', group='Table', inline='1')

var tablePosition = switch tabLoc
    'Top Left'      => position.top_left 
    'Bottom Left'   => position.bottom_left 
    'Top Right'     => position.top_right 
    'Bottom Right'  => position.bottom_right

var tableTxtSize = switch txtSize
    'Tiny'   => size.tiny
    'Small'  => size.small
    'Normal' => size.normal
    'Large'  => size.large

if showTab
    new_table = table.new(tablePosition, 10, 2, border_color=txtCol, border_width=1, frame_color=txtCol, frame_width=1)
    
    
    if barstate.islast
            
        table.cell(new_table, 0, 0, sym1, text_color=color.black, text_size=tableTxtSize, bgcolor=col1)
        table.cell(new_table, 0, 1, str.tostring(vol1), text_color=txtCol, text_size=tableTxtSize)
        if n>=2
            table.cell(new_table, 1, 0, sym2, text_color=color.black, text_size=tableTxtSize, bgcolor=col2)
            table.cell(new_table, 1, 1, str.tostring(vol2), text_color=txtCol, text_size=tableTxtSize)
        if n>=3
            table.cell(new_table, 2, 0, sym3, text_color=color.black, text_size=tableTxtSize, bgcolor=col3)    
            table.cell(new_table, 2, 1, str.tostring(vol3), text_color=txtCol, text_size=tableTxtSize)
        if n>=4
            table.cell(new_table, 3, 0, sym4, text_color=color.black, text_size=tableTxtSize, bgcolor=col4)
            table.cell(new_table, 3, 1, str.tostring(vol4), text_color=txtCol, text_size=tableTxtSize)
        if n>=5
            table.cell(new_table, 4, 0, sym5, text_color=color.black, text_size=tableTxtSize, bgcolor=col5)
            table.cell(new_table, 4, 1, str.tostring(vol5), text_color=txtCol, text_size=tableTxtSize)
        if n>=6
            table.cell(new_table, 5, 0, sym6, text_color=color.black, text_size=tableTxtSize, bgcolor=col6)
            table.cell(new_table, 5, 1, str.tostring(vol6), text_color=txtCol, text_size=tableTxtSize)
        if n>=7
            table.cell(new_table, 6, 0, sym7, text_color=color.black, text_size=tableTxtSize, bgcolor=col7)
            table.cell(new_table, 6, 1, str.tostring(vol7), text_color=txtCol, text_size=tableTxtSize)
        if n>=8
            table.cell(new_table, 7, 0, sym8, text_color=color.black, text_size=tableTxtSize, bgcolor=col8)
            table.cell(new_table, 7, 1, str.tostring(vol8), text_color=txtCol, text_size=tableTxtSize)
        if n>=9
            table.cell(new_table, 8, 0, sym9, text_color=color.black, text_size=tableTxtSize, bgcolor=col9)
            table.cell(new_table, 8, 1, str.tostring(vol9), text_color=txtCol, text_size=tableTxtSize)
        if n>=10
            table.cell(new_table, 9, 0, sym10, text_color=color.black, text_size=tableTxtSize, bgcolor=col10)
            table.cell(new_table, 9, 1, str.tostring(vol10), text_color=txtCol, text_size=tableTxtSize)

        
            