Yield Curve (2-10yr)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © charles edwards

//@version=4
study("Yield Curve (2-10yr)", overlay=false)

TwoYear = security("DGS2", "D", close)
TenYear = security("DGS10", "D", close)

YC = (TenYear - TwoYear)

curveO  = plot(YC)
lineO   = plot(0, color=color.gray)
fill(plot1=curveO, plot2=lineO, color= YC<0 ? color.new(color.red,70): na, title="Inverted")

// Sourcing
var table_source = table(na)
table_source := table.new(position=position.bottom_left, columns=1, rows=1, bgcolor=color.white, border_width=1)
table.cell(table_source, 0, 0, text="Source: Capriole Investments Limited", bgcolor=color.white, text_color=color.black, width=20, height=7, text_size=size.normal, text_halign=text.align_left)