Yield Curve Inversion Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=5
// Author = TradeAutomation


indicator("Bond Yield Curve Inversion", shorttitle="Yield Curve Inversion", overlay=false, timeframe="", timeframe_gaps=false)
//Indicator can be used as a quick/easy check to see if there is a US bond interest rate yield curve inversion. 
//Indicator can be applied to any chart, as it pulls in a comparison of 2 bond interest rate tickers regardless of the chart it is on.
//If the red line is over the green line, it indicates that there is a yield curve inversion. 
//More information about the significance of an inverted yield curve can be found here: https://www.investopedia.com/terms/i/invertedyieldcurve.asp

// Pulls in and compares the value of 13 week and 10 year bonds
Treasury13Wk = request.security("US03M", timeframe.period, close)
Treasury5Yr = request.security("US05Y", timeframe.period, close)
Treasury10Yr = request.security("US10Y", timeframe.period, close)
CBOE13Wk = request.security("CBOE:IRX.P", timeframe.period, close)
CBOE5yr = request.security("CBOE:FVX.P", timeframe.period, close)
CBOE10Yr = request.security("CBOE:TNX.P", timeframe.period, close)
//FRB10YR13WDifference = request.security("T10Y3M", timeframe.period, close)

// Allows the user to select the data source for the data pull
YieldSource = input.bool(false, "Use CBOE Index Rate Instead of Actual Yield?", tooltip="The default will pull in actual yields. If CBOE is selected it will pull in the equivalent CBOE index rate. The index rate is not the actual rate, but will give you an approximation of the relative yield curves with more historical data")
Bond13Wk = YieldSource==true ? CBOE13Wk : Treasury13Wk
Bond5Yr = YieldSource==true ? CBOE5yr : Treasury5Yr
Bond10Yr = YieldSource==true ? CBOE10Yr : Treasury10Yr
Inverted = Bond13Wk>Bond10Yr 
//or FRB10YR13WDifference<0

// Plots
plot(input.bool(true, "Plot 13wk?") ==true ? Bond13Wk : na, color = color.red)
plot(input.bool(false, "Plot 5yr?") ==true ? Bond5Yr : na, color=color.yellow)
plot(input.bool(true, "Plot 10yr?") ==true ? Bond10Yr : na, color = color.green)
//plot(input.bool(false, "Plot Fed Published 10yr-13wk?") ==true ? FRB10YR13WDifference : na, color = color.orange)
hline(input.float(2, "H Line", step=.1, tooltip = "This is a custom dashed line. You can define the value with this input make the indicator easier to check if it is over/under a value"))
plotshape(Inverted, style=shape.cross, location=location.bottom)