 Intraday Super Sectors v2.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TIG_That-Indicator-Guy
//@version=5
indicator(" ", overlay = false)



/////////////////////////////////////////////////
// LET'S GET THIS PARTY STARTED
/////////////////////////////////////////////////



var oGroup0 = "Welcome to the New Super Sector Indicator !"

oStudyTitle = input.string("New Super Sectors", "What title would you like displayed?", inline = "00", group = oGroup0)


var oGroup1 = "Super Sector Lines"

oColorCyclical = input.color(color.rgb(255, 153, 51,0), "Sector Colors:   Cyclical", inline = "11", group = oGroup1)
oColorDefensive = input.color(color.rgb(51, 153, 255, 0), "Defensive", inline = "11", group = oGroup1)


var oGroup2 = "          EMA Length          Linewidth      Show ?"

oTickEma = input.int(1, "Tick ", minval = 1, inline = "21", group = oGroup2)
oLineWidthTick  = input.int(1, "", minval = 1, maxval = 5, inline = "21", group = oGroup2)
oShowTick = input.bool(true, "", inline = "21", group = oGroup2)

oFastEma = input.int(6, "Fast ", minval = 1, inline = "22", group = oGroup2)
oLineWidthFast  = input.int(2, "", minval = 1, maxval = 5, inline = "22", group = oGroup2)
oShowFast = input.bool(true, "", inline = "22", group = oGroup2)

oSlowEma = input.int(30, "Slow ", minval = 1, inline = "23", group = oGroup2)
oLineWidthSlow  = input.int(3, "", minval = 1, maxval = 5, inline = "23", group = oGroup2)
oShowSlow = input.bool(true, "", inline = "23", group = oGroup2)


oShowCloud = input.bool(true, "Show Clouds between Fast and Slow lines?", inline = "24", group = oGroup2)

oSoftGreen = input.color(color.rgb(0, 255, 0, 85), "   Uptrending", inline = "25", group = oGroup2)
oSoftRed = input.color(color.rgb(255, 0, 0, 80), "  Downdtrending", inline = "25", group = oGroup2)


var oGroup3 = "SPX       EMA Length          Linewidth      Show ? "

oSpxEma = input.int(3, "SPX  ", minval = 1, inline = "41", group = oGroup3)
oLineWidthSpx  = input.int(1, "", minval = 1, maxval = 5, inline = "31", group = oGroup3)
oShowSpx = input.bool(false, "", inline = "31", group = oGroup3)
oColorSpx = input.color(color.rgb(255, 255, 255, 50), "", inline = "31", group = oGroup3)


var oGroup4 = "Text Colors"

oTextColor = input.color(color.rgb(128, 128, 128, 0), "Titles", inline = "41", group = oGroup4)
oTextGreen = input.color(color.rgb(64, 192, 64, 0), "   Up Text", inline = "41", group = oGroup4)
oTextRed   = input.color(color.rgb(255, 0, 0, 0), "   Down Text", inline = "41", group = oGroup4)

oShowSectors = input.bool(true, "Show All The Sector Data? (untick for phone use)", inline = "42", group = oGroup4)


// Sector data retrieved from https://finance.yahoo.com/quote/SPY/holdings/ on May 1, 2022

var oGroup6 = "Sector                          Weight / Cyclical-Defensive?"

oWeightXLB = input.float(2.31, "XLB (Materials)               ", minval = 0, inline = "61", group = oGroup6)
oSectorXLB = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "61", group = oGroup6)

oWeightXLC = input.float(9.34, "XLC (Communications Services)", minval = 0, inline = "62", group = oGroup6)
oSectorXLC = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "62", group = oGroup6)

oWeightXLE = input.float(3.86, "XLE (Energy)                 ", minval = 0, inline = "63", group = oGroup6)
oSectorXLE = input.string("Defensive", "", options = ["Cyclical", "Defensive"], inline = "63", group = oGroup6)

oWeightXLF = input.float(13.19, "XLF (Financials)              ", minval = 0, inline = "64", group = oGroup6)
oSectorXLF = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "64", group = oGroup6)

oWeightXLI = input.float(8.13, "XLI (Industrials)              ", minval = 0, inline = "65", group = oGroup6)
oSectorXLI = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "65", group = oGroup6)

