Upgraded Watermark
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amphibiantrading

//@version=5
indicator("Upgraded Watermark", shorttitle = 'WM', overlay = true)

yPos        = input.string("Middle", "Watermark Location", options = ["Top", "Middle", "Bottom"], inline = '1')
xPos        = input.string("Center", " ", options = ["Right","Center", "Left"], inline = '1')
txtCol      = input.color(color.rgb(164, 167, 180,30), 'Text Color', inline = '2')
txtSize     = input.string('Huge', 'Text Size', options = ['Huge', 'Large', 'Normal', 'Small'], inline = '2')
symTime     = input.bool(true, 'Symbol & Time Frame')
compName    = input.bool(true, 'Company Name')
indSec      = input.bool(true, 'Industry & Sector')
mCap        = input.bool(false, 'Show Market Cap')

//switch
sizer = switch txtSize
    'Huge' => size.huge
    'Large' => size.large
    'Normal' => size.normal
    'Small' => size.small

//rounding method for marketcap
method rounder(float this) =>
    if this >= 1000000000000
        market = math.round(math.abs(this / 1000000000000),2)
    else if this >= 1000000000
        market = math.round(math.abs(this / 1000000000),2)
    else 
        market = math.round(math.abs(this / 1000000),2)

//ticker info
sector  = syminfo.sector
ind     = syminfo.industry
tick    = syminfo.ticker
tf      = timeframe.period
name    = syminfo.description
tso     = syminfo.shares_outstanding_total

tf := timeframe.period == 'D' ? '1D' : timeframe.period == 'W' ? '1W' : timeframe.period == '60' ? '1H' : 
     timeframe.period == '120' ? '2H' : timeframe.period == '180' ? '3H' : timeframe.period == '240' ? '4H' : tf

//market cap info
marketcap   = tso * close 
marCap      =  marketcap > 1000000000000 ? 'T' : marketcap > 1000000000 ? 'B' : 'M' 

//plot
var table sec = table.new(str.lower(yPos) + '_' + str.lower(xPos), 1,3, color.new(color.white,100), color.new(color.white,100), 1, color.new(color.white,100), 1)
if barstate.islast
    if symTime
        sec.cell(0,0,tick + ', ' + tf, text_color = txtCol, text_size = sizer)
    if compName
        sec.cell(0,1, mCap ? name + ' (' + str.tostring(nz(marketcap.rounder())) + marCap + ')' : name, text_color = txtCol, text_size = sizer)
    if indSec
        sec.cell(0,2, not na(sector) ? sector + ', ' + ind : '', text_color = txtCol, text_size = sizer)
