#
# TD Ameritrade IP Company, Inc. (c) 2014-2016
#
input show_in_right_expansion = yes;
input lookback = 1;
input aggregationPeriod = AggregationPeriod.DAY;
def PH = high(period = aggregationPeriod)[lookback];
def PL = low(period = aggregationPeriod)[lookback];
def PC = close(period = aggregationPeriod)[lookback];
plot R3;
plot R2;
plot R1;
plot PP;
plot S1;
plot S2;
plot S3;
PP = if show_in_right_expansion and !isnan(close) then double.nan else (PH + PL + PC) / 3;
R1 = 2 * PP - PL;
R2 = PP + (PH - PL);
R3 = 2 * PP + (PH - 2 * PL);
S1 = 2 * PP - PH;
S2 = PP - (PH - PL);
S3 = 2 * PP - (2 * PH - PL);
R3.SetDefaultColor(GetColor(5));
R2.SetDefaultColor(GetColor(5));
R1.SetDefaultColor(GetColor(5));
PP.SetDefaultColor(GetColor(0));
S1.SetDefaultColor(GetColor(6));
S2.SetDefaultColor(GetColor(6));
S3.SetDefaultColor(GetColor(6));
R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
input showbubbles = yes;
input bubblemover = 5;
def bn = barnumber();
def mo = bubblemover;
def mo1 = mo + 1;
AddChartBubble(showbubbles and bn==highestall(bn - mo1), pp[mo1], "PP" + lookback, pp.TakeValueColor());
AddChartBubble(showbubbles and bn==highestall(bn - mo1), S1[mo1], "S1-" + lookback, S1.TakeValueColor());
AddChartBubble(showbubbles and bn==highestall(bn - mo1), S2[mo1], "S2-" + lookback, S2.TakeValueColor());
AddChartBubble(showbubbles and bn==highestall(bn - mo1), S3[mo1], "S3-" + lookback, S3.TakeValueColor());
AddChartBubble(showbubbles and bn==highestall(bn - mo1), R1[mo1], "R1-" + lookback, R1.TakeValueColor());
AddChartBubble(showbubbles and bn==highestall(bn - mo1), R2[mo1], "R2-" + lookback, R2.TakeValueColor());
AddChartBubble(showbubbles and bn==highestall(bn - mo1), R3[mo1], "R3-" + lookback, R3.TakeValueColor());
#