CE - 42MACRO Fixed Income and Macro 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Celestial-Eye

//          QUICK GUIDE: https://docs.google.com/document/d/1b-ZVyQghSqDETX_GF_-OSIBCa4e0CBGqENbdfId9I-s/edit?usp=sharing

//@version=5
indicator("🌌 CE - 42MACRO Fixed Income and Macro 🌌", "🌌 CE - FIM 🌌")

showPerfTab  = input.bool(true,               "Show Performance Table",               tooltip = "Plots the Performance table",                                                  group = "🌌 Table Settings Performance 🌌")
rocPeriod    = input.int (30,                 "ROC Period", minval=1,                 tooltip = "Defines the time horizon for the Performance Table",                           group = "🌌 Table Settings Performance 🌌")
CalcType     = input.string("Rate of Change", "Choose different Calculations",        ["Rate of Change", "Sharpe Ratio", "Sortino Ratio", "Omega Ratio", "Normalization"],      group = "🌌 Table Settings Performance 🌌")
useRelative  = input.bool(false,              "Use Relative Asset Calculation",       tooltip = "Calculates Asset values in comparison to all other Assets",                    group = "🌌 Table Settings Performance 🌌")

reg          = input.bool(false,              "Show calculated regimes",                                                                                                        group = "Visuals - USE ONE AT A TIME FOR BEST EXPERIENCE")
colx         = input.bool(false,              "Visualize Risk On and Off Phases",                                                                                               group = "Visuals - USE ONE AT A TIME FOR BEST EXPERIENCE")
ultimateGRID = input.bool(false,              "Show ULTIMATE GRID regimes",           tooltip = "Uses all different calculations to find the average regimes",                  group = "Visuals - USE ONE AT A TIME FOR BEST EXPERIENCE")                                             
ultimateRISK = input.bool(false,              "Show ULTIMATE RISK Phases",            tooltip = "Uses all different calculations to find the Risk On/OFF phase",                group = "Visuals - USE ONE AT A TIME FOR BEST EXPERIENCE")                                             
barcRisk     = input.bool(false,              "Barcolor Risk Phases",                 tooltip = "Barcolors Risk On/OFF phases if either one is enabled",                        group = "Visuals - USE ONE AT A TIME FOR BEST EXPERIENCE")                                             
barcGRID     = input.bool(false,              "Barcolor GRID regimes",                tooltip = "Barcolors GRID regimes if either one is enabled",                              group = "Visuals - USE ONE AT A TIME FOR BEST EXPERIENCE")                                             


f_calc(name) =>
    request.security(name, "D", close, barmerge.gaps_off)


//Fixed Income
CWB  = f_calc("CWB")                        // CWB (Convertibles)
BKLN = f_calc("BKLN")                       // BKLN (Leveraged Loans)
HYG  = f_calc("HYG")                        // HYG (High Yield Credit)
PFF  = f_calc("PFF")                        // PFF (Preferreds)
EMB  = f_calc("EMB")                        // EMB (Emerging Market US$ Bonds)
TLT  = f_calc("TLT")                        // TLT (Long Bond)
IEF  = f_calc("IEF")                        // IEF (5-10yr Treasurys)
TIP  = f_calc("TIP")                        // TIP (5-10yr TIPS)
STIP = f_calc("STIP")                       // STIP (0-5yr TIPS)
EMLC = f_calc("EMLC")                       // EMLC (EM Local Currency Bonds)
BIZD = f_calc("AMEX:BIZD")                  // BIZD (BDCs)
AGG  = f_calc("AGG")                        // AGG (Barclays Agg)
LQD  = f_calc("LQD")                        // LQD (Investment Grade Credit)
MBB  = f_calc("MBB")                        // MBB (MBS)
SHY  = f_calc("SHY")                        // SHY (1-3yr Treasurys)

//Macro
BITO = f_calc("BITO")                       // BITO (Bitcoin)
DBB  = f_calc("DBB")                        // DBB (Industrial Metals)
DBC  = f_calc("DBC")                        // DBC (Commodities)
GLD  = f_calc("GLD")                        // GLD (Gold)
VIXM = f_calc("VIXM")                       // VIXM (Equity Volatility)
PFIX = f_calc("PFIX")                       // PFIX (Interest Rate Volatility)
USO  = f_calc("USO")                        // USO (Energy)
DBP  = f_calc("DBP")                        // DBP (Precious Metals)
DBA  = f_calc("DBA")                        // DBA (Agriculture)
UUP  = f_calc("UUP")                        // UUP (US Dollar)
UDN  = f_calc("UDN")                        // UDN (Inverse US Dollar)



// Fixed Income(Yield) Calculation
// Top 5 Fixed Income Factors 		Top 5 Fixed Income Factors 		     Top 5 Fixed Income Factors 		Top 5 Fixed Income Factors 
						
//   Convertibles (CWB)		           Leveraged Loans (BKLN)		        1-3yr Treasurys (SHY)		      1-3yr Treasurys (SHY)
						
//   Leveraged Loans (BKLN)		       Convertibles (CWB)		            0-5yr TIPS (STIP)		          5-10yr Treasurys (IEF)
						 
//   High Yield Credit (HYG)		   High Yield Credit (HYG)		        5-10yr Treasurys (IEF)	          Barclays Agg (AGG)
						
//   Preferreds (PFF)		           0-5yr TIPS (STIP)		            5-10yr TIPS (TIP)		          MBS (MBB)
						
//   Emerging Market US$ Bonds (EMB)   BDCs (BIZD)		                    Long Bond (TLT)		              Investment Grade Credit (LQD)
						
//  Bottom 5 Fixed Income Factors 	Bottom 5 Fixed Income Factors 	    Bottom 5 Fixed Income Factors 		Bottom 5 Fixed Income Factors 
						
//   Long Bond (TLT)		           Long Bond (TLT)		                Convertibles (CWB)		          Preferreds (PFF)
						
//   5-10yr Treasurys (IEF)		       5-10yr Treasurys (IEF)		         BDCS (BIZD)		              BDCs (BIZD)
						 
//   5-10yr TIPS (TIP)		           Barclays Agg (AGG)		             EM Local Currency Bonds (EMLC)	  EM Local Currency Bonds (EMLC)
						
//   0-5yr TIPS (STIP)		           Investment Grade Credit (LQD)		 Preferreds (PFF)		          High Yield Credit (HYG)
						
//  EM Local Currency Bonds (EMLC)	   MBS (MBB)		                     Investment Grade Credit (LQD)	  Leveraged Loans (BKLN)



//                      <<HOW TO CALCULATE YIELDS...>> 
//            -> Beware that I changed that part and don't actually use Yield Calculation as I initially planned....
//            Reason beeing that the time horizon is too long and it negatively effects time coherence 

// Trailing 12-Month Yield: This metric represents the income generated by the ETF's underlying assets over the past 12 months, expressed as a percentage of the ETF's net asset value.

// SEC Yield: The SEC yield is an annualized yield calculation required by the U.S. Securities and Exchange Commission (SEC) for certain ETFs and mutual funds. 
//It is calculated based on the income earned by the ETF's holdings over the past 30 days and adjusted for any expense ratios or fees.

// Distribution Yield: The distribution yield is a measure of the ETF's income distribution, typically expressed as a percentage of its net asset value. 
//It considers dividends, interest payments, and any other distributions made by the ETF.

// Current Yield: The current yield is a simple yield calculation that measures the annual income generated by the ETF based on its current market price. 
//It is calculated by dividing the ETF's annual income (dividends and interest) by its current market price.

// Yield-to-Maturity (YTM): For bond ETFs, you can use the YTM metric to estimate the yield based on the bonds held by the ETF and their respective yields to maturity.

// Yield-to-Worst (YTW): For bond ETFs holding callable bonds, YTW estimates the lowest potential yield if the issuer calls the bonds before their maturity date.

////////////////////////////////////*********************************************************************** This is how it would look like

// CWB_sym  = "AMEX:CWB"
// BKLN_sym = "AMEX:BKLN"
// HYG_sym  = "AMEX:HYG"
// PFF_sym  = "NASDAQ:PFF"
// EMB_sym  = "NASDAQ:EMB"
// TLT_sym  = "NASDAQ:TLT"
// IEF_sym  = "NASDAQ:IEF"
// TIP_sym  = "AMEX:TIP"
// STIP_sym = "AMEX:STIP"
// EMLC_sym = "AMEX:EMLC"
// BIZD_sym = "AMEX:BIZD"
// AGG_sym  = "AMEX:AGG"
// LQD_sym  = "AMEX:LQD"
// MBB_sym  = "NASDAQ:MBB"
// SHY_sym  = "NASDAQ:SHY"

// // Function to calculate dividend yield
// getDividendYield(symbol,sym) =>
//     dividendPerShare = request.dividends(symbol)
//     dividendYield = (dividendPerShare / sym) * 100
//     dividendYield


// CWB_roc  = getDividendYield(CWB_sym,  CWB)
// BKLN_roc = getDividendYield(BKLN_sym, BKLN)
// HYG_roc  = getDividendYield(HYG_sym,  HYG)
// PFF_roc  = getDividendYield(PFF_sym,  PFF)
// EMB_roc  = getDividendYield(EMB_sym,  EMB)
// TLT_roc  = getDividendYield(TLT_sym,  TLT)
// IEF_roc  = getDividendYield(IEF_sym,  IEF)
// TIP_roc  = getDividendYield(TIP_sym,  TIP)
// STIP_roc = getDividendYield(STIP_sym, STIP)
// EMLC_roc = getDividendYield(EMLC_sym, EMLC)
// BIZD_roc = getDividendYield(BIZD_sym, BIZD) - 2
// AGG_roc  = getDividendYield(AGG_sym,  AGG)
// LQD_roc  = getDividendYield(LQD_sym,  LQD)
// MBB_roc  = getDividendYield(MBB_sym,  MBB)
// SHY_roc  = getDividendYield(SHY_sym,  SHY) 

////////////////////////////////////*********************************************************************** 

// <<<Now this is gonna be on how to compare them against each other...>>>

// Multiple options: 
// 1. Avg of all yields -> see which perform better and worse
// 2. Avg of only the regime Yields -> perfomance values
// 3. Avg of all top vs all bottom perfomers -> relative rate of change
// 4. sum of Top to Bot... then compare for highest/lowest



/////////////////*****************Fixed Income FACTORS*************//////////////////

//sharpe ratio calculation function         -> BY QuantiLuxe / ELiCobra
f_sharpe(src, lookback) =>
    float daily_return = src / src[1] - 1
    returns_array = array.new_float(0)
    for i = 0 to lookback
        array.push(returns_array, daily_return[i])
    
    standard_deviation = array.stdev(returns_array)
    mean = array.avg(returns_array)
    
    math.round(mean / standard_deviation * math.sqrt(lookback), 2)


//sortino ratio calculation function        -> BY QuantiLuxe / ELiCobra
f_sortino(src, lookback) =>
    float daily_return = src / src[1] - 1
    returns_array = array.new_float(0)
    negative_returns_array = array.new_float(0)
    for i = 0 to lookback
        array.push(returns_array, daily_return[i])
        if daily_return[i] <= 0.0
            array.push(negative_returns_array, daily_return[i])
        else
            array.push(negative_returns_array, 0.0)

    negative_returns_standard_deviation = array.stdev(negative_returns_array)
    mean = array.avg(returns_array)
    
    math.round(mean / negative_returns_standard_deviation * math.sqrt(lookback), 2)


//omega ratio calculation function        -> BY QuantiLuxe / ELiCobra
f_omega(src, lookback) =>
    float daily_return = src / src[1] - 1
    negative_returns_array = array.new_float(0)
    positive_returns_array = array.new_float(0)
    for i = 0 to lookback
        if daily_return[i] <= 0.0
            array.push(negative_returns_array, daily_return[i])
            array.push(positive_returns_array, 0.0)
        else
            array.push(positive_returns_array, daily_return[i])
            array.push(negative_returns_array, 0.0)

    postive_area = array.sum(positive_returns_array)
    negative_area = array.sum(negative_returns_array) * (-1)
    
    math.round(postive_area / negative_area, 2)