oWeightXLK = input.float(25.51, "XLK (Information Technology) ", minval = 0, inline = "66", group = oGroup6)
oSectorXLK = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "66", group = oGroup6)

oWeightXLP = input.float(6.49, "XLP (Consumer Staples)       ", minval = 0, inline = "67", group = oGroup6)
oSectorXLP = input.string("Defensive", "", options = ["Cyclical", "Defensive"], inline = "67", group = oGroup6)

oWeightXLRE = input.float(2.71, "XLRE (Real Estate)            ", minval = 0, inline = "68", group = oGroup6)
oSectorXLRE = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "68", group = oGroup6)

oWeightXLU = input.float(2.45, "XLU (Utilities)                ", minval = 0, inline = "69", group = oGroup6)
oSectorXLU = input.string("Defensive", "", options = ["Cyclical", "Defensive"], inline = "69", group = oGroup6)

oWeightXLV = input.float(13.66, "XLV (Health Care)             ", minval = 0, inline = "6A", group = oGroup6)
oSectorXLV = input.string("Defensive", "", options = ["Cyclical", "Defensive"], inline = "6A", group = oGroup6)

oWeightXLY = input.float(11.81, "XLY (Consumer Discretionary)  ", minval = 0, inline = "6B", group = oGroup6)
oSectorXLY = input.string("Cyclical", "", options = ["Cyclical", "Defensive"], inline = "6B", group = oGroup6)



// Initialize Global Variables

oColorNone = color.rgb(0, 0, 0, 255)
oColorGray = color.rgb(128, 128, 128, 50)

var oOpenSpx = 0.0
var oOpenCyclical = 0.0
var oOpenDefensive = 0.0

var oBarCount = 0

var oOpenXLB = 0.0
var oOpenXLC = 0.0
var oOpenXLE = 0.0
var oOpenXLF = 0.0
var oOpenXLI = 0.0
var oOpenXLK = 0.0
var oOpenXLP = 0.0
var oOpenXLRE = 0.0
var oOpenXLU = 0.0
var oOpenXLV = 0.0
var oOpenXLY = 0.0

var oFactor = 0.0

var oTickCyclical = 0.0
var oFastCyclical = 0.0
var oSlowCyclical = 0.0
var oTickDefensive = 0.0
var oFastDefensive = 0.0
var oSlowDefensive = 0.0

var oFastSpx = 0.0



/////////////////////////////////////////////////
// DO SOME CALCULATIONS
/////////////////////////////////////////////////


// Intialize for a new session



oCashSession = time(timeframe.period, "0930-1600", "America/New_York")
oNewSession = (oCashSession and not(oCashSession[1])) or (oCashSession and (dayofweek != dayofweek[1]))

oShow = (oCashSession and not(oNewSession))




// !!! can delete this after testing!!
var oOpenTotal = 0.0


oOpenSpx := oNewSession ? request.security("SPX", timeframe.period, open) : oOpenSpx

oOpenXLB := oNewSession ? request.security("XLB", timeframe.period, open) : oOpenXLB
oOpenXLC := oNewSession ? request.security("XLC", timeframe.period, open) : oOpenXLC
oOpenXLE := oNewSession ? request.security("XLE", timeframe.period, open) : oOpenXLE
oOpenXLF := oNewSession ? request.security("XLF", timeframe.period, open) : oOpenXLF
oOpenXLI := oNewSession ? request.security("XLI", timeframe.period, open) : oOpenXLI
oOpenXLK := oNewSession ? request.security("XLK", timeframe.period, open) : oOpenXLK
oOpenXLP := oNewSession ? request.security("XLP", timeframe.period, open) : oOpenXLP
oOpenXLRE := oNewSession ? request.security("XLRE", timeframe.period, open) : oOpenXLRE
oOpenXLU := oNewSession ? request.security("XLU", timeframe.period, open) : oOpenXLU
oOpenXLV := oNewSession ? request.security("XLV", timeframe.period, open) : oOpenXLV
oOpenXLY := oNewSession ? request.security("XLY", timeframe.period, open) : oOpenXLY








