I've created a code that labels sectors and indexes that shows the current % change. I tried to get it to rank order them, but I've succeeded only in getting the labels at the top with the percentages but not rank ordering them. Can someone improve on the code so it does the rank ordering?
Here's a chart link: http://tos.mx/!V1CshPSK
Here's a screenshot of the chart:
Here's the code:
declare upper;
# Sectors
def XLK = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * 100;
def XLV = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * 100;
def XLF = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * 100;
def XLI = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * 100;
def XLE = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * 100;
def XLU = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * 100;
def XLB = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * 100;
def XLY = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * 100;
def XLP = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * 100;
def XLRE = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * 100;
def XLC = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * 100;
# Index ETFs
def SPY = (close("SPY") - close("SPY")[1]) / close("SPY")[1] * 100;
def QQQ = (close("QQQ") - close("QQQ")[1]) / close("QQQ")[1] * 100;
def IWM = (close("IWM") - close("IWM")[1]) / close("IWM")[1] * 100;
# Labels
AddLabel(yes, "XLK (Tech): " + Round(XLK, 2) + "%", if XLK >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLV (Health): " + Round(XLV, 2) + "%", if XLV >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLF (Financials): " + Round(XLF, 2) + "%", if XLF >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLI (Industrials): " + Round(XLI, 2) + "%", if XLI >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLE (Energy): " + Round(XLE, 2) + "%", if XLE >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLU (Utilities): " + Round(XLU, 2) + "%", if XLU >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLB (Materials): " + Round(XLB, 2) + "%", if XLB >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLY (Cons Disc): " + Round(XLY, 2) + "%", if XLY >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLP (Cons Stap): " + Round(XLP, 2) + "%", if XLP >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLRE (Real Estate): " + Round(XLRE, 2) + "%", if XLRE >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLC (Comm Services): " + Round(XLC, 2) + "%", if XLC >= 0 then Color.GREEN else Color.RED);
# Indexes
AddLabel(yes, "SPY (S&P 500): " + Round(SPY, 2) + "%", if SPY >= 0 then Color.CYAN else Color.MAGENTA);
AddLabel(yes, "QQQ (Nasdaq): " + Round(QQQ, 2) + "%", if QQQ >= 0 then Color.CYAN else Color.MAGENTA);
AddLabel(yes, "IWM (Russell 2000): " + Round(IWM, 2) + "%", if IWM >= 0 then Color.CYAN else Color.MAGENTA);
Here's a chart link: http://tos.mx/!V1CshPSK
Here's a screenshot of the chart:
Here's the code:
declare upper;
# Sectors
def XLK = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * 100;
def XLV = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * 100;
def XLF = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * 100;
def XLI = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * 100;
def XLE = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * 100;
def XLU = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * 100;
def XLB = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * 100;
def XLY = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * 100;
def XLP = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * 100;
def XLRE = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * 100;
def XLC = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * 100;
# Index ETFs
def SPY = (close("SPY") - close("SPY")[1]) / close("SPY")[1] * 100;
def QQQ = (close("QQQ") - close("QQQ")[1]) / close("QQQ")[1] * 100;
def IWM = (close("IWM") - close("IWM")[1]) / close("IWM")[1] * 100;
# Labels
AddLabel(yes, "XLK (Tech): " + Round(XLK, 2) + "%", if XLK >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLV (Health): " + Round(XLV, 2) + "%", if XLV >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLF (Financials): " + Round(XLF, 2) + "%", if XLF >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLI (Industrials): " + Round(XLI, 2) + "%", if XLI >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLE (Energy): " + Round(XLE, 2) + "%", if XLE >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLU (Utilities): " + Round(XLU, 2) + "%", if XLU >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLB (Materials): " + Round(XLB, 2) + "%", if XLB >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLY (Cons Disc): " + Round(XLY, 2) + "%", if XLY >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLP (Cons Stap): " + Round(XLP, 2) + "%", if XLP >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLRE (Real Estate): " + Round(XLRE, 2) + "%", if XLRE >= 0 then Color.GREEN else Color.RED);
AddLabel(yes, "XLC (Comm Services): " + Round(XLC, 2) + "%", if XLC >= 0 then Color.GREEN else Color.RED);
# Indexes
AddLabel(yes, "SPY (S&P 500): " + Round(SPY, 2) + "%", if SPY >= 0 then Color.CYAN else Color.MAGENTA);
AddLabel(yes, "QQQ (Nasdaq): " + Round(QQQ, 2) + "%", if QQQ >= 0 then Color.CYAN else Color.MAGENTA);
AddLabel(yes, "IWM (Russell 2000): " + Round(IWM, 2) + "%", if IWM >= 0 then Color.CYAN else Color.MAGENTA);
Last edited by a moderator: