declare lower;
script s {
input sym = "UAL";
input len1 = 20;
input len2 = 50;
input avg = AverageType.SIMPLE;
def c = if IsNaN(close(sym)) then c[1] else close(sym);
plot green = MovingAverage(avg, c, length = len1) >= MovingAverage(avg, c, length = len2);
}
input sym1 = "UAL";
input sym2 = "DAL";
input sym3 = "JBLU";
input sym4 = "AAL";
plot line1 = if IsNaN(close) then Double.NaN else 1;
line1.AssignValueColor(if s(sym1).green == 1 then Color.GREEN else if s(sym1).green == 0 then Color.RED else Color.YELLOW);
line1.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line2 = if IsNaN(close) then Double.NaN else 2;
line2.AssignValueColor(if s(sym2).green == 1 then Color.GREEN else if s(sym2).green == 0 then Color.RED else Color.YELLOW);
line2.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line3 = if IsNaN(close) then Double.NaN else 3;
line3.AssignValueColor(if s(sym3).green == 1 then Color.GREEN else if s(sym3).green == 0 then Color.RED else Color.YELLOW);
line3.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line4 = if IsNaN(close) then Double.NaN else 4;
line4.AssignValueColor(if s(sym4).green == 1 then Color.GREEN else if s(sym4).green == 0 then Color.RED else Color.YELLOW);
line4.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line5 = 5;#Fill Line
line5.SetDefaultColor(Color.BLACK);
plot line6 = if IsNaN(close) then Double.NaN else 6;
def summary = s(sym1).green + s(sym2).green + s(sym3).green + s(sym4).green;
line6.AssignValueColor( if summary == 4 then Color.GREEN else if summary == 0 then Color.RED else Color.YELLOW);
line6.SetPaintingStrategy(PaintingStrategy.POINTS);
#Bubbles
input showbubbles = yes;
input bubblemover = 4;
def bm = bubblemover;
def bm1 = bm + 1;
def last = IsNaN(close[bm]) and !IsNaN(close[bm1]);
AddChartBubble(showbubbles and last, line1[bm1], sym1, (if s(sym1).green[bm1] == 1 then Color.GREEN else if s(sym1).green[bm1] == 0 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line2[bm1], sym2, (if s(sym2).green[bm1] == 1 then Color.GREEN else if s(sym2).green[bm1] == 0 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line3[bm1], sym3, (if s(sym3).green[bm1] == 1 then Color.GREEN else if s(sym3).green[bm1] == 0 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line4[bm1], sym4, (if s(sym4).green[bm1] == 1 then Color.GREEN else if s(sym4).green[bm1] == 0 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line6[bm1], "Trend", if summary == 4 then Color.GREEN else if summary == 0 then Color.RED else Color.YELLOW, up = No);