if oNewSession
    oOpenCyclical :=     (oSectorXLB == "Cyclical" ? oOpenXLB * oWeightXLB : 0) +
                         (oSectorXLC == "Cyclical" ? oOpenXLC * oWeightXLC : 0) +
                         (oSectorXLE == "Cyclical" ? oOpenXLE * oWeightXLE : 0) +
                         (oSectorXLF == "Cyclical" ? oOpenXLF * oWeightXLF : 0) +
                         (oSectorXLI == "Cyclical" ? oOpenXLI * oWeightXLI : 0) +
                         (oSectorXLK == "Cyclical" ? oOpenXLK * oWeightXLK : 0) +
                         (oSectorXLP == "Cyclical" ? oOpenXLP * oWeightXLP : 0) +
                         (oSectorXLRE == "Cyclical" ? oOpenXLRE * oWeightXLRE : 0) +
                         (oSectorXLU == "Cyclical" ? oOpenXLU * oWeightXLU : 0) +
                         (oSectorXLV == "Cyclical" ? oOpenXLV * oWeightXLV : 0) +
                         (oSectorXLY == "Cyclical" ? oOpenXLY * oWeightXLY : 0)                   
                     
    oOpenDefensive :=    (oSectorXLB == "Defensive" ? oOpenXLB * oWeightXLB : 0) +
                         (oSectorXLC == "Defensive" ? oOpenXLC * oWeightXLC : 0) +
                         (oSectorXLE == "Defensive" ? oOpenXLE * oWeightXLE : 0) +
                         (oSectorXLF == "Defensive" ? oOpenXLF * oWeightXLF : 0) +
                         (oSectorXLI == "Defensive" ? oOpenXLI * oWeightXLI : 0) +
                         (oSectorXLK == "Defensive" ? oOpenXLK * oWeightXLK : 0) +
                         (oSectorXLP == "Defensive" ? oOpenXLP * oWeightXLP : 0) +
                         (oSectorXLRE == "Defensive" ? oOpenXLRE * oWeightXLRE : 0) +
                         (oSectorXLU == "Defensive" ? oOpenXLU * oWeightXLU : 0) +
                         (oSectorXLV == "Defensive" ? oOpenXLV * oWeightXLV : 0) +
                         (oSectorXLY == "Defensive" ? oOpenXLY * oWeightXLY : 0)

    // I don't know why, but the open values for the sectors appear to usually be slightly 'wrong'. So need correction!

    oOpenTotal :=        oOpenXLB * oWeightXLB +
                         oOpenXLC * oWeightXLC +
                         oOpenXLE * oWeightXLE +
                         oOpenXLF * oWeightXLF +
                         oOpenXLI * oWeightXLI +
                         oOpenXLK * oWeightXLK +
                         oOpenXLP * oWeightXLP +
                         oOpenXLRE * oWeightXLRE +
                         oOpenXLU * oWeightXLU +
                         oOpenXLV * oWeightXLV +
                         oOpenXLY * oWeightXLY

    oFactor := oOpenSpx / oOpenTotal

    oOpenXLB *= oFactor
    oOpenXLC *= oFactor
    oOpenXLE *= oFactor
    oOpenXLF *= oFactor
    oOpenXLI *= oFactor
    oOpenXLK *= oFactor
    oOpenXLP *= oFactor
    oOpenXLRE *= oFactor
    oOpenXLU *= oFactor
    oOpenXLV *= oFactor
    oOpenXLY *= oFactor

    oOpenCyclical *= oFactor
    oOpenDefensive *= oFactor

    oOpenTotal := oOpenTotal * oFactor
    
    oBarCount := 0
    


// So where are we now?

oCurrentSpx = request.security("SPX", timeframe.period, close)

oCurrentXLB = request.security("XLB", timeframe.period, close)
oCurrentXLC = request.security("XLC", timeframe.period, close)
oCurrentXLE = request.security("XLE", timeframe.period, close)
oCurrentXLF = request.security("XLF", timeframe.period, close)
oCurrentXLI = request.security("XLI", timeframe.period, close)
oCurrentXLK = request.security("XLK", timeframe.period, close)
oCurrentXLP = request.security("XLP", timeframe.period, close)
oCurrentXLRE = request.security("XLRE", timeframe.period, close)
oCurrentXLU = request.security("XLU", timeframe.period, close)
oCurrentXLV = request.security("XLV", timeframe.period, close)
oCurrentXLY = request.security("XLY", timeframe.period, close)




