[FR]Wm
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FFriZz

//@version=5
indicator('[FR]Wm','[FR]Wm', true) 
import PineCoders/Time/3 as l

string ypos = input.string('top', 'WaterMark Position', inline='12', options=['top', 'middle', 'bottom'])
string xpos = input.string('right', '', inline='12', options=['left', 'right', 'center'])

int timeadj = input.int(-5,'Time Adj UTC (Match Chart UTC Time)',minval=-23,maxval = 25)

smh = input.bool(false,'Sec/Min/Hour -- Before TF(on) or After TF(off)',group = 'TF Label')
string s = input('s','Second TF',group = 's/m/h')
string m = input('m','Minute TF',group = 's/m/h')
string h = input('h','Hour TF'  ,group = 's/m/h') 

string Format_i = input.string('HH:mm:ss a','Format Select',group = 'Format',
 options = ['Custom','HH:mm:ss a','dd/MM/yyyy','EEEE, dd/MM/yy','HH:mm a','d/MM','E, dd/MM','H:ss'])
if Format_i == 'Custom'
    Format_i := input('M/d | E | h:mm a','Custom Format input'  ,group = 'If ↟↟↟ Format Select is Custom',inline='') 

string Examples_i = input.text_area(
 '(Enter in Format Input ↟↟↟) Make your own format by Copying one of the examples provided, or building one using the letters under column (Sym.) and refrencing the examples provided\n\n' +
 '------------------------------------------------\n' +
 'Examples = HH:mm:ss a | dd/MM/yyyy | EEEE,dd/MM/yy\n' +
 'Examples = HH:mm a | d/MM | E,dd/MM | H:ss \n' +
  '-----------------------------------------------\n' +
 '(Sym.) ↦ (Use Cases) ↦ (Ex.= Eamples)\n' +
  '-----------------------------------------------\n' +
 'y ↦ short         ↦ Ex.  Short Format' +
 'y ↦ meidum        ↦ Ex.  Meidumn Format' +
 'y ↦ full          ↦ Ex.  Full Format' +
 'y ↦ Year          ↦ Ex. 2018(yyyy),18(yy)\n' +
 'M ↦ Month of year ↦ Ex. October(MMMM),Oct(MMM),10(MM)\n' +
 'w ↦ Week of year  ↦ Ex. 26\n' +
 'W ↦ Week of month ↦ Ex. 2\n' +
 'D ↦ Day of Year   ↦ Ex. 266\n' +
 'd ↦ Day of the month ↦ Ex. 09(dd),9(d)\n' +
 'E ↦ Day name of week ↦ Ex. Tuesday(EEEE),Tues(E)\n' +
 'u ↦ Day in week (1-7) ↦ Ex. 4\n' +
 'a ↦ AM or PM marker   ↦ Ex. AM or PM\n' +
 'H ↦ Hour (0-23)       ↦ Ex. 09(HH),9(H)\n' +
 'h ↦ Hour (1-12)       ↦ Ex. 05(hh),5(h)\n' +
 'm ↦ Minute of hour    ↦ Ex. 09(mm),5(m) \n' +
 's ↦ Second of minute  ↦ Ex. 05(ss),5(s)\n' +
 '------------------------------------------------\n' +
 'Can use ()[] on outsides or :/,. Between\n' +
  '-----------------------------------------------\n',
 '↟↟↟↟↟↟ Date/Time Format',group = 'If ↟↟↟ Format Select is Custom')

