Hi all, I am trying to start a new indicator, and one aspect of it requires taking N number of the SPDR sectors and looking at whether they all flip green or red for the day. However, when I finished this step I noticed that it doesn't seem to show any of the green-flipped results on different stocks, but those results do appear when looking at the first symbol in the code, XLI. I've attached an example of what I mean here, where XLI shows a green arrow off open that does not appear for QQQ -- does anybody know what is going on with this?
Code:
# Input ETF symbols
input etf1 = "XLE";
input etf2 = "XLV";
input etf3 = "XLY";
input etf4 = "XLU";
input etf5 = "XLI";
# Number of ETFs that need to be green/red to trigger a signal
input tolerance = 4;
input agg = aggregationperiod.day;
# Script to check if a symbol is green for the day
script isGreenDay {
input symbol = "";
input aggy = aggregationperiod.day;
def isGreen = close(symbol = symbol) > open(symbol = symbol, period=aggy);
plot result = isGreen;
}
# Script to check if a symbol is red for the day
script isRedDay {
input symbol = "";
input aggy = aggregationperiod.day;
def isRed = close(symbol = symbol) < open(symbol = symbol, period=aggy);
plot result = isRed;
}
# Count green and red ETFs
def greenCount =
isGreenDay(etf1, agg).result +
isGreenDay(etf2, agg).result +
isGreenDay(etf3, agg).result +
isGreenDay(etf4, agg).result +
isGreenDay(etf5, agg).result;
def redCount =
isRedDay(etf1, agg).result +
isRedDay(etf2, agg).result +
isRedDay(etf3, agg).result +
isRedDay(etf4, agg).result +
isRedDay(etf5, agg).result;
# Plot arrows based on the count
def up = greenCount >= tolerance;
def dn = redCount >= tolerance;
plot UpArrow = up and !up[1];
plot DownArrow = dn and !dn[1];
UpArrow.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);
UpArrow.SetDefaultColor(Color.GREEN);
UpArrow.SetLineWeight(3);
DownArrow.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_DOWN);
DownArrow.SetDefaultColor(Color.RED);
DownArrow.SetLineWeight(3);