[H] Multi Coin Compare
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Hermetism
// Some Credits to @Violent and @HomelessLemon
//@version=5

indicator(title='[H] Compare', shorttitle='[H] Compare', overlay=true)


t = input.bool(true, title='Show Table', group='Table', tooltip='Show the table')
tablePositionY = input.string('top', title='Y-Position', options=['top', 'middle', 'bottom'], group="Table", inline="1")
tablePositionX = input.string('right', title='X-Position', options=['left', 'center', 'right'], group="Table", inline="1")
var table dataTable = table.new(tablePositionY + '_' + tablePositionX, 1, 5, border_width=7)

////////////////////////////////////////////////////////////////////////////////
//  Compare 
////////////////////////////////////////////////////////////////////////////////
 
int compareNumber = input.int(3, maxval=5, title='Number of Comparisons', tooltip='Maximum of 5')

compareSym = input.symbol('BINANCE:SHIBUSDT', 'Compare Symbol', group="Coin One")
compareRes = input.timeframe('60', 'Timeframe', group="Coin One")
compareMult = input.bool(title='Multiply', defval=true, tooltip='If the coin you are comparing has a lower price than the main symbol you will need to multiply instead of divide', group="Coin One")
compareDiv = input.float(1397367240.7179794, 'Divider', minval=1, step=0.1, tooltip='The amount to divide the current price for the comparison', group="Coin One")
compareColor = input(title='Compare Color', defval=#ff9800, group="Coin One")
compareSource = input.source(close, "Source", group="Coin One")
comparePrice = request.security(compareSym, compareRes, compareSource)

compareSym1 = input.symbol('BINANCE:LTCUSDT', 'Compare Symbol', group="Coin Two")
compareRes1 = input.timeframe('60', 'Timeframe', group="Coin Two")
compareMult1 = input.bool(title='Multiply', defval=true, tooltip='If the coin you are comparing has a lower price than the main symbol you will need to multiply instead of divide', group="Coin Two")
compareDiv1 = input.float(290.9133288227, 'Divider', minval=1, step=0.1, tooltip='The amount to divide the current price for the comparison', group="Coin Two")
compareColor1 = input(title='Compare Color', defval=#3179f5, group="Coin Two")
compareSource1 = input.source(close, "Source", group="Coin Two")
comparePrice1 = request.security(compareSym1, compareRes1, compareSource1)

compareSym2 = input.symbol('BINANCE:ETHUSDT', 'Compare Symbol', group="Coin Three")
compareRes2 = input.timeframe('60', 'Timeframe', group="Coin Three")
compareMult2 = input.bool(title='Multiply', defval=true, tooltip='If the symbol you are comparing has a lower price than the main symbol you will need to multiply instead of divide', group="Coin Three")
compareDiv2 = input.float(12.9467280124, 'Divider', minval=1, step=0.1, tooltip='The amount to divide the current price for the comparison', group="Coin Three")
compareColor2 = input(title='Compare Color', defval=#ab47bc, group="Coin Three")
compareSource2 = input.source(close, "Source", group="Coin Three")
comparePrice2 = request.security(compareSym2, compareRes2, compareSource2)

compareSym3 = input.symbol('BINANCE:DOGEUSDT', 'Compare Symbol', group="Coin Four")
compareRes3 = input.timeframe('60', 'Timeframe', group="Coin Four")
compareMult3 = input.bool(title='Multiply', defval=true, tooltip='If the symbol you are comparing has a lower price than the main symbol you will need to multiply instead of divide', group="Coin Four")
compareDiv3 = input.float(236637.259218492, 'Divider', minval=1, step=0.1, tooltip='The amount to divide the current price for the comparison', group="Coin Four")
compareColor3 = input(title='Compare Color', defval=#ffeb3b, group="Coin Four")
compareSource3 = input.source(close, "Source", group="Coin Four")
comparePrice3 = request.security(compareSym3, compareRes3, compareSource3)

compareSym4 = input.symbol('BINANCE:DOTUSDT', 'Compare Symbol', group="Coin Five")
compareRes4 = input.timeframe('60', 'Timeframe', group="Coin Five")
compareMult4 = input.bool(title='Multiply', defval=true, tooltip='If the symbol you are comparing has a lower price than the main symbol you will need to multiply instead of divide', group="Coin Five")
compareDiv4 = input.float(741071.8717683557, 'Divider', minval=1, step=0.1, tooltip='The amount to divide the current price for the comparison', group="Coin Five")
compareColor4 = input(title='Compare Color', defval=#26c6da, group="Coin Five")
compareSource4 = input.source(close, "Source", group="Coin Five")
comparePrice4 = request.security(compareSym4, compareRes4, compareSource4)


plot(compareMult  ? compareNumber >= 1 ? comparePrice  *  compareDiv : na : compareNumber >= 1 ? comparePrice  / compareDiv  : na, '[1] Compare Price', color=compareColor, style=plot.style_stepline, linewidth=2)
plot(compareMult1 ? compareNumber >= 2 ? comparePrice1 * compareDiv1 : na : compareNumber >= 2 ? comparePrice1 / compareDiv1 : na, '[2] Compare Price', color=compareColor1, style=plot.style_stepline, linewidth=2)
plot(compareMult2 ? compareNumber >= 3 ? comparePrice2 * compareDiv2 : na : compareNumber >= 3 ? comparePrice2 / compareDiv2 : na, '[3] Compare Price', color=compareColor2, style=plot.style_stepline, linewidth=2)
plot(compareMult3 ? compareNumber >= 4 ? comparePrice3 * compareDiv3 : na : compareNumber >= 4 ? comparePrice3 / compareDiv3 : na, '[4] Compare Price', color=compareColor3, style=plot.style_stepline, linewidth=2)
plot(compareMult4 ? compareNumber >= 5 ? comparePrice4 * compareDiv4 : na : compareNumber >= 5 ? comparePrice4 / compareDiv4 : na, '[5] Compare Price', color=compareColor4, style=plot.style_stepline, linewidth=2)

////////////////////////////////////////////////////////////////////////////////
//  Output
////////////////////////////////////////////////////////////////////////////////

if barstate.islast and t==true and compareNumber>0
    compareText = compareSym + " " + str.tostring(comparePrice, format="0.##########")
    compareText1 = compareSym1 + " " + str.tostring(comparePrice1, format="0.##########")
    compareText2 = compareSym2 + " " + str.tostring(comparePrice2, format="0.##########")
    compareText3 = compareSym3 + " " + str.tostring(comparePrice3, format="0.##########")
    compareText4 = compareSym4 + " " + str.tostring(comparePrice4, format="0.##########")
    tableBgColor = input(color.rgb(120, 123, 134, 85), "Table Background Color", group="Table")
    
    if(compareNumber>=1)
        table.cell(dataTable, 0, 0, text=compareText, bgcolor=tableBgColor, text_color=compareColor)
    
    if(compareNumber>=2)
        table.cell(dataTable, 0, 1, text=compareText1, bgcolor=tableBgColor, text_color=compareColor1)
    
    if(compareNumber>=3)
        table.cell(dataTable, 0, 2, text=compareText2, bgcolor=tableBgColor, text_color=compareColor2)
        
    if(compareNumber>=4)
        table.cell(dataTable, 0, 3, text=compareText3, bgcolor=tableBgColor, text_color=compareColor3)
        
    if(compareNumber>=5)
        table.cell(dataTable, 0, 4, text=compareText4, bgcolor=tableBgColor, text_color=compareColor4)

