SST Table New
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// atulkharadi

//@version=5

indicator(title='SST Table New', shorttitle='SST Table New', overlay=true)

Stock = syminfo.ticker
length = input.int(20, minval=1)
profit = input.int(10, minval=1)
HIGH20 = ta.highest(length)
LOW20 = ta.lowest(length)
TARGET = HIGH20 * (100 + profit) / 100
LHIGH20 = HIGH20[1]
DIFF = (HIGH20 - close) / close * 100

//================================================================================================

//Input RS
swrs = input(true, title='RS')
source = input(title='Source', defval=close)
comparativeTickerId = input.symbol('NSE:NIFTY', title='Comparative Symbol')
RSlength = input.int(55, minval=1, title='Period')
//showZeroLine = input(defval=true, title='Show Zero Line')
toggleRSColor = input(defval=true, title='Toggle RS color on crossovers')

//Setup RS
baseSymbol = request.security(syminfo.tickerid, timeframe.period, source)
comparativeSymbol = request.security(comparativeTickerId, timeframe.period, source)

//Plot RS
//plot(showZeroLine ? 0 : na, linewidth=1, color=color.new(color.maroon, 0), title='Zero Line')
res = (baseSymbol / baseSymbol[RSlength] / (comparativeSymbol / comparativeSymbol[RSlength]) - 1) * 100
resColor = toggleRSColor ? res > 0 ? color.green : color.red : color.blue
plot(swrs ? (100+res)*close/100 : na, title='RS', linewidth=2, color=resColor)

//=============================================================================================

plot(HIGH20, 'HIGH20', color=color.new(color.blue, 0), trackprice=false, editable=true)
plot(LOW20, 'LOW20', color=color.new(color.red, 0), trackprice=false, editable=true)
plot(TARGET, 'TARGET', color=color.new(color.green, 0), trackprice=false, editable=true)

var table gttTable = table.new(position.top_right, 8, 6, bgcolor=color.white, frame_color=color.white, frame_width=2, border_width=2)

Low20D = '20D \nLOW'
table.cell(gttTable, 0, 0, text=Low20D, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
LHigh20D = 'OLD \nGTT'
table.cell(gttTable, 1, 0, text=LHigh20D, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
High20D = 'NEW \nGTT'
table.cell(gttTable, 2, 0, text=High20D, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
SST = 'STOCK NAME'
table.cell(gttTable, 3, 0, text=SST, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
CMP = 'PRICE'
table.cell(gttTable, 4, 0, text=CMP, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
Diff = 'DIFF %'
table.cell(gttTable, 5, 0, text=Diff, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
UpdateGTT = 'Update \nGTT'
table.cell(gttTable, 6, 0, text=UpdateGTT, bgcolor=color.silver, text_color=color.white, text_size=size.normal)

RS_55 = 'RS 55'
table.cell(gttTable, 7, 0, text='RS 55', bgcolor=color.silver, text_color=color.white, text_size=size.normal)

table.cell(gttTable, 3, 1, text=Stock, bgcolor=color.silver, text_color=color.white, text_size=size.normal)

if barstate.islast
    Low20D = str.tostring(math.round(LOW20, 2))
    table.cell(gttTable, 0, 1, text=Low20D, bgcolor=color.blue, text_color=color.white, text_size=size.normal)
    LHigh20D = str.tostring(math.round(LHIGH20, 2))
    table.cell(gttTable, 1, 1, text=LHigh20D, bgcolor=color.blue, text_color=color.white, text_size=size.normal)
    High20D = str.tostring(math.round(HIGH20, 2))
    table.cell(gttTable, 2, 1, text=High20D, bgcolor=color.blue, text_color=color.white, text_size=size.normal)
    CMP = str.tostring(math.round(close, 2))
    table.cell(gttTable, 4, 1, text=CMP, bgcolor=color.silver, text_color=color.white, text_size=size.normal)
    Diff = str.tostring(math.round(DIFF, 2))
    table.cell(gttTable, 5, 1, text=Diff, bgcolor=color.blue, text_color=color.white, text_size=size.normal)
    RS_55 = str.tostring(math.round(res/100, 2))
    table.cell(gttTable, 7, 1, text=RS_55, bgcolor=color.blue, text_color=color.white, text_size=size.normal)
    
    
    UpdateGTT = if HIGH20 < HIGH20[1]
        str.tostring('YES')
    table.cell(gttTable, 6, 1, text=UpdateGTT, width=0, bgcolor=color.blue, text_color=color.white, text_size=size.auto)
    
//    TriggeredGTT = if HIGH20 > HIGH20[1]
//        str.tostring('TRG @ ')+str.tostring(HIGH20[1])
//    table.cell(gttTable, 6, 1, text=TriggeredGTT, width=0, bgcolor=color.blue, text_color=color.white, text_size=size.auto)
    
//    TargetGTT = if HIGH20 > HIGH20[1]
//        str.tostring(math.round(TARGET[1], 2))
//    table.cell(gttTable, 7, 1, text=TargetGTT, bgcolor=color.blue, text_color=color.white, text_size=size.normal)

plot(res/100, title='RS', linewidth=2, color=resColor)