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

//@version=5
indicator("Net Liq", shorttitle = "Net Liq", overlay = false, scale = scale.right)
import calebsandfort/NetLiquidityLibrary/7

net_liquidity = NetLiquidityLibrary.get_net_liquidity()

plot(net_liquidity > 0 ? net_liquidity / 1000000000 : na, title = "Net Liq",  trackprice = true, linewidth = 2)

var fed_c_delta = "8,677b"
var tga_c_delta = "545b"
var rrp_c_delta = "2,238b"
var nl_c_delta = "5,894b"
var fed_d_delta = "0b"
var tga_d_delta = "+15b"
var rrp_d_delta = "+5b"
var nl_d_delta = "-20b"
var fed_w_delta = "0b"
var tga_w_delta = "-6b"
var rrp_w_delta = "+8b"
var nl_w_delta = "-2b"
var fed_ww_delta = "-46b"
var tga_ww_delta = "-114b"
var rrp_ww_delta = "+51b"
var nl_ww_delta = "+17b"
var fed_www_delta = "-67b"
var tga_www_delta = "-110b"
var rrp_www_delta = "-4b"
var nl_www_delta = "+47b"
var fed_m_delta = "-82b"
var tga_m_delta = "-69b"
var rrp_m_delta = "-9b"
var nl_m_delta = "-3b"

var fed_d_delta_pos = false
var tga_d_delta_pos = true
var rrp_d_delta_pos = true
var nl_d_delta_pos = false
var fed_w_delta_pos = false
var tga_w_delta_pos = false
var rrp_w_delta_pos = true
var nl_w_delta_pos = false
var fed_ww_delta_pos = false
var tga_ww_delta_pos = false
var rrp_ww_delta_pos = true
var nl_ww_delta_pos = true
var fed_www_delta_pos = false
var tga_www_delta_pos = false
var rrp_www_delta_pos = false
var nl_www_delta_pos = true
var fed_m_delta_pos = false
var tga_m_delta_pos = false
var rrp_m_delta_pos = false
var nl_m_delta_pos = false

textColor = color.white
bullishColor = color.green
bearishColor = color.red
header_color = #2196F3
bg_color = #2A2E39
current_bg_color = color.purple

var table infoTable = table.new(position.bottom_left, 7, 5, frame_color=textColor, frame_width = 1, border_color=textColor, border_width = 1)

if barstate.islast
    table.cell(infoTable, 0, 0, "Metric", bgcolor=header_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 1, 0, "Current", bgcolor=header_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 2, 0, "1DΔ", bgcolor=header_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 3, 0, "1WΔ", bgcolor=header_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 4, 0, "2WΔ", bgcolor=header_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 5, 0, "3WΔ", bgcolor=header_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 6, 0, "1MΔ", bgcolor=header_color, text_color=textColor, text_size = size.small)
    
    table.cell(infoTable, 0, 1, "FED BS", bgcolor=bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 1, 1, fed_c_delta, bgcolor=current_bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 2, 1, fed_d_delta, bgcolor=fed_d_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 3, 1, fed_w_delta, bgcolor=fed_w_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 4, 1, fed_ww_delta, bgcolor=fed_ww_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 5, 1, fed_www_delta, bgcolor=fed_ww_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 6, 1, fed_m_delta, bgcolor=fed_m_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)

    table.cell(infoTable, 0, 2, "TGA", bgcolor=bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 1, 2, tga_c_delta, bgcolor=current_bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 2, 2, tga_d_delta, bgcolor=tga_d_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 3, 2, tga_w_delta, bgcolor=tga_w_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 4, 2, tga_ww_delta, bgcolor=tga_ww_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 5, 2, tga_www_delta, bgcolor=tga_ww_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 6, 2, tga_m_delta, bgcolor=tga_m_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    
    table.cell(infoTable, 0, 3, "RRP", bgcolor=bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 1, 3, rrp_c_delta, bgcolor=current_bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 2, 3, rrp_d_delta, bgcolor=rrp_d_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 3, 3, rrp_w_delta, bgcolor=rrp_w_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 4, 3, rrp_ww_delta, bgcolor=rrp_ww_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 5, 3, rrp_ww_delta, bgcolor=rrp_www_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 6, 3, rrp_m_delta, bgcolor=rrp_m_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    
    table.cell(infoTable, 0, 4, "Net Liq", bgcolor=bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 1, 4, nl_c_delta, bgcolor=current_bg_color, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 2, 4, nl_d_delta, bgcolor=nl_d_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 3, 4, nl_w_delta, bgcolor=nl_w_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 4, 4, nl_ww_delta, bgcolor=nl_ww_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 5, 4, nl_www_delta, bgcolor=nl_www_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)
    table.cell(infoTable, 6, 4, nl_m_delta, bgcolor=nl_m_delta_pos ? bullishColor : bearishColor, text_color=textColor, text_size = size.small)