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

//@version=5
indicator("watermark", overlay=true)

showTF = input.bool(true, "show time frame", inline = "24")
showpf = input.bool(true, "show prefix", inline = "24")
showchange = input.bool(false, "show change %", inline = "24")
string  i_tableYpos = input.string("bottom", "Position", inline = "12", options = ["top", "middle", "bottom"])
string  i_tableXpos = input.string("right", "", inline = "12", options = ["left", "center", "right"])
size1 = input.string("huge", "title", inline = "14", options = ["tiny", "small", "normal", "large", "huge", "auto"])
size3 = input.string("large", "change", inline = "14", options = ["tiny", "small", "normal", "large", "huge", "auto"])
size2 = input.string("small", "signature", inline = "14", options = ["tiny", "small", "normal", "large", "huge", "auto"])
color = input.color(#ffffff77, "color")
string = input.string("by you", "your signature")
seperator = input.string("/", "seperator")

cahngeClose = request.security(syminfo.tickerid, timeframe.period, close)

cur = syminfo.currency
base = syminfo.basecurrency
exchange = syminfo.prefix

        
getTimeFrame() =>
    tf = timeframe.multiplier
    tfstr = ""
    if timeframe.isseconds
        tfstr := "s"
    if timeframe.isminutes
        if tf >= 60
            tf := tf / 60
            tfstr := "h"
        else
            tfstr := "m"
    if timeframe.isdaily
        tfstr := "D"
    if timeframe.isweekly
        tfstr := "W"
    if timeframe.ismonthly
        tfstr := "M"  
        
    [tfstr, str.tostring(tf)]
        
var table table1 = table.new(i_tableYpos + "_" + i_tableXpos , 4, 1)

if barstate.islast

    
    str1 = base != "" ? base + seperator + cur : syminfo.ticker
    [tf, period] = getTimeFrame()
    
    change = math.round(((cahngeClose[0] / cahngeClose[1]) - 1) * 100, 2)
    changeStr = ""
    if change > 0 
        changeStr := "▲" + str.tostring(math.abs(change)) + "%"
    else
        changeStr := "▼" + str.tostring(math.abs(change)) + "%"
    

    table.cell(table1, 0, 0, showpf ? exchange : "", text_color = color, width=0, text_size=size2)

    table.cell(table1, 1, 0, str1 + (showTF ? (" " + period + tf) : ""), width=0, text_color = color,  text_size=size1)
    table.cell(table1, 2, 0, showchange ? changeStr : "", width=0, text_color = change > 0 ? color.green : color.red,  text_size=size3)

    table.cell(table1, 3, 0, string, text_color = color, width=0,  text_size=size2)


