Modified Mannarino Market Risk Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HARRYDAN2
//@version=5

indicator(title='Modified Mannarino Market Risk Indicator', shorttitle='MMMRI', overlay=false, scale=scale.right, format=format.price)

var table risk = table.new(position=position.top_right, columns=1, rows=1)

lowRisk = input(title='Low Risk', defval=80)
moderateRisk = input(title='Moderate Risk', defval=140)
highRisk = input(title='High Risk', defval=180)
extremeRisk = input(title='Extreme Risk', defval=220)
tardMode = input(title='  Tard Mode', defval=260)
somethingsawry = input(title='Somethings Awry', defval=300)
buyputs = input(title='Buy Puts or Calls, RIsk is a Double Edged Sword', defval=350)
getstock = input(title = 'Request Stock Certificate', defval = 400)
systemerror = input(title = 'System Error Imminent', defval = 500)
maLength = input(title="SMA Length", defval=50)
hideSma = input.bool(title="Hide SMA", defval=false)

highlight(mmri) =>
    col = color.green
    if mmri > lowRisk and mmri < moderateRisk
        col := color.yellow
        col
    if mmri >= moderateRisk and mmri < highRisk
        col := color.orange
        col
    if mmri >= highRisk and mmri < extremeRisk
        col := color.red
        col
    if mmri >= extremeRisk and mmri < tardMode
        col := color.white
        col
    if mmri >= tardMode and mmri < somethingsawry
        col := color.blue
        col
    if mmri >= somethingsawry and mmri < buyputs
        col := color.purple
        col
    if mmri >= buyputs and mmri < getstock
        col := color.rgb(12, 211, 151)
        col
    if mmri >= getstock and mmri < systemerror 
        col := color.rgb(95, 50, 255)
        col
    if mmri > systemerror
        col := color.rgb(255, 109, 52)
    col

riskLevel(mmri) =>
    text_1 = 'Low Risk'
    if mmri > lowRisk and mmri < moderateRisk
        text_1 := 'Moderate Risk'
        text_1
    if mmri >= moderateRisk and mmri < highRisk
        text_1 := 'High Risk'
        text_1
    if mmri >= highRisk
        text_1 := 'Extreme Risk'
        text_1
    if mmri >= extremeRisk
        text_1 := 'Tard Mode'
        text_1
    if mmri >= tardMode
        text_1 := 'Somethings Awry'
        text_1
    if mmri >= somethingsawry
        text_1 := 'Buy Puts or Calls, RIsk is a Double Edged Sword'
        text_1 
    if mmri >= buyputs
        text_1 := 'Request Stock Certificate'
        text_1 
    if mmri >= getstock
        text_1 := 'System Error Imminent'
        text_1 
    text_1

dollarSymbol = input.symbol(title='Dollar Symbol', defval='dxy')
yieldSymbol = input.symbol(title='Yield Symbol', defval='tnx')
mmriConstant = input(title='Divisor', defval=1.61)
debtgdpConstant = input(title='Multiplier', defval=1.356)

dxy = request.security(symbol=dollarSymbol, timeframe='', expression=close)
yield = request.security(symbol=yieldSymbol, timeframe='', expression=close)
mmmri = ((dxy * yield)/(mmriConstant)) * (debtgdpConstant) 

table.set_bgcolor(risk, highlight(mmmri))
table.cell(risk, 0, 0, str.tostring(riskLevel(mmmri)))
plot(series=mmmri, title="MMRI", trackprice=false, color=highlight(mmmri))
plot(series=hideSma ? na : ta.sma(mmmri, maLength), title="SMA", color=color.new(color.blue, 50))