oCurrentCyclical =   (oSectorXLB == "Cyclical" ? oCurrentXLB * oWeightXLB : 0) +
                     (oSectorXLC == "Cyclical" ? oCurrentXLC * oWeightXLC : 0) +
                     (oSectorXLE == "Cyclical" ? oCurrentXLE * oWeightXLE : 0) +
                     (oSectorXLF == "Cyclical" ? oCurrentXLF * oWeightXLF : 0) +
                     (oSectorXLI == "Cyclical" ? oCurrentXLI * oWeightXLI : 0) +
                     (oSectorXLK == "Cyclical" ? oCurrentXLK * oWeightXLK : 0) +
                     (oSectorXLP == "Cyclical" ? oCurrentXLP * oWeightXLP : 0) +
                     (oSectorXLRE == "Cyclical" ? oCurrentXLRE * oWeightXLRE : 0) +
                     (oSectorXLU == "Cyclical" ? oCurrentXLU * oWeightXLU : 0) +
                     (oSectorXLV == "Cyclical" ? oCurrentXLV * oWeightXLV : 0) +
                     (oSectorXLY == "Cyclical" ? oCurrentXLY * oWeightXLY : 0)               
                 
oCurrentDefensive =  (oSectorXLB == "Defensive" ? oCurrentXLB * oWeightXLB : 0) +
                     (oSectorXLC == "Defensive" ? oCurrentXLC * oWeightXLC : 0) +
                     (oSectorXLE == "Defensive" ? oCurrentXLE * oWeightXLE : 0) +
                     (oSectorXLF == "Defensive" ? oCurrentXLF * oWeightXLF : 0) +
                     (oSectorXLI == "Defensive" ? oCurrentXLI * oWeightXLI : 0) +
                     (oSectorXLK == "Defensive" ? oCurrentXLK * oWeightXLK : 0) +
                     (oSectorXLP == "Defensive" ? oCurrentXLP * oWeightXLP : 0) +
                     (oSectorXLRE == "Defensive" ? oCurrentXLRE * oWeightXLRE : 0) +
                     (oSectorXLU == "Defensive" ? oCurrentXLU * oWeightXLU : 0) +
                     (oSectorXLV == "Defensive" ? oCurrentXLV * oWeightXLV : 0) +
                     (oSectorXLY == "Defensive" ? oCurrentXLY * oWeightXLY : 0)


oCurrentTotal =      oCurrentXLB * oWeightXLB +
                     oCurrentXLC * oWeightXLC +
                     oCurrentXLE * oWeightXLE +
                     oCurrentXLF * oWeightXLF +
                     oCurrentXLI * oWeightXLI +
                     oCurrentXLK * oWeightXLK +
                     oCurrentXLP * oWeightXLP +
                     oCurrentXLRE * oWeightXLRE +
                     oCurrentXLU * oWeightXLU +
                     oCurrentXLV * oWeightXLV +
                     oCurrentXLY * oWeightXLY

oFactor := oCurrentSpx / oCurrentTotal


oCurrentCyclical *= oFactor
oCurrentDefensive *= oFactor


oBarCount += 1


oXLB = 100 * (oCurrentXLB * oFactor / oOpenXLB - 1)
oXLC = 100 * (oCurrentXLC * oFactor / oOpenXLC - 1)
oXLE = 100 * (oCurrentXLE * oFactor / oOpenXLE - 1)
oXLF = 100 * (oCurrentXLF * oFactor / oOpenXLF - 1)
oXLI = 100 * (oCurrentXLI * oFactor / oOpenXLI - 1)
oXLK = 100 * (oCurrentXLK * oFactor / oOpenXLK - 1)
oXLP = 100 * (oCurrentXLP * oFactor / oOpenXLP - 1)
oXLRE = 100 * (oCurrentXLRE * oFactor / oOpenXLRE - 1)
oXLU = 100 * (oCurrentXLU * oFactor / oOpenXLU - 1)
oXLV = 100 * (oCurrentXLV * oFactor / oOpenXLV - 1)
oXLY = 100 * (oCurrentXLY * oFactor / oOpenXLY - 1)



// Calculate the changes

oSpx = 100 * (oCurrentSpx / oOpenSpx - 1)
oCyclical = 100 * (oCurrentCyclical / oOpenCyclical - 1)
oDefensive = 100 * (oCurrentDefensive / oOpenDefensive - 1)



// Calculate the plot values
// Grrrrr ... have to calculate EMA values manually 'cos TA doesn't allow dynamic (variable) lengths

