The Investment Clock
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Original Author: © BarefootJoey
//
// Inspiration: https://macro-ops.com/the-investment-clock/
// Model:       https://medium.com/@richardhwlin/how-does-investment-clock-work-c7d8fbbeb7bd
//
//@version=5
indicator("The Investment Clock", overlay=false)

// ----------------------- 🦶 BarefootJoey Theme ---------------------------- //
// Colors
red = color.red
green = color.green
fuchsia = color.fuchsia
yellow = color.yellow
aqua = color.aqua
orange = color.orange
// Groups
grg = "Growth"
gri = "Inflation"
grip = "Info Panel"

// --------------------- Inflation vs Growth YoY ---------------------------- //
// Growth
sustainable = input.float(2.5, "Sustainable Growth", minval=0, group=grg)
hline(sustainable, color=yellow, editable=false)

i_input = input.symbol("GDPC1", title="Growth Ticker", group=grg, tooltip="You may get errors if your chart is set to a different timeframe/ticker than 1d CPILFESL")
tickeri = request.security(i_input, "D", close)
tickero = (ta.change(tickeri,12) / tickeri[12]) *100
plot(tickero, title="Growth", color = tickero>tickero[1] ? yellow : tickero<tickero[1] ? fuchsia : color.gray)

// Inflation
sustainable2 = input.float(3, "Sustainable Inflation", minval=0, group=gri)
hline(sustainable2, color=aqua, editable=false)

i_input2 = input.symbol("CPILFESL", title="Inflation Ticker", group=gri, tooltip="You may get errors if your chart is set to a different timeframe/ticker than 1d CPILFESL")
tickeri2 = request.security(i_input2, "D", close)
tickero2 = (ta.change(tickeri2,12) / tickeri2[12]) *100
plot(tickero2, title="Inflation", color = tickero2>tickero2[1] ? aqua : tickero2<tickero2[1] ? orange : color.gray)

// Define High/Low Growth/Inflation
hg = tickero>sustainable
lg = tickero<sustainable
hi = tickero2>sustainable2
li = tickero2<sustainable2

// Define the 4 phases & indicate them via background color
// Overheat
overheat = hg and hi
overheatcol = overheat ? orange : na
overheatcolbg = overheat ? color.new(overheatcol,80) : na
bgcolor(overheatcolbg, title="🔥 Overheating Background")
// Stagflation
stagflation = lg and hi
stagflationcol = stagflation ? red : na
stagflationcolbg = stagflation ? color.new(stagflationcol,80) : na
bgcolor(stagflationcolbg, title="📉 Stagflation Background")
// Reflation
reflation = lg and li
reflationcol = reflation ? yellow : na
reflationcolbg = reflation ? color.new(reflationcol,80) : na
bgcolor(reflationcolbg, title="🎈 Reflation Background")
// Recovery
recovery = hg and li
recoverycol = recovery ? green : na
recoverycolbg = recovery ? color.new(recoverycol,80) : na
bgcolor(recoverycolbg, title="🤒 Recovery Background")

// ----------------------------- Info Panel --------------------------------- //
// Status
status = overheat ? "🔥 Overheating: Commodities ⛽"
  : stagflation ? "📉 Stagflation: Cash 💰"
  : recovery ? "🤒 Recovery: Stocks 📈"
  : reflation ? "🎈 Reflation: Bonds 🎫"
  : na

// Tooltip
ttip = overheat ? "📈 High Inflation\n🥵 Low Growth\n👟📉 Hold Cyclical Value\n🚜 Hold Industrials $IYJ\n🔴 Fading Info Tech $IYW 💻\n🔴 Fading Basic Materials $IYM 🧱\n🟢 Buying Oil & Gas $IYE ⛽\n👀 See Rate Hikes 📈\n🔮 Anticipate Stagflation or Recovery"
  : stagflation ? "📉 Low Inflation\n🥵 Low Growth\n🍗📉 Hold Defensive Value\n⚡ Hold Utilities $IDU\n🟢 Buying Consumer Staples $IYK\n 🟢 Buying Healthcare $IYH 🩺\n🔴 Fading Oil & Gas $IYE ⛽\n🔮 Anticipate Reflation or Overheating"
  : recovery ? "📉 Low Inflation\n💪 High Growth\n👟📈 Hold Cyclical Growth\n📞 Hold Telecom $IYZ\n🟢  Buying Info Tech $IYW 💻\n 🟢 Buying Basic Materials $IYM 🧱\n🔴 Fading Consumer Discretionary $IYC 🎮\n🔮 Anticipate Overheating or Reflation"
  : reflation ? "📈 High Inflation\n💪 High Growth\n🍗📈 Hold Defensive Growth\n🏦 Hold Financials $IYF\n🔴 Fading Consumer Staples $IYK\n 🔴 Fading Healthcare $IYH 🩺\n🟢 Buying Consumer Discretionary $IYC 🎮\n👀 See Rate Cuts 📉\n🔮 Anticipate Recovery or Stagflation"
  : na

// Text Color
txtcol = overheat ? overheatcol
  : stagflation ? stagflationcol
  : recovery ? recoverycol
  : reflation ? reflationcol
  : na

// Info Panel
position = input.string(position.bottom_center, "Info Panel Position", [position.top_center, position.top_right, position.middle_right, position.bottom_right, position.bottom_center, position.bottom_left, position.middle_left, position.top_left], group=grip)
size2 = input.string(size.small, "Info Panel Size", [size.tiny, size.small, size.normal, size.large, size.huge], group=grip)
var table Ticker = na
Ticker := table.new(position, 1, 1)
if barstate.islast // and showticker
    table.cell(Ticker, 0, 0, 
      text = status,
      text_size = size2, 
      text_color = txtcol,
      tooltip = ttip)

// EoS made w/ ❤ by @BarefootJoey ✌💗📈