Binance Futures Swap-Spot Basis Label
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © king_mob

//@version=5

indicator("Swap-Spot Basis Label", overlay=true)


cursym = str.tostring(syminfo.tickerid)

symname = str.substring(cursym, 0, str.length(cursym) - 4)

spot = request.security(symname, timeframe.period, close)

basis1 = ((close-spot)/close)*100

basis = math.round(basis1, 4)


dt = time - time[1]

lineCol = (basis > 0) ? color.green : (basis < 0) ? color.red : color.black

lbl = label.new(time + 60*dt, close, xloc=xloc.bar_time, text=str.tostring(basis), style=label.style_none, textcolor=lineCol, size=size.small)

label.delete(lbl[1])