Floating RSI Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mayurssupe

//@version=5
indicator("Floating RSI",overlay=true)
_rsiLabels = input.bool(defval = false,title="RSI Labels",group = "Options",tooltip = "it calculates the RSI value of bar and it will display on the top of the bar")

rsiZones = input.string(defval="60/40",title="RSI Zones",options=["60/40","50/50","70/30","80/20"],group="RSI")
rsiPeriod = input.int(defval=9,title="RSI Period",group="RSI")
_source = input.source(defval=close,title="RSI Source",group="RSI")


black = input.color(defval=color.black,title="Black",group="Colors")
white = input.color(defval=color.white,title="White",group="Colors")
red = input.color(defval=color.red,title="Red",group="Colors")
green = input.color(defval=color.green,title="Green",group="Colors")
silver = input.color(defval=color.silver,title="Silver",group="Colors")

//Defining RSI
rsi = ta.rsi(_source,rsiPeriod)

//defining values as per the rsi Zones
var int rsiOB = 0
var int rsiOS = 0

if(rsiZones == "60/40")
    rsiOB:=60
    rsiOS:=40
else if(rsiZones =="50/50")
    rsiOB :=50
    rsiOS :=50
else if(rsiZones =="70/30")
    rsiOB :=70
    rsiOS :=30
else if(rsiZones =="80/20")
    rsiOB :=80
    rsiOS :=20

var string GP2 = "Display Table"
string  i_tableYpos = input.string("middle", "Panel position", inline = "11", options = ["top", "middle", "bottom"], group = GP2)
string  i_tableXpos = input.string("right", "", inline = "11", options = ["left", "center", "right"], group = GP2)

var table t = table.new(i_tableYpos + "_" + i_tableXpos, 9, 9, border_width=1,frame_width=1)
_CalcTf = input.timeframe(defval="D",title="High Minus Low TF",options=['D','W','M'],group="Table")

//Gaps value
prevDayClose = request.security(syminfo.tickerid,"D",close)[1]// previous day last day candle close
nextdayOpen = request.security(syminfo.tickerid,"D",open) // next day candle open
_gaps = nz(nextdayOpen - prevDayClose)

var string gapStatus = na
var color bgcolor = na
if(prevDayClose > nextdayOpen)
    gapStatus:="▼"
    bgcolor:=red
else if(prevDayClose < nextdayOpen)
    gapStatus:="▲"
    bgcolor:= green


highC = high
LowC =  low
closeC = close
_Calc = (high - low)
_Calc_pts = request.security(syminfo.tickerid, _CalcTf, _Calc) 
_CalcOpen = (close - open)
atr = ta.atr(14)


// Trend Stregth Using Adx
[diplus, diminus, adx] = ta.dmi(14, 14)

weak = adx >= 0 and adx <= 20
strong = adx >= 20.05 and adx <= 49.99
ExtremeStrong = adx >= 50 and adx <= 60 
danger = adx >= 60 and adx <= 100 

var string adxSign = na
var color adxS = na

if(weak)
    adxSign :="Weak"
    adxS:= color.gray
else if(strong)
    adxSign :="Good"
    adxS:= color.green
else if(ExtremeStrong)
    adxSign :="Strong"
    adxS:= color.purple
else if(danger)
    adxSign :="Exhausted"
    adxS:= color.red
else
    adxSign:= "0"
    


if barstate.isrealtime or barstate.islast or barstate.isconfirmed

    table.cell(t, 0, 1, 'RSI',bgcolor=black,text_color=white)
    table.cell(t, 0, 2, "ATR",bgcolor=black,text_color=white)
    table.cell(t, 0, 3, 'High - Low',bgcolor=black,text_color=white)
    table.cell(t, 0, 4, 'Body Len',bgcolor=black,text_color=white)
    table.cell(t, 0, 5, "Today Gap",bgcolor=black,text_color=white)
    table.cell(t, 0, 6, "Trend Stregth",bgcolor=black,text_color=white)
    
    table.cell(t, 1, 1, str.tostring(math.round(rsi, 0)),bgcolor=rsi > rsiOB ? green : rsi < rsiOS ? red : color.orange,text_color=color.white)
    table.cell(t, 1, 2, str.tostring(math.round(atr, 3)),bgcolor=black ,text_color=white)
    table.cell(t, 1, 3, str.tostring(math.round(_Calc_pts, 3)),bgcolor=black ,text_color=white)
    table.cell(t, 1, 4, str.tostring(math.round(_CalcOpen, 3)),bgcolor=black ,text_color=white)
    table.cell(t, 1, 5, str.tostring(math.round(_gaps, 0))+ " " +gapStatus,bgcolor=bgcolor ,text_color=white)
    table.cell(t, 1, 6, str.tostring(adxSign),bgcolor=adxS ,text_color=white)


//Labels of RSI
t1 =str.tostring(math.round(rsi, 2))
label.new(_rsiLabels and bar_index ? bar_index : na,rsi,text=str.tostring(t1),yloc = yloc.abovebar,color=rsi > rsiOB ? color.aqua : rsi < rsiOS ? color.rgb(255, 69, 116, 20) : black,textcolor=color.white,style=label.style_label_down,size=size.small)