oTickMultiplier = (2 / (math.min(oBarCount, oTickEma) + 1))
oFastMultiplier = (2 / (math.min(oBarCount, oFastEma) + 1))
oSlowMultiplier = (2 / (math.min(oBarCount, oSlowEma) + 1))

oTickCyclical := oBarCount == 1 ? oCyclical : oCyclical * oTickMultiplier + oTickCyclical[1] * (1 - oTickMultiplier)
oFastCyclical := oBarCount == 1 ? oCyclical : oCyclical * oFastMultiplier + oFastCyclical[1] * (1 - oFastMultiplier)
oSlowCyclical := oBarCount == 1 ? oCyclical : oCyclical * oSlowMultiplier + oSlowCyclical[1] * (1 - oSlowMultiplier)

oTickDefensive := oBarCount == 1 ? oDefensive : oDefensive * oTickMultiplier + oTickDefensive[1] * (1 - oTickMultiplier)
oFastDefensive := oBarCount == 1 ? oDefensive : oDefensive * oFastMultiplier + oFastDefensive[1] * (1 - oFastMultiplier)
oSlowDefensive := oBarCount == 1 ? oDefensive : oDefensive * oSlowMultiplier + oSlowDefensive[1] * (1 - oSlowMultiplier)

oSpxMultiplier = (2 / (math.min(oBarCount, oSpxEma) + 1))

oFastSpx := oBarCount == 1 ? oSpx : oSpx * oSpxMultiplier + oFastSpx[1] * (1 - oSpxMultiplier)



/////////////////////////////////////////////////
//  DISPLAY STUFF
/////////////////////////////////////////////////


// Plot the lines and infill


plot(0, color = oColorGray)


oPlotCyclicalTick = plot(oCyclical, linewidth = oLineWidthTick, color = oShow and oShowTick ? oColorCyclical : oColorNone)
oPlotCyclicalFast = plot(oFastCyclical, linewidth = oLineWidthFast, color = oShow and oShowFast ? oColorCyclical : oColorNone)
oPlotCyclicalSlow = plot(oSlowCyclical, linewidth = oLineWidthSlow, color = oShow and oShowSlow ? oColorCyclical : oColorNone)

fill(oPlotCyclicalFast, oPlotCyclicalSlow, color = oShow and oShowCloud ? oFastCyclical > oSlowCyclical ? oSoftGreen : oSoftRed : oColorNone)


oPlotDefensiveTick = plot(oDefensive, linewidth = oLineWidthTick, color = oShow and oShowTick ? oColorDefensive : oColorNone)
oPlotDefensiveFast = plot(oFastDefensive, linewidth = oLineWidthFast, color = oShow and oShowFast ? oColorDefensive : oColorNone)
oPlotDefensiveSlow = plot(oSlowDefensive, linewidth = oLineWidthSlow, color = oShow and oShowSlow ? oColorDefensive : oColorNone)

fill(oPlotDefensiveFast, oPlotDefensiveSlow, color = oShow and oShowCloud ? oFastDefensive > oSlowDefensive ? oSoftGreen : oSoftRed : oColorNone)


plot(oFastSpx, linewidth = oLineWidthSpx, color = oShow and oShowSpx ? oColorSpx : oColorNone)



// Plot the title

var table oTableTitle = table.new(position.top_left, 1, 1)
table.cell(oTableTitle, 0, 0, "    " + oStudyTitle, text_color = oTextColor, text_halign = text.align_left)


// Plot the data table


var table oTable1 = table.new(position.bottom_left, 13, 6)

var oCount = 0

