changed input symbol to qqq. took a few things out i personally didnt need. added coloration based on 9 moving average of $tick/q.
declare lower;
input xlbwt = 1.08; # Materials
input xlewt = 0.74; # Energy
input xliwt = 4.01; # Industrials
input xlcwt = 2.81; # Communications
input xlywt = 18.58; # Consumer Discretionary
input xlfwt = 3.90; # Financials
input xlrewt = 0.85; # Real Estate
input xluwt = 0.94; # Utilities
input xlpwt = 2.00; # Consumer Staples
input xlvwt = 6.12; # Health Care
input xlkwt = 58.97; # Information Technology
def SectorCount = 11;
def Scale = 5000;
script PC {
input Symbol = "QQQ";
def isFirstBar = GetTime() == RegularTradingStart(GetYYYYMMDD()) + 1;
def O = if isFirstBar then close(Symbol) else O[1];
def C = close(Symbol);
plot PctChg = (C - O) / O;
}
def xlkPctChg = PC("XLK");
def xlyPctChg = PC("XLY");
def xlvPctChg = PC("XLV");
def xlfPctChg = PC("XLF");
def xlcPctChg = PC("XLC");
def xliPctChg = PC("XLI");
def xlpPctChg = PC("XLP");
def xlrePctChg = PC("XLRE");
def xlePctChg = PC("XLE");
def xlbPctChg = PC("XLB");
def xluPctChg = PC("XLU");
def xlkSizing = xlkPctChg * xlkwt;
def xlvSizing = xlvPctChg * xlvwt;
def xlySizing = xlyPctChg * xlywt;
def xlfSizing = xlfPctChg * xlfwt;
def xlcSizing = xlcPctChg * xlcwt;
def xliSizing = xliPctChg * xliwt;
def xlpSizing = xlpPctChg * xlpwt;
def xleSizing = xlePctChg * xlewt;
def xlreSizing = xlrePctChg * xlrewt;
def xlbSizing = xlbPctChg * xlbwt;
def xluSizing = xluPctChg * xluwt;
def combinedSizing = Scale * (
xlkSizing +
xlvSizing +
xlySizing +
xlfSizing +
xlcSizing +
xliSizing +
xlpSizing +
xleSizing +
xlreSizing +
xlbSizing +
xluSizing
) / SectorCount;
def Weighted_AD = if !IsNaN(combinedSizing) then combinedSizing else Double.NaN;
# Calculate the 9-period moving average of $TICK/Q
def tickMA = SimpleMovingAvg(close("$TICK/Q"), 9);
plot Diff_Weighted_AD = Weighted_AD;
Diff_Weighted_AD.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Diff_Weighted_AD.SetLineWeight(3);
Diff_Weighted_AD.DefineColor("Positive and Up", Color.GREEN);
Diff_Weighted_AD.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff_Weighted_AD.DefineColor("Negative and Down", Color.RED);
Diff_Weighted_AD.DefineColor("Negative and Up", Color.PINK);
Diff_Weighted_AD.AssignValueColor(if tickMA >= 0 then
if tickMA > tickMA[1] then Diff_Weighted_AD.color("Positive and Up")
else Diff_Weighted_AD.color("Positive and Down")
else if tickMA < tickMA[1] then Diff_Weighted_AD.color("Negative and Down")
else Diff_Weighted_AD.color("Negative and Up"));