Recession Indicator (Unemployment Rate)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VanHe1sing

//@version=5
indicator("Recession Indicator (Unemployment Rate)")

// Unemployment Rate source
src = request.security("UNRATE", "", close)

// Yearly Rate of change
YoY = (src-src[12])/src[12]

//Checking of timeframe
timeframe = timeframe.ismonthly

// Colored background between the annual ROC above zero and its peak
var ath = 0.0
if YoY > ath
    ath := YoY
bgcolor(timeframe ? (YoY > 0 and YoY < ath and YoY > ta.sma(YoY,5) ? color.rgb(120, 123, 134, 31): na) : na)

//Plot's
plot(timeframe ? YoY : na, color = color.white), plot(timeframe ? 0 : na, color = color.gray)

// Checker of timeframe
tbl= table.new(position.middle_center,1,1),table.cell(tbl, 0, 0, timeframe ? "" : "USE MONTHLY TIMEFRAME", text_color = color.red, text_size = size.huge)
