#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © HARRYDAN2
#indicator(title='Modified Mannarino Market Risk Indicator', shorttitle='MMMRI', overlay=false, scale=scale.right, format=format.price)
# Converted and mod by Sam4Cok@Samer800 - 05/2023
declare lower;
input LevelType = {Default "10 Levels", "5 Levels"};
input useChartTimeframe = {Default "Yes", "No"};
input ManualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input ShowAlertLabel = yes;
input showDetailedLabel = yes;
input useModifiedMmri = yes;
input maLength = 50; # "SMA Length"
input hideSma = no; # "Hide SMA"
input dollarSymbol = "$DXY"; # 'Dollar Symbol'
input yieldSymbol = "TNX"; # 'Yield Symbol'
input mmriConstant = 1.61; # 'Divisor'
input debtGdpConstant = 1.29; # 'Multiplier'
def lowRisk = 80; # 'Low Risk'
def moderateRisk = 140; # 'Moderate Risk'
def highRisk = 180; # 'High Risk'
def extremeRisk = 220; # 'Extreme Risk'
def tardMode = 260; # 'Tard Mode'
def somethingsAwry = 300; # 'Somethings Awry'
def buyPuts = 350; # 'Buy Puts or Calls, RIsk is a Double Edged Sword'
def getStock = 400; # 'Request Stock Certificate'
def systemError = 500; # 'System Error Imminent'
def na = Double.NaN;
def theme = LevelType==LevelType."10 Levels";
def current = GetAggregationPeriod();
def isintraday = current < AggregationPeriod.DAY;
def RTH = if isintraday then SecondsTillTime(0830) < 0 and SEcondsTillTime(1500) > 0 else 1;
def RTH1 = if isintraday then SecondsTillTime(0830) < 0 and SEcondsTillTime(1600) > 0 else 1;
def dollarClose; def yieldClose;
switch (useChartTimeframe) {
case "Yes" :
dollarClose = close(Symbol = dollarSymbol);
yieldClose = close(Symbol = yieldSymbol);
case "No" :
dollarClose = close(Symbol = dollarSymbol, Period = ManualTimeframe);
yieldClose = close(Symbol = yieldSymbol, Period = ManualTimeframe);
}
def dxy = if RTH then dollarClose else dxy[1];
def yield = if RTH then yieldClose/10 else yield[1];
def mri = if RTH then ((dxy * yield)/(mmriConstant)) else mri[1];
def mmri = if RTH then ((dxy * yield)/(mmriConstant)) * (debtgdpConstant) else mmri[1];
def mmmri = if useModifiedMmri then mmri else mri;
def sma = if RTH then SimpleMovingAvg(mmmri, maLength) else sma[1];
def col1 =
if mmmri < 050 then 1 else
if mmmri >= 050 and mmmri < 100 then 2 else
if mmmri >= 100 and mmmri < 200 then 3 else
if mmmri >= 200 and mmmri < 300 then 4 else 0;
def col =
if mmmri > lowRisk and mmmri < moderateRisk then 1 else
if mmmri >= moderateRisk and mmmri < highRisk then 2 else
if mmmri >= highRisk and mmmri < extremeRisk then 3 else
if mmmri >= extremeRisk and mmmri < tardMode then 4 else
if mmmri >= tardMode and mmmri < somethingsawry then 5 else
if mmmri >= somethingsawry and mmmri < buyputs then 6 else
if mmmri >= buyputs and mmmri < getstock then 7 else
if mmmri >= getstock and mmmri < systemerror then 8 else
if mmmri > systemerror then 9 else 0;
def riskLevel =
if mmmri > lowRisk and mmmri < moderateRisk then 1 else
if mmmri >= moderateRisk and mmmri < highRisk then 2 else
if mmmri >= highRisk then 3 else
if mmmri >= extremeRisk then 4 else
if mmmri >= tardMode then 5 else
if mmmri >= somethingsawry then 6 else
if mmmri >= buyputs then 7 else
if mmmri >= getstock then 8 else 0;
plot MMRIline = if RTH1 then mmmri else na;#, title="MMRI", trackprice=false, color=highlight(mmmri))
plot SMAline = if hideSma or !RTH1 then na else sma;#(mmmri, maLength), title="SMA", color=color.new(color.blue, 50))
MMRIline.SetLineWeight(2);
MMRIline.AssignValueColor(if theme then
if col==1 then Color.YELLOW else
if col==2 then Color.LIGHT_RED else
if col==3 then Color.RED else
if col==4 then Color.WHITE else
if col==5 then Color.CYAN else
if col==6 then Color.MAGENTA else
if col==7 then CreateColor(12, 211, 151) else
if col==8 then CreateColor(95, 50, 255) else
if col==9 then CreateColor(255, 109, 52) else Color.GREEN else
if col1==1 then Color.CYAN else
if col1==2 then Color.GREEN else
if col1==3 then Color.GRAY else
if col1==4 then Color.DARK_ORANGE else Color.RED);
SMAline.SetDefaultColor(Color.BLUE);
AddLabel(ShowAlertLabel, if theme then
if riskLevel==1 then "Moderate Risk" else
if riskLevel==2 then "High Risk" else
if riskLevel==3 then "Extreme Risk" else
if riskLevel==4 then "Tard Mode" else
if riskLevel==5 then "Somethings Awry" else
if riskLevel==6 then "Buy Puts or Calls, RIsk is a Double Edged Sword" else
if riskLevel==7 then "Request Stock Certificate" else
if riskLevel==8 then "System Error Imminent" else "Low Risk" else
if col1==1 then "Slight Risk" else
if col1==2 then "Low Risk" else
if col1==3 then "Moderate Risk" else
if col1==4 then "High Risk" else "Extreme Risk" ,
if theme then
if col==1 then Color.YELLOW else
if col==2 then Color.LIGHT_RED else
if col==3 then Color.RED else
if col==4 then Color.WHITE else
if col==5 then Color.CYAN else
if col==6 then Color.MAGENTA else
if col==7 then CreateColor(12, 211, 151) else
if col==8 then CreateColor(95, 50, 255) else
if col==9 then CreateColor(255, 109, 52) else Color.GREEN else
if col1==1 then Color.CYAN else
if col1==2 then Color.GREEN else
if col1==3 then Color.GRAY else
if col1==4 then Color.DARK_ORANGE else Color.RED);
AddLabel(showDetailedLabel, "MMMRI: " + ROUND(mmri, 2), color.WHITE);
AddLabel(showDetailedLabel, "MMRI: " + ROUND(mri, 2), color.WHITE);
AddLabel(showDetailedLabel, "DXY: " + ROUND(dxy, 2), color.WHITE);
AddLabel(showDetailedLabel, "US10Y: " + ROUND(yield, 2) + "%", color.WHITE);
#-- END CODE