color  color =    input(color.new(#000000, transp=0),'Text Color')
string textsize = input.string('normal', 'Text size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'])
string tva1 =     input.string(text.align_center,'Text Align Vert',inline = 'ta1',options = [text.align_top, text.align_center, text.align_bottom])
string tha1 =     input.string(text.align_center,'Text Align Horiz',inline = 'ta1',options = [text.align_left, text.align_center, text.align_right])

smh(s,m,h)=>
    string TFM = ''
    string TFP = timeframe.period
    int    TFS = timeframe.in_seconds()
    if TFS < 60
        TFM := smh ? s + str.tostring(TFS) : 
         str.tostring(TFS) + s
    if TFS >= 60
        TFM := smh ? m + TFP : TFP + m
    if timeframe.isminutes 
        if str.tonumber(TFP) >= 60
            TFM := smh ? h + str.tostring(str.tonumber(TFP) / 60) :
             str.tostring(str.tonumber(TFP) / 60) + h
    if timeframe.isdwm
        TFM := TFP
    TFM
    
TFM = smh(s,m,h)
///////////////////////////////////////////////////////////////////////////////
     
UTC = 3600000 * timeadj

var Session = ''
var int Sessionc = 0
tokyo ='Tokyo'
tokyos = 180000
tokyof = 030000

london ='London'
londons = 030000
londonf = 120000

newyork ='New York'
newyorks = 080000
newyorkf = 170000

noses = 'Sessions Closed'
nosess = 170000
nosesf = 200000

sestime = str.tonumber(str.replace_all(l.formattedTime(timenow + UTC),':',''))
TTtime = l.formattedTime(timenow + UTC, 'H:mm:ss a')

sep = ' ⇆ '
Session := ''
Sessionc := 0
var light = ''

if sestime > tokyos and sestime < tokyof
    Sessionc += 2
    Session := Session + tokyo

if sestime > londons and sestime < londonf
    Sessionc += 1
    Session := Session + (Sessionc > 1 ? ' ⇆ ' : '') + london

if sestime > newyorks and sestime < newyorkf
    Session :=  Session + (Sessionc >= 1 ? ' ⇆ ' : '') + newyork

if sestime > nosess and sestime < nosesf
    Session := ''
    Session := noses
    light := ' 🔴' 
else
    light := ' 🟢'
    
Tokyos =   24 + timeadj > 24 ? 0 + timeadj : 24 + timeadj < 0 ? 24 + timeadj : 24 + timeadj
Tokyof =    9 + timeadj > 24 ? 0 + timeadj :  9 + timeadj < 0 ? 24 + timeadj :  9 + timeadj

Londons =   7 + timeadj > 24 ? 0 + timeadj :  7 + timeadj < 0 ? 24 + timeadj :  7 + timeadj
Londonf =  16 + timeadj > 24 ? 0 + timeadj : 16 + timeadj < 0 ? 24 + timeadj : 16 + timeadj

Newyorks = 12 + timeadj > 24 ? 0 + timeadj : 12 + timeadj < 0 ? 24 + timeadj : 12 + timeadj
Newyorkf = 21 + timeadj > 24 ? 0 + timeadj : 21 + timeadj < 0 ? 24 + timeadj : 21 + timeadj

Nosess =   21 + timeadj > 24 ? 0 + timeadj : 21 + timeadj < 0 ? 24 + timeadj : 21 + timeadj
Nosesf =   24 + timeadj > 24 ? 0 + timeadj : 24 + timeadj < 0 ? 24 + timeadj : 24 + timeadj
 
TLovers =  7  + timeadj > 24 ? 0 + timeadj :  7 + timeadj < 0 ? 24 + timeadj :  7 + timeadj
TLoverf =  9  + timeadj > 24 ? 0 + timeadj :  9 + timeadj < 0 ? 24 + timeadj :  9 + timeadj

NLovers =  12 + timeadj > 24 ? 0 + timeadj : 12 + timeadj < 0 ? 24 + timeadj : 12 + timeadj
NLoverf =  16 + timeadj > 24 ? 0 + timeadj : 16 + timeadj < 0 ? 24 + timeadj : 16 + timeadj

var table watermark = table.new(ypos + '_' + xpos, 2, 2)
if barstate.islast
    table.cell(watermark, 0, 0,l.formattedDate(timenow + UTC,Format_i) + '\n' + 
     str.tostring(syminfo.ticker) + ' | ' + TFM,
     text_color = color, text_size=textsize ,text_valign = tva1,text_halign = tha1,
     //
     tooltip = '---------------- Sessions🕧 --------------\n' +
     //
     '--Tokyo: '+ str.tostring(Tokyos) +':00' + 
     (Tokyos >= 12 ? 'PM' : 'AM') + ' - ' + str.tostring(Tokyof) + ':00' + 
     (Tokyof >= 12 ? 'PM' : 'AM') + '\n' +
     //
     '--London: '+ str.tostring(Londons) +':00' + 
     (Londons >= 12 ? 'PM' : 'AM') + ' - ' + str.tostring(Londonf) + ':00' + 
     (Londonf >= 12 ? 'PM' : 'AM') + '\n' +
     //
     '--Tokyo/London: '+ str.tostring(TLovers) + ':00' + 
     (TLovers >= 12 ? 'PM' : 'AM') + ' - ' + str.tostring(TLoverf) + ':00' + 
     (TLoverf >= 12 ? 'PM' : 'AM') + '\n' +
     //
     '--New York: '+ str.tostring(Newyorks) +':00' + 
     (Newyorks >= 12 ? 'PM' : 'AM') + ' - ' + str.tostring(Newyorkf) + ':00' + 
     (Newyorkf >= 12 ? 'PM' : 'AM') + '\n' +
     //
     '--NY/London: '+ str.tostring(NLovers) +':00' + 
     (NLovers >= 12 ? 'PM' : 'AM') + ' - ' + str.tostring(NLoverf) + ':00' + 
     (NLoverf >= 12 ? 'PM' : 'AM') + '\n' +
     //
     '--Sessions Closed: '+ str.tostring(Nosess) +':00' + 
     (Nosess >= 12 ? 'PM' : 'AM') + ' - ' + str.tostring(Nosesf) + ':00' + 
     (Nosesf >= 12 ? 'PM' : 'AM') + '\n' +
     //
     '---------------------------------------------\n            Session: ' + Session + light +
     '\n                 ' + TTtime  +  '\n---------------------------------------------')


