Net USD Liquidity w/ overlays [tedtalksmacro]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tedtalksmacro

//@version=5
indicator("Net USD Liquidity w/ overlays [tedtalksmacro]", overlay = false)

//USCBBS-RRPONTTLD*1000000000-WTREGEN*1000000000

balance_sheet = request.security("USCBBS", 'D', close)
treasury_gen = request.security("WTREGEN", 'D', close)
rrp = request.security("RRPONTTLD", 'D', close)

value = (balance_sheet-treasury_gen-rrp) / 1000000000000
var booleish = true

seven_sma = ta.ema(value, 20)

bullish = value > seven_sma
bearish = value < seven_sma

if booleish
    if bearish
        booleish := false
if not booleish
    if bullish
        booleish := true

// mycolor = higher ? color.silver : lower ? color.blue : na
sentimentColor = booleish ? color.rgb(101, 171, 103) : color.rgb(197, 10, 10)
plot(value, transp = 0, linewidth=2, color= sentimentColor, title = 'USD Liquidity [tln USD]')
plot(treasury_gen / 100000000000, style = plot.style_columns, linewidth=2, color= color.orange, title = 'Treasury General Account [tln USD]')
plot(rrp / 1000000000000, style = plot.style_columns, linewidth=1, color= color.new(color.black, 0), title = 'Reverse Repo [tln USD]')