if barstate.isfirst

    table.cell(oTable1, 1, 0, "SPX", text_color = oTextColor, text_halign = text.align_left)

    table.cell(oTable1, 0, 2, " ", bgcolor = oColorDefensive)
    table.cell(oTable1, 0, 3, " ", bgcolor = oColorDefensive)
    table.cell(oTable1, 1, 2, "Defensive", text_color = oTextColor, text_halign = text.align_left)

    table.cell(oTable1, 0, 4, " ", bgcolor = oColorCyclical)
    table.cell(oTable1, 0, 5, " ", bgcolor = oColorCyclical)
    table.cell(oTable1, 1, 4, "Cyclical", text_color = oTextColor, text_halign = text.align_left)

    oCount := 2
    
    if oSectorXLB == "Defensive"
        table.cell(oTable1, oCount, 2, "XLB",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLC == "Defensive"
        table.cell(oTable1, oCount, 2, "XLC",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLE == "Defensive"
        table.cell(oTable1, oCount, 2, "XLE",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLF == "Defensive"
        table.cell(oTable1, oCount, 2, "XLF",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
        
    if oSectorXLI == "Defensive"
        table.cell(oTable1, oCount, 2, "XLI",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLK == "Defensive"
        table.cell(oTable1, oCount, 2, "XLK",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLP == "Defensive"
        table.cell(oTable1, oCount, 2, "XLP",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLRE == "Defensive"
        table.cell(oTable1, oCount, 2, "XLRE", text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLU == "Defensive"
        table.cell(oTable1, oCount, 2, "XLU",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
        
    if oSectorXLV == "Defensive"
        table.cell(oTable1, oCount, 2, "XLV",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
        
    if oSectorXLY == "Defensive"
        table.cell(oTable1, oCount, 2, "XLY",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    oCount := 2
    
    if oSectorXLB == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLB",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLC == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLC",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLE == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLE",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLF == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLF",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
        
    if oSectorXLI == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLI",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLK == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLK",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLP == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLP",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLRE == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLRE", text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
    
    if oSectorXLU == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLU",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
        
    if oSectorXLV == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLV",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1
        
    if oSectorXLY == "Cyclical"
        table.cell(oTable1, oCount, 4, "XLY",  text_color = oShowSectors ? oTextColor : oColorNone, text_halign = text.align_center)
        oCount += 1



table.cell(oTable1, 1, 1, str.format("{0, number, #.##}", math.abs(oSpx)), text_color = oShow ? oSpx > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_left)
table.cell(oTable1, 1, 3, str.format("{0, number, #.##}", math.abs(oDefensive)), text_color = oShow ? oDefensive > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_left)
table.cell(oTable1, 1, 5, str.format("{0, number, #.##}", math.abs(oCyclical)), text_color = oShow ? oCyclical > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_left)


oCount := 2

if oSectorXLB == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLB)), text_color = oShow and oShowSectors ? oXLB > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLC == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLC)), text_color = oShow and oShowSectors ? oXLC > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLE == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLE)), text_color = oShow and oShowSectors ? oXLE > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLF == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLF)), text_color = oShow and oShowSectors ? oXLF > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1
    
if oSectorXLI == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLI)), text_color = oShow and oShowSectors ? oXLI > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLK == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLK)), text_color = oShow and oShowSectors ? oXLK > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLP == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLP)), text_color = oShow and oShowSectors ? oXLP > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLRE == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLRE)), text_color = oShow and oShowSectors ? oXLRE > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLU == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLU)), text_color = oShow and oShowSectors ? oXLU > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1
    
if oSectorXLV == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLV)), text_color = oShow and oShowSectors ? oXLV > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1
    
if oSectorXLY == "Defensive"
    table.cell(oTable1, oCount, 3, str.format("{0, number, #.##}", math.abs(oXLY)), text_color = oShow and oShowSectors ? oXLY > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

oCount := 2

if oSectorXLB == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLB)), text_color = oShow and oShowSectors ? oXLB > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLC == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLC)), text_color = oShow and oShowSectors ? oXLC > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLE == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLE)), text_color = oShow and oShowSectors ? oXLE > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLF == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLF)), text_color = oShow and oShowSectors ? oXLF > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1
    
if oSectorXLI == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLI)), text_color = oShow and oShowSectors ? oXLI > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLK == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLK)), text_color = oShow and oShowSectors ? oXLK > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLP == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLP)), text_color = oShow and oShowSectors ? oXLP > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLRE == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLRE)), text_color = oShow and oShowSectors ? oXLRE > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1

if oSectorXLU == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLU)), text_color = oShow and oShowSectors ? oXLU > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1
    
if oSectorXLV == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLV)), text_color = oShow and oShowSectors ? oXLV > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1
    
if oSectorXLY == "Cyclical"
    table.cell(oTable1, oCount, 5, str.format("{0, number, #.##}", math.abs(oXLY)), text_color = oShow and oShowSectors ? oXLY > 0 ? oTextGreen : oTextRed : oColorNone, text_halign = text.align_center)
    oCount += 1





// That's all folks

