USTS Yield Curve Inversions
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dharmatech

//@version=5
indicator("Yield Curve Inversion", overlay = false)

DGS30  = request.security("DGS30",  "D", close)
DGS20  = request.security("DGS20",  "D", close)
DGS10  = request.security("DGS10",  "D", close)
DGS7   = request.security("DGS7",   "D", close)
DGS5   = request.security("DGS5",   "D", close)
DGS3   = request.security("DGS3",   "D", close)
DGS2   = request.security("DGS2",   "D", close)
DGS1   = request.security("DGS1",   "D", close)
DGS6MO = request.security("DGS6MO", "D", close)
DGS3MO = request.security("DGS3MO", "D", close)
DGS1MO = request.security("DGS1MO", "D", close)
RRP    = request.security("RRPONTSYAWARD", "D", close)

get_color(a, b) =>
    if (b < a)
        color.red
    else if (b >= a)
        color.green
    else
        color.black

plot(1.0, linewidth = 11, color = get_color(DGS20, DGS30))
plot(0.9, linewidth = 11, color = get_color(DGS10, DGS20))
plot(0.8, linewidth = 11, color = get_color(DGS7, DGS10))
plot(0.7, linewidth = 11, color = get_color(DGS5, DGS7))
plot(0.6, linewidth = 11, color = get_color(DGS3, DGS5))
plot(0.5, linewidth = 11, color = get_color(DGS2, DGS3))
plot(0.4, linewidth = 11, color = get_color(DGS1, DGS2))
plot(0.3, linewidth = 11, color = get_color(DGS6MO, DGS1))
plot(0.2, linewidth = 11, color = get_color(DGS3MO, DGS6MO))
plot(0.1, linewidth = 11, color = get_color(DGS1MO, DGS3MO))
plot(0.0, linewidth = 11, color = get_color(RRP, DGS1MO))

if barstate.islast
    label.new(bar_index + 5, 1.0 - 0.03, "30Y", style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.9 - 0.03, "20Y", style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.8 - 0.03, "10Y", style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.7 - 0.03, "7Y",  style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.6 - 0.03, "5Y",  style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.5 - 0.03, "3Y",  style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.4 - 0.03, "2Y",  style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.3 - 0.03, "1Y",  style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.2 - 0.03, "6M",  style = label.style_none, textcolor = color.yellow)
    label.new(bar_index + 5, 0.1 - 0.03, "3M",  style = label.style_none, textcolor = color.yellow)    
    label.new(bar_index + 5, 0.0 - 0.03, "1M",  style = label.style_none, textcolor = color.yellow)    