//normalization calculation function
f_normalization(src, lookback) =>
    lowest  = ta.lowest (src, lookback)
    highest = ta.highest(src, lookback)
    normalized = (src - lowest) / (highest - lowest) - 0.5


//calculate the average Fixed Income RoC
avgROCFI = math.avg(
         nz(ta.roc(CWB,  rocPeriod)),     
         nz(ta.roc(BKLN, rocPeriod)),     
         nz(ta.roc(HYG,  rocPeriod)),     
         nz(ta.roc(PFF,  rocPeriod)),     
         nz(ta.roc(EMB,  rocPeriod)),     
         nz(ta.roc(TLT,  rocPeriod)),     
         nz(ta.roc(IEF,  rocPeriod)),     
         nz(ta.roc(TIP,  rocPeriod)),     
         nz(ta.roc(STIP, rocPeriod)),     
         nz(ta.roc(EMLC, rocPeriod)),     
         nz(ta.roc(BIZD, rocPeriod)),     
         nz(ta.roc(AGG,  rocPeriod)),     
         nz(ta.roc(LQD,  rocPeriod)),     
         nz(ta.roc(MBB,  rocPeriod)),     
         nz(ta.roc(SHY,  rocPeriod))) 

//calculate the average Fixed Income Sharpe value
avgRoCFISH = math.avg(
         nz(f_sharpe(CWB,  rocPeriod)),     
         nz(f_sharpe(BKLN, rocPeriod)),     
         nz(f_sharpe(HYG,  rocPeriod)),     
         nz(f_sharpe(PFF,  rocPeriod)),     
         nz(f_sharpe(EMB,  rocPeriod)),     
         nz(f_sharpe(TLT,  rocPeriod)),     
         nz(f_sharpe(IEF,  rocPeriod)),     
         nz(f_sharpe(TIP,  rocPeriod)),     
         nz(f_sharpe(STIP, rocPeriod)),     
         nz(f_sharpe(EMLC, rocPeriod)),     
         nz(f_sharpe(BIZD, rocPeriod)),     
         nz(f_sharpe(AGG,  rocPeriod)),     
         nz(f_sharpe(LQD,  rocPeriod)),     
         nz(f_sharpe(MBB,  rocPeriod)),     
         nz(f_sharpe(SHY,  rocPeriod))) 

//calculate the average Fixed Income Sortino value
avgRoCFISO = math.avg(
         nz(f_sortino(CWB,  rocPeriod)),     
         nz(f_sortino(BKLN, rocPeriod)),     
         nz(f_sortino(HYG,  rocPeriod)),     
         nz(f_sortino(PFF,  rocPeriod)),     
         nz(f_sortino(EMB,  rocPeriod)),     
         nz(f_sortino(TLT,  rocPeriod)),     
         nz(f_sortino(IEF,  rocPeriod)),     
         nz(f_sortino(TIP,  rocPeriod)),     
         nz(f_sortino(STIP, rocPeriod)),     
         nz(f_sortino(EMLC, rocPeriod)),     
         nz(f_sortino(BIZD, rocPeriod)),     
         nz(f_sortino(AGG,  rocPeriod)),     
         nz(f_sortino(LQD,  rocPeriod)),     
         nz(f_sortino(MBB,  rocPeriod)),     
         nz(f_sortino(SHY,  rocPeriod))) 

//calculate the average Fixed Income Omega value
avgRoCFIO = math.avg(
         nz(f_omega(CWB,  rocPeriod)),     
         nz(f_omega(BKLN, rocPeriod)),     
         nz(f_omega(HYG,  rocPeriod)),     
         nz(f_omega(PFF,  rocPeriod)),     
         nz(f_omega(EMB,  rocPeriod)),     
         nz(f_omega(TLT,  rocPeriod)),     
         nz(f_omega(IEF,  rocPeriod)),     
         nz(f_omega(TIP,  rocPeriod)),     
         nz(f_omega(STIP, rocPeriod)),     
         nz(f_omega(EMLC, rocPeriod)),     
         nz(f_omega(BIZD, rocPeriod)),     
         nz(f_omega(AGG,  rocPeriod)),     
         nz(f_omega(LQD,  rocPeriod)),     
         nz(f_omega(MBB,  rocPeriod)),     
         nz(f_omega(SHY,  rocPeriod))) 

//calculate the average Fixed Income Normalized value
avgRoCFINO = math.avg(
         nz(f_normalization(CWB,  rocPeriod)),     
         nz(f_normalization(BKLN, rocPeriod)),     
         nz(f_normalization(HYG,  rocPeriod)),     
         nz(f_normalization(PFF,  rocPeriod)),     
         nz(f_normalization(EMB,  rocPeriod)),     
         nz(f_normalization(TLT,  rocPeriod)),     
         nz(f_normalization(IEF,  rocPeriod)),     
         nz(f_normalization(TIP,  rocPeriod)),     
         nz(f_normalization(STIP, rocPeriod)),     
         nz(f_normalization(EMLC, rocPeriod)),     
         nz(f_normalization(BIZD, rocPeriod)),     
         nz(f_normalization(AGG,  rocPeriod)),     
         nz(f_normalization(LQD,  rocPeriod)),     
         nz(f_normalization(MBB,  rocPeriod)),     
         nz(f_normalization(SHY,  rocPeriod))) 

var float CWB_roc   = na  
var float BKLN_roc  = na
var float HYG_roc   = na  
var float PFF_roc   = na  
var float EMB_roc   = na  
var float TLT_roc   = na  
var float IEF_roc   = na  
var float TIP_roc   = na  
var float STIP_roc  = na
var float EMLC_roc  = na
var float BIZD_roc  = na
var float AGG_roc   = na  
var float LQD_roc   = na  
var float MBB_roc   = na  
var float SHY_roc   = na  

/////////////////// -> potentially make a single function that then uses switch statements to decide the CalcType

if CalcType == "Rate of Change"
    // Calculate the relative RoC for each asset - Standard
    CWB_roc  := ta.roc(CWB , rocPeriod) - (useRelative? avgROCFI : 0)    
    BKLN_roc := ta.roc(BKLN, rocPeriod) - (useRelative? avgROCFI : 0)  
    HYG_roc  := ta.roc(HYG, rocPeriod)  - (useRelative? avgROCFI : 0)    
    PFF_roc  := ta.roc(PFF, rocPeriod)  - (useRelative? avgROCFI : 0)    
    EMB_roc  := ta.roc(EMB, rocPeriod)  - (useRelative? avgROCFI : 0)    
    TLT_roc  := ta.roc(TLT, rocPeriod)  - (useRelative? avgROCFI : 0)    
    IEF_roc  := ta.roc(IEF, rocPeriod)  - (useRelative? avgROCFI : 0)    
    TIP_roc  := ta.roc(TIP, rocPeriod)  - (useRelative? avgROCFI : 0)    
    STIP_roc := ta.roc(STIP, rocPeriod) - (useRelative? avgROCFI : 0)  
    EMLC_roc := ta.roc(EMLC, rocPeriod) - (useRelative? avgROCFI : 0)  
    BIZD_roc := ta.roc(BIZD, rocPeriod) - (useRelative? avgROCFI : 0)  
    AGG_roc  := ta.roc(AGG, rocPeriod)  - (useRelative? avgROCFI : 0)    
    LQD_roc  := ta.roc(LQD, rocPeriod)  - (useRelative? avgROCFI : 0)    
    SHY_roc  := ta.roc(SHY, rocPeriod)  - (useRelative? avgROCFI : 0)  
    MBB_roc  := ta.roc(MBB, rocPeriod)  - (useRelative? avgROCFI : 0)    

