Inflation Rate of Change
// 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("Inflation Rate of Change", shorttitle="CPI Inflation ROC", overlay=false)

//Selects Consumer Price Index Data Source
CPISourceInput = input.string(title="Data Source", defval="All Items", options=["All Items", "Food", "Housing", "Energy", "Medical", "Apparel"])

//Maps Selection to Data Source
CPISource = CPISourceInput== "All Items" ? "FRED:CPIAUCSL" : CPISourceInput== "Food" ? "FRED:CPIUFDNS" : CPISourceInput== "Housing" ? "FRED:CPIHOSNS" : CPISourceInput== "Energy" ? "FRED:CPIENGSL" : CPISourceInput== "Medical" ? "FRED:CPIMEDSL" : CPISourceInput== "Apparel" ? "FRED:CPIAPPSL" : "All Items"

//Pulls in Consumer Price Index Data
CPI = request.security(CPISource, "D", close)
ROCBarsBack = input.int(253, "Comparing to CPI # of Bars Back", tooltip = "To compare CPI change year over year, you would put 253 here if on any typical market DAY chart, or 12 if on a MONTH chart.")
CPIROC = 100*(CPI-CPI[ROCBarsBack])/CPI

//Plots 
plot(CPIROC, color = color.red)