else if CalcType == "Sharpe Ratio"
    // Calculate the Sharpe ratio for each asset - optional
    CWB_roc  := f_sharpe(CWB , rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    BKLN_roc := f_sharpe(BKLN, rocPeriod)  - (useRelative? avgRoCFISH : 0)  
    HYG_roc  := f_sharpe(HYG,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    PFF_roc  := f_sharpe(PFF,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    EMB_roc  := f_sharpe(EMB,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    TLT_roc  := f_sharpe(TLT,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    IEF_roc  := f_sharpe(IEF,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    TIP_roc  := f_sharpe(TIP,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    STIP_roc := f_sharpe(STIP, rocPeriod)  - (useRelative? avgRoCFISH : 0)  
    EMLC_roc := f_sharpe(EMLC, rocPeriod)  - (useRelative? avgRoCFISH : 0)  
    BIZD_roc := f_sharpe(BIZD, rocPeriod)  - (useRelative? avgRoCFISH : 0)  
    AGG_roc  := f_sharpe(AGG,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    LQD_roc  := f_sharpe(LQD,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    
    SHY_roc  := f_sharpe(SHY,  rocPeriod)  - (useRelative? avgRoCFISH : 0)  
    MBB_roc  := f_sharpe(MBB,  rocPeriod)  - (useRelative? avgRoCFISH : 0)    

else if CalcType == "Sortino Ratio"
    // Calculate the Sortino ratio for each asset - optional
    CWB_roc  := f_sortino(CWB , rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    BKLN_roc := f_sortino(BKLN, rocPeriod)  - (useRelative? avgRoCFISO : 0)    
    HYG_roc  := f_sortino(HYG,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    PFF_roc  := f_sortino(PFF,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    EMB_roc  := f_sortino(EMB,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    TLT_roc  := f_sortino(TLT,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    IEF_roc  := f_sortino(IEF,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    TIP_roc  := f_sortino(TIP,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    STIP_roc := f_sortino(STIP, rocPeriod)  - (useRelative? avgRoCFISO : 0)    
    EMLC_roc := f_sortino(EMLC, rocPeriod)  - (useRelative? avgRoCFISO : 0)    
    BIZD_roc := f_sortino(BIZD, rocPeriod)  - (useRelative? avgRoCFISO : 0)    
    AGG_roc  := f_sortino(AGG,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    LQD_roc  := f_sortino(LQD,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          
    SHY_roc  := f_sortino(SHY,  rocPeriod)  - (useRelative? avgRoCFISO : 0)    
    MBB_roc  := f_sortino(MBB,  rocPeriod)  - (useRelative? avgRoCFISO : 0)          

else if CalcType == "Omega Ratio"
    // Calculate the Omega ratio for each asset - optional
    CWB_roc  := f_omega(CWB , rocPeriod) - (useRelative? avgRoCFIO : 0)        
    BKLN_roc := f_omega(BKLN, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    HYG_roc  := f_omega(HYG,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    PFF_roc  := f_omega(PFF,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    EMB_roc  := f_omega(EMB,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    TLT_roc  := f_omega(TLT,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    IEF_roc  := f_omega(IEF,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    TIP_roc  := f_omega(TIP,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    STIP_roc := f_omega(STIP, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    EMLC_roc := f_omega(EMLC, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    BIZD_roc := f_omega(BIZD, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    AGG_roc  := f_omega(AGG,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    LQD_roc  := f_omega(LQD,  rocPeriod) - (useRelative? avgRoCFIO : 0)        
    SHY_roc  := f_omega(SHY,  rocPeriod) - (useRelative? avgRoCFIO : 0)      
    MBB_roc  := f_omega(MBB,  rocPeriod) - (useRelative? avgRoCFIO : 0)        

else if CalcType == "Normalization"
    // Calculate the Normalization for each asset - optional
    CWB_roc  := f_normalization(CWB , rocPeriod) - (useRelative? avgRoCFINO : 0)    
    BKLN_roc := f_normalization(BKLN, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    HYG_roc  := f_normalization(HYG,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    PFF_roc  := f_normalization(PFF,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    EMB_roc  := f_normalization(EMB,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    TLT_roc  := f_normalization(TLT,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    IEF_roc  := f_normalization(IEF,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    TIP_roc  := f_normalization(TIP,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    STIP_roc := f_normalization(STIP, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    EMLC_roc := f_normalization(EMLC, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    BIZD_roc := f_normalization(BIZD, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    AGG_roc  := f_normalization(AGG,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    LQD_roc  := f_normalization(LQD,  rocPeriod) - (useRelative? avgRoCFINO : 0)    
    SHY_roc  := f_normalization(SHY,  rocPeriod) - (useRelative? avgRoCFINO : 0)  
    MBB_roc  := f_normalization(MBB,  rocPeriod) - (useRelative? avgRoCFINO : 0)    


// Calculate the probabilities for Fixed Income
GoldilocksY  = (CWB_roc >0?+1:0) + (BKLN_roc>0?+1:0) + (HYG_roc>0?+1:0) + (PFF_roc  >0?+1:0) + (EMB_roc >0?+1:0) + (TLT_roc<0?+1:0) + (IEF_roc <0?+1:0) + (TIP_roc <0?+1:0) + (STIP_roc<0?+1:0) + (EMLC_roc<0?+1:0)
ReflationY   = (BKLN_roc>0?+1:0) + (CWB_roc >0?+1:0) + (HYG_roc>0?+1:0) + (STIP_roc >0?+1:0) + (BIZD_roc>0?+1:0) + (TLT_roc<0?+1:0) + (IEF_roc <0?+1:0) + (AGG_roc <0?+1:0) + (LQD_roc <0?+1:0) + (MBB_roc <0?+1:0)
InflationY   = (SHY_roc >0?+1:0) + (STIP_roc>0?+1:0) + (IEF_roc>0?+1:0) + (TIP_roc  >0?+1:0) + (TLT_roc >0?+1:0) + (CWB_roc<0?+1:0) + (BIZD_roc<0?+1:0) + (EMLC_roc<0?+1:0) + (PFF_roc <0?+1:0) + (LQD_roc <0?+1:0) 
DeflationY   = (SHY_roc >0?+1:0) + (IEF_roc >0?+1:0) + (AGG_roc>0?+1:0) + (MBB_roc  >0?+1:0) + (LQD_roc >0?+1:0) + (PFF_roc<0?+1:0) + (BIZD_roc<0?+1:0) + (EMLC_roc<0?+1:0) + (HYG_roc <0?+1:0) + (BKLN_roc<0?+1:0)
DenumeratorY =  GoldilocksY + ReflationY +  InflationY +  DeflationY


/////////////////*****************MACRO FACTORS*************//////////////////

//calculate the average Macro RoC
avgROC = math.avg(
         nz(ta.roc(BITO, rocPeriod)),     
         nz(ta.roc(DBB,  rocPeriod)),     
         nz(ta.roc(DBC,  rocPeriod)),     
         nz(ta.roc(UDN,  rocPeriod)),     
         nz(ta.roc(GLD,  rocPeriod)),     
         nz(ta.roc(VIXM, rocPeriod)),     
         nz(ta.roc(UUP,  rocPeriod)),     
         nz(ta.roc(PFIX, rocPeriod)),     
         nz(ta.roc(USO,  rocPeriod)),     
         nz(ta.roc(DBP,  rocPeriod)),     
         nz(ta.roc(DBA,  rocPeriod)))

//calculate the average Macro Sharpe value
avgRoCMSH = math.avg(
         nz(f_sharpe(BITO, rocPeriod)),     
         nz(f_sharpe(DBB,  rocPeriod)),     
         nz(f_sharpe(DBC,  rocPeriod)),     
         nz(f_sharpe(UDN,  rocPeriod)),     
         nz(f_sharpe(GLD,  rocPeriod)),     
         nz(f_sharpe(VIXM, rocPeriod)),     
         nz(f_sharpe(UUP,  rocPeriod)),     
         nz(f_sharpe(PFIX, rocPeriod)),     
         nz(f_sharpe(USO,  rocPeriod)),     
         nz(f_sharpe(DBP,  rocPeriod)),     
         nz(f_sharpe(DBA,  rocPeriod)))

//calculate the average Macro Sortino value
avgRoCMSO = math.avg(
         nz(f_sortino(BITO, rocPeriod)),     
         nz(f_sortino(DBB,  rocPeriod)),     
         nz(f_sortino(DBC,  rocPeriod)),     
         nz(f_sortino(UDN,  rocPeriod)),     
         nz(f_sortino(GLD,  rocPeriod)),     
         nz(f_sortino(VIXM, rocPeriod)),     
         nz(f_sortino(UUP,  rocPeriod)),     
         nz(f_sortino(PFIX, rocPeriod)),     
         nz(f_sortino(USO,  rocPeriod)),     
         nz(f_sortino(DBP,  rocPeriod)),     
         nz(f_sortino(DBA,  rocPeriod)))

//calculate the average Macro Omega value
avgRoCMO = math.avg(
         nz(f_omega(BITO, rocPeriod)),     
         nz(f_omega(DBB,  rocPeriod)),     
         nz(f_omega(DBC,  rocPeriod)),     
         nz(f_omega(UDN,  rocPeriod)),     
         nz(f_omega(GLD,  rocPeriod)),     
         nz(f_omega(VIXM, rocPeriod)),     
         nz(f_omega(UUP,  rocPeriod)),     
         nz(f_omega(PFIX, rocPeriod)),     
         nz(f_omega(USO,  rocPeriod)),     
         nz(f_omega(DBP,  rocPeriod)),     
         nz(f_omega(DBA,  rocPeriod)))

//calculate the average Macro Normalized value
avgRoCMNO = math.avg(
         nz(f_normalization(BITO, rocPeriod)),     
         nz(f_normalization(DBB,  rocPeriod)),     
         nz(f_normalization(DBC,  rocPeriod)),     
         nz(f_normalization(UDN,  rocPeriod)),     
         nz(f_normalization(GLD,  rocPeriod)),     
         nz(f_normalization(VIXM, rocPeriod)),     
         nz(f_normalization(UUP,  rocPeriod)),     
         nz(f_normalization(PFIX, rocPeriod)),     
         nz(f_normalization(USO,  rocPeriod)),     
         nz(f_normalization(DBP,  rocPeriod)),     
         nz(f_normalization(DBA,  rocPeriod)))

var float rocBITO   = na     
var float rocDBB    = na     
var float rocDBC    = na     
var float rocUDN    = na     
var float rocGLD    = na     
var float rocVIXM   = na     
var float rocUUP    = na     
var float rocPFIX   = na     
var float rocUSO    = na     
var float rocDBP    = na      
var float rocDBA    = na 


if CalcType == "Rate of Change"
    // Calculate the relative RoC for each asset - Standard
    rocBITO := ta.roc(BITO, rocPeriod) - (useRelative? avgROC : 0)         
    rocDBB  := ta.roc(DBB,  rocPeriod) - (useRelative? avgROC : 0)      
    rocDBC  := ta.roc(DBC,  rocPeriod) - (useRelative? avgROC : 0)      
    rocUDN  := ta.roc(UDN,  rocPeriod) - (useRelative? avgROC : 0)      
    rocGLD  := ta.roc(GLD,  rocPeriod) - (useRelative? avgROC : 0)      
    rocVIXM := ta.roc(VIXM, rocPeriod) - (useRelative? avgROC : 0)      
    rocUUP  := ta.roc(UUP,  rocPeriod) - (useRelative? avgROC : 0)      
    rocPFIX := ta.roc(PFIX, rocPeriod) - (useRelative? avgROC : 0)      
    rocUSO  := ta.roc(USO,  rocPeriod) - (useRelative? avgROC : 0)      
    rocDBP  := ta.roc(DBP,  rocPeriod) - (useRelative? avgROC : 0)            
    rocDBA  := ta.roc(DBA,  rocPeriod) - (useRelative? avgROC : 0)  

else if CalcType == "Sharpe Ratio"
    // Calculate the Sharpe ratio for each asset - optional
    rocBITO := f_sharpe(BITO, rocPeriod) - (useRelative? avgRoCMSH : 0)             
    rocDBB  := f_sharpe(DBB,  rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocDBC  := f_sharpe(DBC,  rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocUDN  := f_sharpe(UDN,  rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocGLD  := f_sharpe(GLD,  rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocVIXM := f_sharpe(VIXM, rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocUUP  := f_sharpe(UUP,  rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocPFIX := f_sharpe(PFIX, rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocUSO  := f_sharpe(USO,  rocPeriod) - (useRelative? avgRoCMSH : 0)          
    rocDBP  := f_sharpe(DBP,  rocPeriod) - (useRelative? avgRoCMSH : 0)                      
    rocDBA  := f_sharpe(DBA,  rocPeriod) - (useRelative? avgRoCMSH : 0)  

else if CalcType == "Sortino Ratio"
    // Calculate the Sortino ratio for each asset - optional
    rocBITO := f_sortino(BITO, rocPeriod) - (useRelative? avgRoCMSO : 0)              
    rocDBB  := f_sortino(DBB,  rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocDBC  := f_sortino(DBC,  rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocUDN  := f_sortino(UDN,  rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocGLD  := f_sortino(GLD,  rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocVIXM := f_sortino(VIXM, rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocUUP  := f_sortino(UUP,  rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocPFIX := f_sortino(PFIX, rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocUSO  := f_sortino(USO,  rocPeriod) - (useRelative? avgRoCMSO : 0)           
    rocDBP  := f_sortino(DBP,  rocPeriod) - (useRelative? avgRoCMSO : 0)                       
    rocDBA  := f_sortino(DBA,  rocPeriod) - (useRelative? avgRoCMSO : 0)  

else if CalcType == "Omega Ratio"
    // Calculate the Omega ratio for each asset - optional
    rocBITO := f_omega(BITO, rocPeriod) - (useRelative? avgRoCMO : 0)              
    rocDBB  := f_omega(DBB,  rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocDBC  := f_omega(DBC,  rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocUDN  := f_omega(UDN,  rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocGLD  := f_omega(GLD,  rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocVIXM := f_omega(VIXM, rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocUUP  := f_omega(UUP,  rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocPFIX := f_omega(PFIX, rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocUSO  := f_omega(USO,  rocPeriod) - (useRelative? avgRoCMO : 0)           
    rocDBP  := f_omega(DBP,  rocPeriod) - (useRelative? avgRoCMO : 0)                       
    rocDBA  := f_omega(DBA,  rocPeriod) - (useRelative? avgRoCMO : 0)  

else if CalcType == "Normalization"
    // Calculate the Normalization for each asset - optional
    rocBITO := f_normalization(BITO, rocPeriod) - (useRelative? avgRoCMNO : 0)              
    rocDBB  := f_normalization(DBB,  rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocDBC  := f_normalization(DBC,  rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocUDN  := f_normalization(UDN,  rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocGLD  := f_normalization(GLD,  rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocVIXM := f_normalization(VIXM, rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocUUP  := f_normalization(UUP,  rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocPFIX := f_normalization(PFIX, rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocUSO  := f_normalization(USO,  rocPeriod) - (useRelative? avgRoCMNO : 0)           
    rocDBP  := f_normalization(DBP,  rocPeriod) - (useRelative? avgRoCMNO : 0)                       
    rocDBA  := f_normalization(DBA,  rocPeriod) - (useRelative? avgRoCMNO : 0)  


// Calculate the probabilities
Goldilocks  = (rocBITO>0?+1:0) + (rocDBB>0?+1:0) + (rocDBC>0?+1:0)  + (rocUDN>0?+1:0) +(rocGLD>0?+1:0)  + (rocVIXM<0?+1:0) + (rocUUP<0?+1:0) + (rocPFIX<0?+1:0) + (rocUSO<0?+1:0) + (rocDBP<0?+1:0)
Reflation   = (rocBITO>0?+1:0) + (rocDBC>0?+1:0) + (rocUSO>0?+1:0)  + (rocDBB>0?+1:0) +(rocGLD>0?+1:0)  + (rocUUP<0?+1:0)  + (rocDBA<0?+1:0) + (rocUDN<0?+1:0)  + (rocDBP<0?+1:0) + (rocVIXM<0?+1:0)
Inflation   = (rocBITO>0?+1:0) + (rocGLD>0?+1:0) + (rocVIXM>0?+1:0) + (rocUUP>0?+1:0) +(rocPFIX>0?+1:0) + (rocDBB<0?+1:0)  + (rocUDN<0?+1:0) + (rocDBC<0?+1:0)  + (rocUSO<0?+1:0) + (rocDBP<0?+1:0) 
Deflation   = (rocUUP>0?+1:0)  + (rocGLD>0?+1:0) + (rocVIXM>0?+1:0) + (rocDBP>0?+1:0) +(rocPFIX>0?+1:0) + (rocBITO<0?+1:0) + (rocUDN<0?+1:0) + (rocDBC<0?+1:0)  + (rocUSO<0?+1:0) + (rocDBB<0?+1:0)
Denumerator =  Goldilocks + Reflation +  Inflation +  Deflation

Goldilocksx  = Goldilocks  + GoldilocksY
Reflationx   = Reflation   + ReflationY
Inflationx   = Inflation   + InflationY
Deflationx   = Deflation   + DeflationY
DenumeratorX = Goldilocksx + Reflationx +  Inflationx +  Deflationx
// Find the greatest value among the scenarios
maxValueX    = math.max(Goldilocksx, Reflationx, Inflationx, Deflationx)

// Determine the market scenario based on the greatest value
Riskx = ""
if maxValueX == Goldilocksx or maxValueX == Reflationx
    Riskx := "RISK ON"
else
    Riskx := "RISK OFF"

color regCol = na
if maxValueX == Goldilocksx
    regCol := color.new(color.green, 50)
else if maxValueX == Reflationx
    regCol := color.new(color.lime,  50)
else if maxValueX == Inflationx
    regCol := color.new(color.red,   50)
else if maxValueX == Deflationx
    regCol := color.new(color.blue,  50)

plot(colx?      Riskx == "RISK ON"? 1 : -1 : na )
bgcolor(colx?   Riskx == "RISK ON"? color.new(color.green, 60) : color.new(color.red, 60):na)
RiskColX     = (Riskx == "RISK ON"? color.green : color.red)
RiskBgx      = (Riskx == "RISK ON"? color.new(color.green, 40) : color.new(color.red, 40))
bgcolor(reg? regCol: na)





var string G2 = "🌌 Table Settings Performance 🌌"
string table_y_pos =  input.string(defval = "bottom", title = "Table Position",  options = ["top", "middle", "bottom"], group = G2, inline = "1")
string table_x_pos =  input.string(defval = "right",  title = "",                options = ["left", "center", "right"], group = G2, inline = "1")
string i_text_size  = input.string(defval=size.tiny,  title='Text Size:',        options = [size.tiny, size.small, size.normal, size.large, size.huge, size.auto], group = G2)
 
color positive_color_input = color(color.new(color.green, 0))
color negative_color_input = color(color.new(color.red, 0))

var table table = table.new(
     table_y_pos + "_" + table_x_pos, 
     columns = 10, 
     rows = 34, 
     frame_color = color.white,
     frame_width = 1, 
     border_color = color.white, 
     border_width = 1)

if showPerfTab
    table.merge_cells(table, 0, 0,  7,  0)
    table.merge_cells(table, 0, 1,  1,  1)
    table.merge_cells(table, 2, 1,  3,  1)
    table.merge_cells(table, 4, 1,  5,  1)
    table.merge_cells(table, 6, 1,  7,  1)
    table.merge_cells(table, 0, 2,  7,  2)
    table.merge_cells(table, 0, 8,  7,  8)
    table.merge_cells(table, 0, 16, 7, 16)
    table.merge_cells(table, 0, 23, 7, 23)
    table.merge_cells(table, 0, 29, 7, 29)
    table.merge_cells(table, 0, 33, 7, 33)

 // Definitions
if showPerfTab and barstate.islast
    table.cell(table, 0, 0,  text = "🌌 CE - Fixed Income and Macro "+str.tostring(rocPeriod)+"D 🌌", text_size = i_text_size, text_color = color.purple)
    table.cell(table, 0, 2,  text = "Top 5 Fixed Income Factors ",                                     text_size = i_text_size, text_color = color.green)
    table.cell(table, 0, 8,  text = "Bottom 5 Fixed Income Factors ",                                  text_size = i_text_size, text_color = color.red)    
    table.cell(table, 0, 16, text = "Top 5 Macro Factors",                                             text_size = i_text_size, text_color = color.green)    
    table.cell(table, 0, 23, text = "Bottom 5 Macro Factors",                                          text_size = i_text_size, text_color = color.red)    
    table.cell(table, 0, 29, text = "Risk Period: ",                                                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 0, 33, text = Riskx,                                                             text_size = i_text_size, text_color = color.white , bgcolor = RiskBgx, text_font_family = font.family_monospace)
  
 
    table.cell(table, 0, 1,"GOLDILOCKS",                         text_size = i_text_size, text_color = color.green)                                           
    table.cell(table, 2, 1,"REFLATION",                          text_size = i_text_size, text_color = color.lime)         
    table.cell(table, 4, 1,"INFLATION",                          text_size = i_text_size, text_color = color.red)          
    table.cell(table, 6, 1,"DEFLATION",                          text_size = i_text_size, text_color = color.blue)    

    // GOLDILOCKS *** Top 5 Fixed Income Factors    
    table.cell(table, 0, 3,"Convertibles (CWB)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 3,str.tostring(math.round(CWB_roc,2)),  text_size = i_text_size, text_color = CWB_roc  > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 4,"Leveraged Loans (BKLN)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 4,str.tostring(math.round(BKLN_roc,2)), text_size = i_text_size, text_color = BKLN_roc > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 5,"High Yield Credit (HYG)",            text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 5,str.tostring(math.round(HYG_roc,2)),  text_size = i_text_size, text_color = HYG_roc  > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 6,"Preferreds (PFF)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 6,str.tostring(math.round(PFF_roc,2)),  text_size = i_text_size, text_color = PFF_roc  > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 7,"Emerging Market US$ Bonds (EMB)",    text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 7,str.tostring(math.round(EMB_roc,2)),  text_size = i_text_size, text_color = EMB_roc  > 0 ?       positive_color_input : negative_color_input)
    // GOLDILOCKS *** Bottom 5 Fixed Income Factors 
    table.cell(table, 0, 9, "Long Bond (TLT)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 9,str.tostring(math.round(TLT_roc,2)),  text_size = i_text_size, text_color = TLT_roc  > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 10,"5-10yr Treasurys (IEF)",            text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 10,str.tostring(math.round(IEF_roc,2)), text_size = i_text_size, text_color = IEF_roc  > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 11,"5-10yr TIPS (TIP)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 11,str.tostring(math.round(TIP_roc,2)), text_size = i_text_size, text_color = TIP_roc  > 0 ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 12,"0-5yr TIPS (STIP)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 12,str.tostring(math.round(STIP_roc,2)),text_size = i_text_size, text_color = STIP_roc  > 0 ?      positive_color_input : negative_color_input)
    table.cell(table, 0, 13,"EM Local Currency Bonds (EMLC)",    text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 13,str.tostring(math.round(EMLC_roc,2)),text_size = i_text_size, text_color = EMLC_roc  > 0 ?      positive_color_input : negative_color_input)
         
    // REFLATION *** Top 5 Fixed Income Factors         
    table.cell(table, 2, 3,"Leveraged Loans (BKLN)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 3,str.tostring(math.round(BKLN_roc,2)), text_size = i_text_size, text_color = BKLN_roc   > 0?      positive_color_input : negative_color_input)
    table.cell(table, 2, 4,"Convertibles (CWB)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 4,str.tostring(math.round(CWB_roc,2)),  text_size = i_text_size, text_color = CWB_roc  > 0?        positive_color_input : negative_color_input)
    table.cell(table, 2, 5,"High Yield Credit (HYG)",            text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 5,str.tostring(math.round(HYG_roc,2)),  text_size = i_text_size, text_color = HYG_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 2, 6,"0-5yr TIPS (STIP)",                  text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 6,str.tostring(math.round(STIP_roc,2)), text_size = i_text_size, text_color = STIP_roc  > 0?       positive_color_input : negative_color_input)
    table.cell(table, 2, 7,"BDCs (BIZD)",                        text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 7,str.tostring(math.round(BIZD_roc,2)), text_size = i_text_size, text_color = BIZD_roc  > 0?       positive_color_input : negative_color_input)  
    // REFLATION *** Bottom 5 Fixed Income Factors      
    table.cell(table, 2, 9, "Long Bond (TLT)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 9,str.tostring(math.round(TLT_roc,2)),  text_size = i_text_size, text_color = TLT_roc  > 0?        positive_color_input : negative_color_input)
    table.cell(table, 2, 10,"5-10yr Treasurys (IEF)",            text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 10,str.tostring(math.round(IEF_roc,2)), text_size = i_text_size, text_color = IEF_roc  > 0?        positive_color_input : negative_color_input)
    table.cell(table, 2, 11,"Barclays Agg (AGG)",                text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 11,str.tostring(math.round(AGG_roc,2)), text_size = i_text_size, text_color = AGG_roc  > 0?        positive_color_input : negative_color_input)
    table.cell(table, 2, 12,"Investment Grade Credit (LQD)",     text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 12,str.tostring(math.round(LQD_roc,2)), text_size = i_text_size, text_color = LQD_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 2, 13,"MBS (MBB)",                         text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 13,str.tostring(math.round(MBB_roc,2)), text_size = i_text_size, text_color = MBB_roc > 0?         positive_color_input : negative_color_input)
         
    // INFLATION *** Top 5 Fixed Income Factors    
    table.cell(table, 4, 3,"1-3yr Treasurys (SHY)",              text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 3,str.tostring(math.round(SHY_roc,2)),  text_size = i_text_size, text_color = SHY_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 4, 4,"0-5yr TIPS (STIP)",                  text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 4,str.tostring(math.round(STIP_roc,2)), text_size = i_text_size, text_color = STIP_roc > 0?        positive_color_input : negative_color_input)
    table.cell(table, 4, 5,"5-10yr Treasurys (IEF)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 5,str.tostring(math.round(IEF_roc,2)),  text_size = i_text_size, text_color = IEF_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 4, 6,"5-10yr TIPS (TIP)",                  text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 6,str.tostring(math.round(TIP_roc,2)),  text_size = i_text_size, text_color = TIP_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 4, 7,"Long Bond (TLT)",                    text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 7,str.tostring(math.round(TLT_roc,2)),  text_size = i_text_size, text_color = TLT_roc > 0?         positive_color_input : negative_color_input)  
    // INFLATION *** Bottom 5 Fixed Income Factors   
    table.cell(table, 4, 9, "Convertibles (CWB)",                text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 9,str.tostring(math.round(CWB_roc,2)),  text_size = i_text_size, text_color = CWB_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 4, 10,"BDCs (BIZD)",                       text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 10,str.tostring(math.round(BIZD_roc,2)),text_size = i_text_size, text_color = BIZD_roc > 0?        positive_color_input : negative_color_input)
    table.cell(table, 4, 11,"EM Local Currency Bonds (EMLC)",    text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 11,str.tostring(math.round(EMLC_roc,2)),text_size = i_text_size, text_color = EMLC_roc > 0?        positive_color_input : negative_color_input)
    table.cell(table, 4, 12,"Preferreds (PFF)",                  text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 12,str.tostring(math.round(PFF_roc,2)), text_size = i_text_size, text_color = PFF_roc > 0?         positive_color_input : negative_color_input)  
    table.cell(table, 4, 13,"Investment Grade Credit (LQD)",     text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 13,str.tostring(math.round(LQD_roc,2)), text_size = i_text_size, text_color = LQD_roc > 0?         positive_color_input : negative_color_input)  
         
    // DEFLATION *** Top 5 Fixed Income Factors  
    table.cell(table, 6, 3,"1-3yr Treasurys (SHY)",              text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 3,str.tostring(math.round(SHY_roc,2)),  text_size = i_text_size, text_color = SHY_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 6, 4,"5-10yr Treasurys (IEF)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 4,str.tostring(math.round(IEF_roc,2)),  text_size = i_text_size, text_color = IEF_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 6, 5,"Barclays Agg (AGG)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 5,str.tostring(math.round(AGG_roc,2)),  text_size = i_text_size, text_color = AGG_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 6, 6,"MBS (MBB)",                          text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 6,str.tostring(math.round(MBB_roc,2)),  text_size = i_text_size, text_color = MBB_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 6, 7,"Investment Grade Credit (LQD)",      text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 7,str.tostring(math.round(LQD_roc,2)),  text_size = i_text_size, text_color = LQD_roc > 0?         positive_color_input : negative_color_input)
    // DEFLATION *** Bottom 5 Fixed Income Factors   
    table.cell(table, 6, 9, "Preferreds (PFF)",                  text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 9,str.tostring(math.round(PFF_roc,2)),  text_size = i_text_size, text_color = PFF_roc > 0?         positive_color_input : negative_color_input)
    table.cell(table, 6, 10,"BDCs (BIZD)",                       text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 10,str.tostring(math.round(BIZD_roc,2)),text_size = i_text_size, text_color = BIZD_roc > 0?        positive_color_input : negative_color_input)
    table.cell(table, 6, 11,"EM Local Currency Bonds (EMLC)",    text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 11,str.tostring(math.round(EMLC_roc,2)),text_size = i_text_size, text_color = EMLC_roc > 0?        positive_color_input : negative_color_input)
    table.cell(table, 6, 12,"High Yield Credit (HYG)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 12,str.tostring(math.round(HYG_roc,2)), text_size = i_text_size, text_color = HYG_roc > 0?         positive_color_input : negative_color_input)  
    table.cell(table, 6, 13,"Leveraged Loans (BKLN)",            text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 13,str.tostring(math.round(BKLN_roc,2)),text_size = i_text_size, text_color = BKLN_roc > 0?        positive_color_input : negative_color_input)  
           
    // ////   MACRO FACTORS
    // GOLDILOCKS *** Top 5 MACRO FACTORS    
    table.cell(table, 0, 17,"Bitcoin (BITO)",                    text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 17,str.tostring(math.round(rocBITO,2)), text_size = i_text_size, text_color = rocBITO   > 0  ?     positive_color_input : negative_color_input)
    table.cell(table, 0, 18,"Industrial Metals (DBB)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 18,str.tostring(math.round(rocDBB,2)),  text_size = i_text_size, text_color = rocDBB > 0  ?        positive_color_input : negative_color_input)
    table.cell(table, 0, 19,"Commodities (DBC)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 19,str.tostring(math.round(rocDBC,2)),  text_size = i_text_size, text_color = rocDBC  > 0  ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 21,"Inverse US Dollar (UDN)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 21,str.tostring(math.round(rocUDN,2)),  text_size = i_text_size, text_color = rocUDN  > 0  ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 22,"Gold (GLD)",                        text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 22,str.tostring(math.round(rocGLD,2)),  text_size = i_text_size, text_color = rocGLD  > 0  ?       positive_color_input : negative_color_input)
    // GOLDILOCKS *** Bottom 5 MACRO FACTORS 
    table.cell(table, 0, 24, "Equity Volatility (VIXM)",         text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 24,str.tostring(math.round(rocVIXM,2)), text_size = i_text_size, text_color = rocVIXM  > 0  ?      positive_color_input : negative_color_input)
    table.cell(table, 0, 25,"US Dollar (UUP)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 25,str.tostring(math.round(rocUUP,2)),  text_size = i_text_size, text_color = rocUUP  > 0  ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 26,"Interest Rate Volatility (PFIX)",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 26,str.tostring(math.round(rocPFIX,2)), text_size = i_text_size, text_color = rocPFIX  > 0  ?      positive_color_input : negative_color_input)
    table.cell(table, 0, 27,"Energy (USO)",                      text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 27,str.tostring(math.round(rocUSO,2)),  text_size = i_text_size, text_color = rocUSO  > 0  ?       positive_color_input : negative_color_input)
    table.cell(table, 0, 28,"Precious Metals (DBP)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 28,str.tostring(math.round(rocDBP,2)),  text_size = i_text_size, text_color = rocDBP  > 0  ?       positive_color_input : negative_color_input)
         
    // REFLATION *** Top 5 MACRO FACTORS         
    table.cell(table, 2, 17,"Bitcoin (BITO)",                    text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 17,str.tostring(math.round(rocBITO,2)), text_size = i_text_size, text_color = rocBITO   > 0 ?      positive_color_input : negative_color_input)
    table.cell(table, 2, 18,"Commodities (DBC)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 18,str.tostring(math.round(rocDBC,2)),  text_size = i_text_size, text_color = rocDBC  > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 2, 19,"Energy (USO)",                      text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 19,str.tostring(math.round(rocUSO,2)),  text_size = i_text_size, text_color = rocUSO > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 2, 21,"Industrial Metals (DBB)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 21,str.tostring(math.round(rocDBB,2)),  text_size = i_text_size, text_color = rocDBB  > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 2, 22,"Gold (GLD)",                        text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 22,str.tostring(math.round(rocGLD,2)),  text_size = i_text_size, text_color = rocGLD  > 0 ?        positive_color_input : negative_color_input)  
    // REFLATION *** Bottom 5 MACRO FACTORS      
    table.cell(table, 2, 24,"US Dollar (UUP)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 24,str.tostring(math.round(rocUUP,2)),  text_size = i_text_size, text_color = rocUUP  > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 2, 25,"Agriculture (DBA)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 25,str.tostring(math.round(rocDBA,2)),  text_size = i_text_size, text_color = rocDBA  > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 2, 26,"Inverse US Dollar (UDN)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 26,str.tostring(math.round(rocUDN,2)),  text_size = i_text_size, text_color = rocUDN  > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 2, 27,"Precious Metals (DBP)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 27,str.tostring(math.round(rocDBP,2)),  text_size = i_text_size, text_color = rocDBP > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 2, 28,"Equity Volatility (VIXM)",          text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 28,str.tostring(math.round(rocVIXM,2)), text_size = i_text_size, text_color = rocVIXM > 0 ?        positive_color_input : negative_color_input)

    // INFLATION *** Top 5 MACRO FACTORS    
    table.cell(table, 4, 17,"Bitcoin (BITO)",                    text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 17,str.tostring(math.round(rocBITO,2)), text_size = i_text_size, text_color = rocBITO > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 4, 18,"Gold (GLD)",                        text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 18,str.tostring(math.round(rocGLD,2)),  text_size = i_text_size, text_color = rocGLD > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 4, 19,"Equity Volatility (VIXM)",          text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 19,str.tostring(math.round(rocVIXM,2)), text_size = i_text_size, text_color = rocVIXM > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 4, 21,"US Dollar (UUP)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 21,str.tostring(math.round(rocUUP,2)),  text_size = i_text_size, text_color = rocUUP > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 4, 22,"Interest Rate Volatility (PFIX)",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 22,str.tostring(math.round(rocPFIX,2)), text_size = i_text_size, text_color = rocPFIX > 0 ?        positive_color_input : negative_color_input)  
    // INFLATION *** Bottom 5 MACRO FACTORS   
    table.cell(table, 4, 24, "Industrial Metals (DBB)",          text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 24,str.tostring(math.round(rocDBB,2)),  text_size = i_text_size, text_color = rocDBB > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 4, 25,"Inverse US Dollar (UDN)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 25,str.tostring(math.round(rocUDN,2)),  text_size = i_text_size, text_color = rocUDN > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 4, 26,"Commodities (DBC)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 26,str.tostring(math.round(rocDBC,2)),  text_size = i_text_size, text_color = rocDBC > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 4, 27,"Energy (USO)",                      text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 27,str.tostring(math.round(rocUSO,2)),  text_size = i_text_size, text_color = rocUSO > 0 ?         positive_color_input : negative_color_input)  
    table.cell(table, 4, 28,"Precious Metals (DBP)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 28,str.tostring(math.round(rocDBP,2)),  text_size = i_text_size, text_color = rocDBP > 0 ?         positive_color_input : negative_color_input)  

    // DEFLATION *** Top 5 MACRO FACTORS  
    table.cell(table, 6, 17,"US Dollar (UUP)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 17,str.tostring(math.round(rocUUP,2)),  text_size = i_text_size, text_color = rocUUP > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 6, 18,"Gold (GLD)",                        text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 18,str.tostring(math.round(rocGLD,2)),  text_size = i_text_size, text_color = rocGLD > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 6, 19,"Equity Volatility (VIXM)",          text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 19,str.tostring(math.round(rocVIXM,2)), text_size = i_text_size, text_color = rocVIXM > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 6, 21,"Precious Metals (DBP)",             text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 21,str.tostring(math.round(rocDBP,2)),  text_size = i_text_size, text_color = rocDBP > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 6, 22,"Interest Rate Volatility (PFIX)",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 22,str.tostring(math.round(rocPFIX,2)), text_size = i_text_size, text_color = rocPFIX > 0 ?        positive_color_input : negative_color_input)
    // DEFLATION *** Bottom 5 MACRO FACTORS   
    table.cell(table, 6, 24, "Bitcoin (BITO)",                   text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 24,str.tostring(math.round(rocBITO,2)), text_size = i_text_size, text_color = rocBITO > 0 ?        positive_color_input : negative_color_input)
    table.cell(table, 6, 25,"Inverse US Dollar (UDN)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 25,str.tostring(math.round(rocUDN,2)),  text_size = i_text_size, text_color = rocUDN > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 6, 26,"Commodities (DBC)",                 text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 26,str.tostring(math.round(rocDBC,2)),  text_size = i_text_size, text_color = rocDBC > 0 ?         positive_color_input : negative_color_input)
    table.cell(table, 6, 27,"Energy (USO)",                      text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 27,str.tostring(math.round(rocUSO,2)),  text_size = i_text_size, text_color = rocUSO > 0 ?         positive_color_input : negative_color_input)  
    table.cell(table, 6, 28,"Industrial Metals (DBB)",           text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 28,str.tostring(math.round(rocDBB,2)),  text_size = i_text_size, text_color = rocDBB > 0 ?         positive_color_input : negative_color_input)  

    table.cell(table, 0, 32, text = "Goldilocksx Probability: ",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 1, 32,str.tostring(math.round(Goldilocksx/DenumeratorX*100, 2))+"% | "+str.tostring(Goldilocksx)+ " / 20",text_size = i_text_size, text_color = RiskColX)
    table.cell(table, 2, 32, text = "Reflation Probability: ",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 3, 32,str.tostring(math.round(Reflationx/DenumeratorX*100, 2))+"% | "+str.tostring(Reflationx)+ " / 20",  text_size = i_text_size, text_color = RiskColX)
    table.cell(table, 4, 32, text = "Inflation Probability: ",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 5, 32,str.tostring(math.round(Inflationx/DenumeratorX*100, 2))+"% | "+str.tostring(Inflationx)+ " / 20",  text_size = i_text_size, text_color = RiskColX)
    table.cell(table, 6, 32, text = "Deflation Probability: ",   text_size = i_text_size, text_color = color.white)
    table.cell(table, 7, 32,str.tostring(math.round(Deflationx/DenumeratorX*100, 2))+"% | "+str.tostring(Deflationx)+ " / 20",  text_size = i_text_size, text_color = RiskColX)



// SOME FUN SHIT DOWN HERE

RiskULTIMATE = ""
color regColULTIMATE = na


if ultimateGRID or ultimateRISK
    // Calculate the relative RoC for each asset - 
    CWB_RoC  = ta.roc(CWB , rocPeriod) - (useRelative? avgROCFI : 0)   
    BKLN_RoC = ta.roc(BKLN, rocPeriod) - (useRelative? avgROCFI : 0)
    HYG_RoC  = ta.roc(HYG,  rocPeriod) - (useRelative? avgROCFI : 0)    
    PFF_RoC  = ta.roc(PFF,  rocPeriod) - (useRelative? avgROCFI : 0)    
    EMB_RoC  = ta.roc(EMB,  rocPeriod) - (useRelative? avgROCFI : 0)    
    TLT_RoC  = ta.roc(TLT,  rocPeriod) - (useRelative? avgROCFI : 0)    
    IEF_RoC  = ta.roc(IEF,  rocPeriod) - (useRelative? avgROCFI : 0)    
    TIP_RoC  = ta.roc(TIP,  rocPeriod) - (useRelative? avgROCFI : 0)    
    STIP_RoC = ta.roc(STIP, rocPeriod) - (useRelative? avgROCFI : 0)
    EMLC_RoC = ta.roc(EMLC, rocPeriod) - (useRelative? avgROCFI : 0)
    BIZD_RoC = ta.roc(BIZD, rocPeriod) - (useRelative? avgROCFI : 0)
    AGG_RoC  = ta.roc(AGG,  rocPeriod) - (useRelative? avgROCFI : 0)    
    LQD_RoC  = ta.roc(LQD,  rocPeriod) - (useRelative? avgROCFI : 0)    
    SHY_RoC  = ta.roc(SHY,  rocPeriod) - (useRelative? avgROCFI : 0) 
    MBB_RoC  = ta.roc(MBB,  rocPeriod) - (useRelative? avgROCFI : 0)    

    // Calculate the Sharpe ratio for each asset - 
    CWB_Sharpe  = f_sharpe(CWB , rocPeriod) - (useRelative? avgRoCFISH : 0)      
    BKLN_Sharpe = f_sharpe(BKLN, rocPeriod) - (useRelative? avgRoCFISH : 0)  
    HYG_Sharpe  = f_sharpe(HYG,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    PFF_Sharpe  = f_sharpe(PFF,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    EMB_Sharpe  = f_sharpe(EMB,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    TLT_Sharpe  = f_sharpe(TLT,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    IEF_Sharpe  = f_sharpe(IEF,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    TIP_Sharpe  = f_sharpe(TIP,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    STIP_Sharpe = f_sharpe(STIP, rocPeriod) - (useRelative? avgRoCFISH : 0)  
    EMLC_Sharpe = f_sharpe(EMLC, rocPeriod) - (useRelative? avgRoCFISH : 0)  
    BIZD_Sharpe = f_sharpe(BIZD, rocPeriod) - (useRelative? avgRoCFISH : 0)  
    AGG_Sharpe  = f_sharpe(AGG,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    LQD_Sharpe  = f_sharpe(LQD,  rocPeriod) - (useRelative? avgRoCFISH : 0)      
    SHY_Sharpe  = f_sharpe(SHY,  rocPeriod) - (useRelative? avgRoCFISH : 0)  
    MBB_Sharpe  = f_sharpe(MBB,  rocPeriod) - (useRelative? avgRoCFISH : 0)      

    // Calculate the Sortino ratio for each asset - 
    CWB_Sortino  = f_sortino(CWB , rocPeriod) - (useRelative? avgRoCFISO : 0)            
    BKLN_Sortino = f_sortino(BKLN, rocPeriod) - (useRelative? avgRoCFISO : 0)    
    HYG_Sortino  = f_sortino(HYG,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    PFF_Sortino  = f_sortino(PFF,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    EMB_Sortino  = f_sortino(EMB,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    TLT_Sortino  = f_sortino(TLT,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    IEF_Sortino  = f_sortino(IEF,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    TIP_Sortino  = f_sortino(TIP,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    STIP_Sortino = f_sortino(STIP, rocPeriod) - (useRelative? avgRoCFISO : 0)    
    EMLC_Sortino = f_sortino(EMLC, rocPeriod) - (useRelative? avgRoCFISO : 0)    
    BIZD_Sortino = f_sortino(BIZD, rocPeriod) - (useRelative? avgRoCFISO : 0)    
    AGG_Sortino  = f_sortino(AGG,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    LQD_Sortino  = f_sortino(LQD,  rocPeriod) - (useRelative? avgRoCFISO : 0)            
    SHY_Sortino  = f_sortino(SHY,  rocPeriod) - (useRelative? avgRoCFISO : 0)    
    MBB_Sortino  = f_sortino(MBB,  rocPeriod) - (useRelative? avgRoCFISO : 0)            

    // Calculate the Omega ratio for each asset - 
    CWB_Omega  = f_omega(CWB , rocPeriod) - (useRelative? avgRoCFIO : 0)         
    BKLN_Omega = f_omega(BKLN, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    HYG_Omega  = f_omega(HYG,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    PFF_Omega  = f_omega(PFF,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    EMB_Omega  = f_omega(EMB,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    TLT_Omega  = f_omega(TLT,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    IEF_Omega  = f_omega(IEF,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    TIP_Omega  = f_omega(TIP,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    STIP_Omega = f_omega(STIP, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    EMLC_Omega = f_omega(EMLC, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    BIZD_Omega = f_omega(BIZD, rocPeriod) - (useRelative? avgRoCFIO : 0)      
    AGG_Omega  = f_omega(AGG,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    LQD_Omega  = f_omega(LQD,  rocPeriod) - (useRelative? avgRoCFIO : 0)         
    SHY_Omega  = f_omega(SHY,  rocPeriod) - (useRelative? avgRoCFIO : 0)      
    MBB_Omega  = f_omega(MBB,  rocPeriod) - (useRelative? avgRoCFIO : 0)         

    // Calculate the Normalization for each asset - 
    CWB_Normal  = f_normalization(CWB , rocPeriod) - (useRelative? avgRoCFINO : 0)      
    BKLN_Normal = f_normalization(BKLN, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    HYG_Normal  = f_normalization(HYG,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    PFF_Normal  = f_normalization(PFF,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    EMB_Normal  = f_normalization(EMB,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    TLT_Normal  = f_normalization(TLT,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    IEF_Normal  = f_normalization(IEF,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    TIP_Normal  = f_normalization(TIP,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    STIP_Normal = f_normalization(STIP, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    EMLC_Normal = f_normalization(EMLC, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    BIZD_Normal = f_normalization(BIZD, rocPeriod) - (useRelative? avgRoCFINO : 0)  
    AGG_Normal  = f_normalization(AGG,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    LQD_Normal  = f_normalization(LQD,  rocPeriod) - (useRelative? avgRoCFINO : 0)      
    SHY_Normal  = f_normalization(SHY,  rocPeriod) - (useRelative? avgRoCFINO : 0)  
    MBB_Normal  = f_normalization(MBB,  rocPeriod) - (useRelative? avgRoCFINO : 0)      


    // Calculate the probabilities for Fixed Income RoC
    GoldilocksFIroc  = (CWB_RoC >0?+1:0) + (BKLN_RoC>0?+1:0) + (HYG_RoC>0?+1:0) + (PFF_RoC  >0?+1:0) + (EMB_RoC >0?+1:0) + (TLT_RoC<0?+1:0) + (IEF_RoC <0?+1:0) + (TIP_RoC <0?+1:0) + (STIP_RoC<0?+1:0) + (EMLC_RoC<0?+1:0)
    ReflationFIroc   = (BKLN_RoC>0?+1:0) + (CWB_RoC >0?+1:0) + (HYG_RoC>0?+1:0) + (STIP_RoC >0?+1:0) + (BIZD_RoC>0?+1:0) + (TLT_RoC<0?+1:0) + (IEF_RoC <0?+1:0) + (AGG_RoC <0?+1:0) + (LQD_RoC <0?+1:0) + (MBB_RoC <0?+1:0)
    InflationFIroc   = (SHY_RoC >0?+1:0) + (STIP_RoC>0?+1:0) + (IEF_RoC>0?+1:0) + (TIP_RoC  >0?+1:0) + (TLT_RoC >0?+1:0) + (CWB_RoC<0?+1:0) + (BIZD_RoC<0?+1:0) + (EMLC_RoC<0?+1:0) + (PFF_RoC <0?+1:0) + (LQD_RoC <0?+1:0) 
    DeflationFIroc   = (SHY_RoC >0?+1:0) + (IEF_RoC >0?+1:0) + (AGG_RoC>0?+1:0) + (MBB_RoC  >0?+1:0) + (LQD_RoC >0?+1:0) + (PFF_RoC<0?+1:0) + (BIZD_RoC<0?+1:0) + (EMLC_RoC<0?+1:0) + (HYG_RoC <0?+1:0) + (BKLN_RoC<0?+1:0)
    DenumeratorFIroc =  GoldilocksFIroc + ReflationFIroc +  InflationFIroc +  DeflationFIroc

    // Calculate the probabilities for Fixed Income Sharpe
    GoldilocksFISharpe  = (CWB_Sharpe >0?+1:0) + (BKLN_Sharpe>0?+1:0) + (HYG_Sharpe>0?+1:0) + (PFF_Sharpe  >0?+1:0) + (EMB_Sharpe >0?+1:0) + (TLT_Sharpe<0?+1:0) + (IEF_Sharpe <0?+1:0) + (TIP_Sharpe <0?+1:0) + (STIP_Sharpe<0?+1:0) + (EMLC_Sharpe<0?+1:0)
    ReflationFISharpe   = (BKLN_Sharpe>0?+1:0) + (CWB_Sharpe >0?+1:0) + (HYG_Sharpe>0?+1:0) + (STIP_Sharpe >0?+1:0) + (BIZD_Sharpe>0?+1:0) + (TLT_Sharpe<0?+1:0) + (IEF_Sharpe <0?+1:0) + (AGG_Sharpe <0?+1:0) + (LQD_Sharpe <0?+1:0) + (MBB_Sharpe <0?+1:0)
    InflationFISharpe   = (SHY_Sharpe >0?+1:0) + (STIP_Sharpe>0?+1:0) + (IEF_Sharpe>0?+1:0) + (TIP_Sharpe  >0?+1:0) + (TLT_Sharpe >0?+1:0) + (CWB_Sharpe<0?+1:0) + (BIZD_Sharpe<0?+1:0) + (EMLC_Sharpe<0?+1:0) + (PFF_Sharpe <0?+1:0) + (LQD_Sharpe <0?+1:0) 
    DeflationFISharpe   = (SHY_Sharpe >0?+1:0) + (IEF_Sharpe >0?+1:0) + (AGG_Sharpe>0?+1:0) + (MBB_Sharpe  >0?+1:0) + (LQD_Sharpe >0?+1:0) + (PFF_Sharpe<0?+1:0) + (BIZD_Sharpe<0?+1:0) + (EMLC_Sharpe<0?+1:0) + (HYG_Sharpe <0?+1:0) + (BKLN_Sharpe<0?+1:0)
    DenumeratorFISharpe =  GoldilocksFISharpe + ReflationFISharpe +  InflationFISharpe +  DeflationFISharpe

    // Calculate the probabilities for Fixed Income Sortino
    GoldilocksFISortino  = (CWB_Sortino >0?+1:0) + (BKLN_Sortino>0?+1:0) + (HYG_Sortino>0?+1:0) + (PFF_Sortino  >0?+1:0) + (EMB_Sortino >0?+1:0) + (TLT_Sortino<0?+1:0) + (IEF_Sortino <0?+1:0) + (TIP_Sortino <0?+1:0) + (STIP_Sortino<0?+1:0) + (EMLC_Sortino<0?+1:0)
    ReflationFISortino   = (BKLN_Sortino>0?+1:0) + (CWB_Sortino >0?+1:0) + (HYG_Sortino>0?+1:0) + (STIP_Sortino >0?+1:0) + (BIZD_Sortino>0?+1:0) + (TLT_Sortino<0?+1:0) + (IEF_Sortino <0?+1:0) + (AGG_Sortino <0?+1:0) + (LQD_Sortino <0?+1:0) + (MBB_Sortino <0?+1:0)
    InflationFISortino   = (SHY_Sortino >0?+1:0) + (STIP_Sortino>0?+1:0) + (IEF_Sortino>0?+1:0) + (TIP_Sortino  >0?+1:0) + (TLT_Sortino >0?+1:0) + (CWB_Sortino<0?+1:0) + (BIZD_Sortino<0?+1:0) + (EMLC_Sortino<0?+1:0) + (PFF_Sortino <0?+1:0) + (LQD_Sortino <0?+1:0) 
    DeflationFISortino   = (SHY_Sortino >0?+1:0) + (IEF_Sortino >0?+1:0) + (AGG_Sortino>0?+1:0) + (MBB_Sortino  >0?+1:0) + (LQD_Sortino >0?+1:0) + (PFF_Sortino<0?+1:0) + (BIZD_Sortino<0?+1:0) + (EMLC_Sortino<0?+1:0) + (HYG_Sortino <0?+1:0) + (BKLN_Sortino<0?+1:0)
    DenumeratorFISortino =  GoldilocksFISortino + ReflationFISortino +  InflationFISortino +  DeflationFISortino

    // Calculate the probabilities for Fixed Income Omega
    GoldilocksFIOmega  = (CWB_Omega >0?+1:0) + (BKLN_Omega>0?+1:0) + (HYG_Omega>0?+1:0) + (PFF_Omega  >0?+1:0) + (EMB_Omega >0?+1:0) + (TLT_Omega<0?+1:0) + (IEF_Omega <0?+1:0) + (TIP_Omega <0?+1:0) + (STIP_Omega<0?+1:0) + (EMLC_Omega<0?+1:0)
    ReflationFIOmega   = (BKLN_Omega>0?+1:0) + (CWB_Omega >0?+1:0) + (HYG_Omega>0?+1:0) + (STIP_Omega >0?+1:0) + (BIZD_Omega>0?+1:0) + (TLT_Omega<0?+1:0) + (IEF_Omega <0?+1:0) + (AGG_Omega <0?+1:0) + (LQD_Omega <0?+1:0) + (MBB_Omega <0?+1:0)
    InflationFIOmega   = (SHY_Omega >0?+1:0) + (STIP_Omega>0?+1:0) + (IEF_Omega>0?+1:0) + (TIP_Omega  >0?+1:0) + (TLT_Omega >0?+1:0) + (CWB_Omega<0?+1:0) + (BIZD_Omega<0?+1:0) + (EMLC_Omega<0?+1:0) + (PFF_Omega <0?+1:0) + (LQD_Omega <0?+1:0) 
    DeflationFIOmega   = (SHY_Omega >0?+1:0) + (IEF_Omega >0?+1:0) + (AGG_Omega>0?+1:0) + (MBB_Omega  >0?+1:0) + (LQD_Omega >0?+1:0) + (PFF_Omega<0?+1:0) + (BIZD_Omega<0?+1:0) + (EMLC_Omega<0?+1:0) + (HYG_Omega <0?+1:0) + (BKLN_Omega<0?+1:0)
    DenumeratorFIOmega =  GoldilocksFIOmega + ReflationFIOmega +  InflationFIOmega +  DeflationFIOmega

    // Calculate the probabilities for Fixed Income Normalization
    GoldilocksFINormal  = (CWB_Normal >0?+1:0) + (BKLN_Normal>0?+1:0) + (HYG_Normal>0?+1:0) + (PFF_Normal  >0?+1:0) + (EMB_Normal >0?+1:0) + (TLT_Normal<0?+1:0) + (IEF_Normal <0?+1:0) + (TIP_Normal <0?+1:0) + (STIP_Normal<0?+1:0) + (EMLC_Normal<0?+1:0)
    ReflationFINormal   = (BKLN_Normal>0?+1:0) + (CWB_Normal >0?+1:0) + (HYG_Normal>0?+1:0) + (STIP_Normal >0?+1:0) + (BIZD_Normal>0?+1:0) + (TLT_Normal<0?+1:0) + (IEF_Normal <0?+1:0) + (AGG_Normal <0?+1:0) + (LQD_Normal <0?+1:0) + (MBB_Normal <0?+1:0)
    InflationFINormal   = (SHY_Normal >0?+1:0) + (STIP_Normal>0?+1:0) + (IEF_Normal>0?+1:0) + (TIP_Normal  >0?+1:0) + (TLT_Normal >0?+1:0) + (CWB_Normal<0?+1:0) + (BIZD_Normal<0?+1:0) + (EMLC_Normal<0?+1:0) + (PFF_Normal <0?+1:0) + (LQD_Normal <0?+1:0) 
    DeflationFINormal   = (SHY_Normal >0?+1:0) + (IEF_Normal >0?+1:0) + (AGG_Normal>0?+1:0) + (MBB_Normal  >0?+1:0) + (LQD_Normal >0?+1:0) + (PFF_Normal<0?+1:0) + (BIZD_Normal<0?+1:0) + (EMLC_Normal<0?+1:0) + (HYG_Normal <0?+1:0) + (BKLN_Normal<0?+1:0)
    DenumeratorFINormal =  GoldilocksFINormal + ReflationFINormal +  InflationFINormal +  DeflationFINormal






    // Calculate the relative RoC for each asset - 
    RoCBITO = ta.roc(BITO, rocPeriod) - (useRelative? avgROC : 0)  
    RoCDBB  = ta.roc(DBB,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCDBC  = ta.roc(DBC,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCUDN  = ta.roc(UDN,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCGLD  = ta.roc(GLD,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCVIXM = ta.roc(VIXM, rocPeriod) - (useRelative? avgROC : 0)  
    RoCUUP  = ta.roc(UUP,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCPFIX = ta.roc(PFIX, rocPeriod) - (useRelative? avgROC : 0)  
    RoCUSO  = ta.roc(USO,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCDBP  = ta.roc(DBP,  rocPeriod) - (useRelative? avgROC : 0)  
    RoCDBA  = ta.roc(DBA,  rocPeriod) - (useRelative? avgROC : 0)  


    // Calculate the Sharpe ratio for each asset - 
    SharpeBITO = f_sharpe(BITO, rocPeriod)  - (useRelative? avgRoCMSH : 0)                  
    SharpeDBB  = f_sharpe(DBB,  rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeDBC  = f_sharpe(DBC,  rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeUDN  = f_sharpe(UDN,  rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeGLD  = f_sharpe(GLD,  rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeVIXM = f_sharpe(VIXM, rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeUUP  = f_sharpe(UUP,  rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpePFIX = f_sharpe(PFIX, rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeUSO  = f_sharpe(USO,  rocPeriod)  - (useRelative? avgRoCMSH : 0)               
    SharpeDBP  = f_sharpe(DBP,  rocPeriod)  - (useRelative? avgRoCMSH : 0)                                 
    SharpeDBA  = f_sharpe(DBA,  rocPeriod)  - (useRelative? avgRoCMSH : 0)  


    // Calculate the Sortino ratio for each asset - 
    SortinoBITO = f_sortino(BITO, rocPeriod) - (useRelative? avgRoCMSO : 0)                   
    SortinoDBB  = f_sortino(DBB,  rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoDBC  = f_sortino(DBC,  rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoUDN  = f_sortino(UDN,  rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoGLD  = f_sortino(GLD,  rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoVIXM = f_sortino(VIXM, rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoUUP  = f_sortino(UUP,  rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoPFIX = f_sortino(PFIX, rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoUSO  = f_sortino(USO,  rocPeriod) - (useRelative? avgRoCMSO : 0)                
    SortinoDBP  = f_sortino(DBP,  rocPeriod) - (useRelative? avgRoCMSO : 0)                                  
    SortinoDBA  = f_sortino(DBA,  rocPeriod) - (useRelative? avgRoCMSO : 0)  


    // Calculate the Omega ratio for each asset - optional
    OmegaBITO = f_omega(BITO, rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaDBB  = f_omega(DBB,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaDBC  = f_omega(DBC,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaUDN  = f_omega(UDN,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaGLD  = f_omega(GLD,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaVIXM = f_omega(VIXM, rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaUUP  = f_omega(UUP,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaPFIX = f_omega(PFIX, rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaUSO  = f_omega(USO,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaDBP  = f_omega(DBP,  rocPeriod) - (useRelative? avgRoCMO : 0)  
    OmegaDBA  = f_omega(DBA,  rocPeriod) - (useRelative? avgRoCMO : 0)  


    // Calculate the Normalization for each asset - optional
    NormalBITO = f_normalization(BITO, rocPeriod) - (useRelative? avgRoCMNO : 0)                   
    NormalDBB  = f_normalization(DBB,  rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalDBC  = f_normalization(DBC,  rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalUDN  = f_normalization(UDN,  rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalGLD  = f_normalization(GLD,  rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalVIXM = f_normalization(VIXM, rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalUUP  = f_normalization(UUP,  rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalPFIX = f_normalization(PFIX, rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalUSO  = f_normalization(USO,  rocPeriod) - (useRelative? avgRoCMNO : 0)                
    NormalDBP  = f_normalization(DBP,  rocPeriod) - (useRelative? avgRoCMNO : 0)                                  
    NormalDBA  = f_normalization(DBA,  rocPeriod) - (useRelative? avgRoCMNO : 0)  


    // Calculate the probabilities Macro RoC
    GoldilocksMroc  = (RoCBITO>0?+1:0) + (RoCDBB>0?+1:0) + (RoCDBC>0?+1:0)  + (RoCUDN>0?+1:0) +(RoCGLD>0?+1:0)  + (RoCVIXM<0?+1:0) + (RoCUUP<0?+1:0) + (RoCPFIX<0?+1:0) + (RoCUSO<0?+1:0) + (RoCDBP<0?+1:0)
    ReflationMroc   = (RoCBITO>0?+1:0) + (RoCDBC>0?+1:0) + (RoCUSO>0?+1:0)  + (RoCDBB>0?+1:0) +(RoCGLD>0?+1:0)  + (RoCUUP<0?+1:0)  + (RoCDBA<0?+1:0) + (RoCUDN<0?+1:0)  + (RoCDBP<0?+1:0) + (RoCVIXM<0?+1:0)
    InflationMroc   = (RoCBITO>0?+1:0) + (RoCGLD>0?+1:0) + (RoCVIXM>0?+1:0) + (RoCUUP>0?+1:0) +(RoCPFIX>0?+1:0) + (RoCDBB<0?+1:0)  + (RoCUDN<0?+1:0) + (RoCDBC<0?+1:0)  + (RoCUSO<0?+1:0) + (RoCDBP<0?+1:0) 
    DeflationMroc   = (RoCUUP>0?+1:0)  + (RoCGLD>0?+1:0) + (RoCVIXM>0?+1:0) + (RoCDBP>0?+1:0) +(RoCPFIX>0?+1:0) + (RoCBITO<0?+1:0) + (RoCUDN<0?+1:0) + (RoCDBC<0?+1:0)  + (RoCUSO<0?+1:0) + (RoCDBB<0?+1:0)
    DenumeratorMroc =  GoldilocksMroc + ReflationMroc +  InflationMroc +  DeflationMroc

    // Calculate the probabilities Macro Sharpe
    GoldilocksMSharpe  = (SharpeBITO>0?+1:0) + (SharpeDBB>0?+1:0) + (SharpeDBC>0?+1:0)  + (SharpeUDN>0?+1:0) +(SharpeGLD>0?+1:0)  + (SharpeVIXM<0?+1:0) + (SharpeUUP<0?+1:0) + (SharpePFIX<0?+1:0) + (SharpeUSO<0?+1:0) + (SharpeDBP<0?+1:0)
    ReflationMSharpe   = (SharpeBITO>0?+1:0) + (SharpeDBC>0?+1:0) + (SharpeUSO>0?+1:0)  + (SharpeDBB>0?+1:0) +(SharpeGLD>0?+1:0)  + (SharpeUUP<0?+1:0)  + (SharpeDBA<0?+1:0) + (SharpeUDN<0?+1:0)  + (SharpeDBP<0?+1:0) + (SharpeVIXM<0?+1:0)
    InflationMSharpe   = (SharpeBITO>0?+1:0) + (SharpeGLD>0?+1:0) + (SharpeVIXM>0?+1:0) + (SharpeUUP>0?+1:0) +(SharpePFIX>0?+1:0) + (SharpeDBB<0?+1:0)  + (SharpeUDN<0?+1:0) + (SharpeDBC<0?+1:0)  + (SharpeUSO<0?+1:0) + (SharpeDBP<0?+1:0) 
    DeflationMSharpe   = (SharpeUUP>0?+1:0)  + (SharpeGLD>0?+1:0) + (SharpeVIXM>0?+1:0) + (SharpeDBP>0?+1:0) +(SharpePFIX>0?+1:0) + (SharpeBITO<0?+1:0) + (SharpeUDN<0?+1:0) + (SharpeDBC<0?+1:0)  + (SharpeUSO<0?+1:0) + (SharpeDBB<0?+1:0)
    DenumeratorMSharpe =  GoldilocksMSharpe + ReflationMSharpe +  InflationMSharpe +  DeflationMSharpe

    // Calculate the probabilities Macro Sortino
    GoldilocksMSortino  = (SortinoBITO>0?+1:0) + (SortinoDBB>0?+1:0) + (SortinoDBC>0?+1:0)  + (SortinoUDN>0?+1:0) +(SortinoGLD>0?+1:0)  + (SortinoVIXM<0?+1:0) + (SortinoUUP<0?+1:0) + (SortinoPFIX<0?+1:0) + (SortinoUSO<0?+1:0) + (SortinoDBP<0?+1:0)
    ReflationMSortino   = (SortinoBITO>0?+1:0) + (SortinoDBC>0?+1:0) + (SortinoUSO>0?+1:0)  + (SortinoDBB>0?+1:0) +(SortinoGLD>0?+1:0)  + (SortinoUUP<0?+1:0)  + (SortinoDBA<0?+1:0) + (SortinoUDN<0?+1:0)  + (SortinoDBP<0?+1:0) + (SortinoVIXM<0?+1:0)
    InflationMSortino   = (SortinoBITO>0?+1:0) + (SortinoGLD>0?+1:0) + (SortinoVIXM>0?+1:0) + (SortinoUUP>0?+1:0) +(SortinoPFIX>0?+1:0) + (SortinoDBB<0?+1:0)  + (SortinoUDN<0?+1:0) + (SortinoDBC<0?+1:0)  + (SortinoUSO<0?+1:0) + (SortinoDBP<0?+1:0) 
    DeflationMSortino   = (SortinoUUP>0?+1:0)  + (SortinoGLD>0?+1:0) + (SortinoVIXM>0?+1:0) + (SortinoDBP>0?+1:0) +(SortinoPFIX>0?+1:0) + (SortinoBITO<0?+1:0) + (SortinoUDN<0?+1:0) + (SortinoDBC<0?+1:0)  + (SortinoUSO<0?+1:0) + (SortinoDBB<0?+1:0)
    DenumeratorMSortino =  GoldilocksMSortino + ReflationMSortino +  InflationMSortino +  DeflationMSortino

    // Calculate the probabilities Macro Omega
    GoldilocksMOmega  = (OmegaBITO>0?+1:0) + (OmegaDBB>0?+1:0) + (OmegaDBC>0?+1:0)  + (OmegaUDN>0?+1:0) +(OmegaGLD>0?+1:0)  + (OmegaVIXM<0?+1:0) + (OmegaUUP<0?+1:0) + (OmegaPFIX<0?+1:0) + (OmegaUSO<0?+1:0) + (OmegaDBP<0?+1:0)
    ReflationMOmega   = (OmegaBITO>0?+1:0) + (OmegaDBC>0?+1:0) + (OmegaUSO>0?+1:0)  + (OmegaDBB>0?+1:0) +(OmegaGLD>0?+1:0)  + (OmegaUUP<0?+1:0)  + (OmegaDBA<0?+1:0) + (OmegaUDN<0?+1:0)  + (OmegaDBP<0?+1:0) + (OmegaVIXM<0?+1:0)
    InflationMOmega   = (OmegaBITO>0?+1:0) + (OmegaGLD>0?+1:0) + (OmegaVIXM>0?+1:0) + (OmegaUUP>0?+1:0) +(OmegaPFIX>0?+1:0) + (OmegaDBB<0?+1:0)  + (OmegaUDN<0?+1:0) + (OmegaDBC<0?+1:0)  + (OmegaUSO<0?+1:0) + (OmegaDBP<0?+1:0) 
    DeflationMOmega   = (OmegaUUP>0?+1:0)  + (OmegaGLD>0?+1:0) + (OmegaVIXM>0?+1:0) + (OmegaDBP>0?+1:0) +(OmegaPFIX>0?+1:0) + (OmegaBITO<0?+1:0) + (OmegaUDN<0?+1:0) + (OmegaDBC<0?+1:0)  + (OmegaUSO<0?+1:0) + (OmegaDBB<0?+1:0)
    DenumeratorMOmega =  GoldilocksMOmega + ReflationMOmega +  InflationMOmega +  DeflationMOmega

    // Calculate the probabilities Macro Normalization
    GoldilocksMNormal  = (NormalBITO>0?+1:0) + (NormalDBB>0?+1:0) + (NormalDBC>0?+1:0)  + (NormalUDN>0?+1:0) +(NormalGLD>0?+1:0)  + (NormalVIXM<0?+1:0) + (NormalUUP<0?+1:0) + (NormalPFIX<0?+1:0) + (NormalUSO<0?+1:0) + (NormalDBP<0?+1:0)
    ReflationMNormal   = (NormalBITO>0?+1:0) + (NormalDBC>0?+1:0) + (NormalUSO>0?+1:0)  + (NormalDBB>0?+1:0) +(NormalGLD>0?+1:0)  + (NormalUUP<0?+1:0)  + (NormalDBA<0?+1:0) + (NormalUDN<0?+1:0)  + (NormalDBP<0?+1:0) + (NormalVIXM<0?+1:0)
    InflationMNormal   = (NormalBITO>0?+1:0) + (NormalGLD>0?+1:0) + (NormalVIXM>0?+1:0) + (NormalUUP>0?+1:0) +(NormalPFIX>0?+1:0) + (NormalDBB<0?+1:0)  + (NormalUDN<0?+1:0) + (NormalDBC<0?+1:0)  + (NormalUSO<0?+1:0) + (NormalDBP<0?+1:0) 
    DeflationMNormal   = (NormalUUP>0?+1:0)  + (NormalGLD>0?+1:0) + (NormalVIXM>0?+1:0) + (NormalDBP>0?+1:0) +(NormalPFIX>0?+1:0) + (NormalBITO<0?+1:0) + (NormalUDN<0?+1:0) + (NormalDBC<0?+1:0)  + (NormalUSO<0?+1:0) + (NormalDBB<0?+1:0)
    DenumeratorMNormal =  GoldilocksMNormal + ReflationMNormal +  InflationMNormal +  DeflationMNormal


    ////// ROC
    GoldilocksTotRoC  = GoldilocksFIroc  + GoldilocksMroc
    ReflationTotRoC   = ReflationFIroc   + ReflationMroc
    InflationTotRoC   = InflationFIroc   + InflationMroc
    DeflationTotRoC   = DeflationFIroc   + DeflationMroc
      

    ////////SHARPE
    GoldilocksTotSharpe  = GoldilocksFISharpe  + GoldilocksMSharpe
    ReflationTotSharpe   = ReflationFISharpe   + ReflationMSharpe
    InflationTotSharpe   = InflationFISharpe   + InflationMSharpe
    DeflationTotSharpe   = DeflationFISharpe   + DeflationMSharpe


    ///////SORTINO
    GoldilocksTotSortino  = GoldilocksFISortino  + GoldilocksMSortino
    ReflationTotSortino   = ReflationFISortino   + ReflationMSortino
    InflationTotSortino   = InflationFISortino   + InflationMSortino
    DeflationTotSortino   = DeflationFISortino   + DeflationMSortino


    /////////OMEGA
    GoldilocksTotOmega  = GoldilocksFIOmega  + GoldilocksMOmega
    ReflationTotOmega   = ReflationFIOmega   + ReflationMOmega
    InflationTotOmega   = InflationFIOmega   + InflationMOmega
    DeflationTotOmega   = DeflationFIOmega   + DeflationMOmega
   

    /////////NORMALIZATION
    GoldilocksTotNormal  = GoldilocksFINormal  + GoldilocksMNormal
    ReflationTotNormal   = ReflationFINormal   + ReflationMNormal
    InflationTotNormal   = InflationFINormal   + InflationMNormal
    DeflationTotNormal   = DeflationFINormal   + DeflationMNormal
  

    // Calculate the individual cross regimes
    GoldilocksULTIMATE  = GoldilocksTotRoC+ GoldilocksTotSharpe + GoldilocksTotSortino + GoldilocksTotOmega + GoldilocksTotNormal
    ReflationULTIMATE   = ReflationTotRoC + ReflationTotSharpe  + ReflationTotSortino  + ReflationTotOmega  + ReflationTotNormal
    InflationULTIMATE   = InflationTotRoC + InflationTotSharpe  + InflationTotSortino  + InflationTotOmega  + InflationTotNormal
    DeflationULTIMATE   = DeflationTotRoC + DeflationTotSharpe  + DeflationTotSortino  + DeflationTotOmega  + DeflationTotNormal
    DenumeratorULTIMATE = GoldilocksULTIMATE + ReflationULTIMATE +  InflationULTIMATE +  DeflationULTIMATE

    // Find the greatest value among the scenarios
    maxValueULTIMATE    = math.max(GoldilocksULTIMATE, ReflationULTIMATE, InflationULTIMATE, DeflationULTIMATE)

    // Determine the market scenario based on the greatest value
    if maxValueULTIMATE == GoldilocksULTIMATE or maxValueULTIMATE == ReflationULTIMATE
        RiskULTIMATE := "RISK ON"
    else
        RiskULTIMATE := "RISK OFF"

    if maxValueULTIMATE == GoldilocksULTIMATE
        regColULTIMATE := color.new(color.green, 50)        
    else if maxValueULTIMATE == ReflationULTIMATE
        regColULTIMATE := color.new(color.lime,  50)   
    else if maxValueULTIMATE == InflationULTIMATE
        regColULTIMATE := color.new(color.red,   50)   
    else if maxValueULTIMATE == DeflationULTIMATE 
        regColULTIMATE := color.new(color.blue,  50)
   
    // var table debug = table.new(
    //  table_y_pos + "_" + table_x_pos, 
    //  columns = 2, 
    //  rows = 7, 
    //  frame_color = color.white,
    //  frame_width = 1, 
    //  border_color = color.white, 
    //  border_width = 1)

    // if barstate.islast
    //     table.cell(debug, 0, 0,"GoldilocksULTIMATE",            text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 1, 0,str.tostring(GoldilocksULTIMATE),text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 0, 1,"ReflationULTIMATE",             text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 1, 1,str.tostring(ReflationULTIMATE), text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 0, 2,"InflationULTIMATE",             text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 1, 2,str.tostring(InflationULTIMATE), text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 0, 3,"DeflationULTIMATE",             text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 1, 3,str.tostring(DeflationULTIMATE), text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 0, 4,"maxValueULTIMATE",              text_size = i_text_size, text_color = color.white)
    //     table.cell(debug, 1, 4,str.tostring(maxValueULTIMATE),  text_size = i_text_size, text_color = color.white)


plot(   ultimateRISK? RiskULTIMATE == "RISK ON"? 1 : -1 : na )
bgcolor(ultimateRISK? RiskULTIMATE == "RISK ON"? color.new(color.green, 60) : color.new(color.red, 60):na)
bgcolor(ultimateGRID? regColULTIMATE: na)

barcolor(barcRisk? colx? RiskBgx : ultimateRISK? RiskULTIMATE   == "RISK ON"? color.green : color.red: na :na)
barcolor(barcGRID? reg?  regCol  : ultimateGRID? regColULTIMATE :na:na)