input lookback = 1;
input ATRperiod = 14;
input averageType = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input ATRMultiplier = 1;
def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[lookback+1], close(period = ”DAY”)[lookback+1], low(period = ”DAY”)[lookback+1]), ATRperiod);
def DailyClose = close(period = ”DAY”)[lookback+0];
def HighATR = DailyClose + ATR ;
def LowATR = DailyClose - ATR;
def bn = BarNumber();
def na = Double.NaN;
def LastBar = !IsNaN(open) and IsNaN(open[-1]);
def lastbarnumber = HighestAll(if LastBar then bn else na);
def ADRH = if IsNaN(close) then ADRH[1] else if LastBar then HighATR[lookback] else ADRH[1];
def ADRL = if IsNaN(close) then ADRL[1] else if LastBar then LowATR[lookback] else ADRL[1];
input limit_line_plot = 4;
def range = ADRH - ADRL;
plot f100 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRH else na;
plot f0 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL else na;
plot f236 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * .236 else na;
plot f382 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * .382 else na;
plot f500 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * .500 else na;
plot f618 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * .618 else na;
plot f764 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * .764 else na;
plot f1236 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * 1.236 else na;
plot f1382 = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL + range * 1.382 else na;
plot f1236_ = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL - range * .236 else na;
plot f1382_ = if Between(bn, lastbarnumber, lastbarnumber + limit_line_plot) then ADRL - range * .382 else na;
f100.SetPaintingStrategy(PaintingStrategy.DASHES);
f0.SetPaintingStrategy(PaintingStrategy.DASHES);
f236.SetPaintingStrategy(PaintingStrategy.DASHES);
f382.SetPaintingStrategy(PaintingStrategy.DASHES);
f500.SetPaintingStrategy(PaintingStrategy.DASHES);
f618.SetPaintingStrategy(PaintingStrategy.DASHES);
f764.SetPaintingStrategy(PaintingStrategy.DASHES);
f1236.SetPaintingStrategy(PaintingStrategy.DASHES);
f1382.SetPaintingStrategy(PaintingStrategy.DASHES);
f1236_.SetPaintingStrategy(PaintingStrategy.DASHES);
f1382_.SetPaintingStrategy(PaintingStrategy.DASHES);
DefineGlobalColor("F", Color.WHITE);
f100.SetDefaultColor(GlobalColor("F"));
f0.SetDefaultColor(GlobalColor("F"));
f236.SetDefaultColor(GlobalColor("F"));
f382.SetDefaultColor(GlobalColor("F"));
f500.SetDefaultColor(GlobalColor("F"));
f618.SetDefaultColor(GlobalColor("F"));
f764.SetDefaultColor(GlobalColor("F"));
f1236.SetDefaultColor(GlobalColor("F"));
f1382.SetDefaultColor(GlobalColor("F"));
f1236_.SetDefaultColor(GlobalColor("F"));
f1382_.SetDefaultColor(GlobalColor("F"));
f100.HideBubble();
f0.HideBubble();
f236.HideBubble();
f382.HideBubble();
f500.HideBubble();
f618.HideBubble();
f764.HideBubble();
f1236.HideBubble();
f1382.HideBubble();
f1236_.HideBubble();
f1382_.HideBubble();
input showbubbles = yes;
input bubblemover = 4;
input showbubble_price = yes;
def b = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f100[b1], "100% " + (if showbubble_price then AsDollars(f100[b1]) else " "), f100.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f0[b1], "0% " + (if showbubble_price then AsDollars(f0[b1]) else " "), f0.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f236[b1], "23.6% " + (if showbubble_price then AsDollars(f236[b1]) else " "), f236.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f382[b1], "38.2% " + (if showbubble_price then AsDollars(f382[b1]) else " "), f382.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f500[b1], "50% " + (if showbubble_price then AsDollars(f500[b1]) else " "), f500.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f618[b1], "61.8% " + (if showbubble_price then AsDollars(f618[b1]) else " "), f618.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f764[b1], "76.% " + (if showbubble_price then AsDollars(f764[b1]) else " "), f764.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f1236[b1], "123.6% " + (if showbubble_price then AsDollars(f1236[b1]) else " "), f1236.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f1382[b1], "138.2% " + (if showbubble_price then AsDollars(f1382[b1]) else " "), f1382.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f1236_[b1], "-23.6% " + (if showbubble_price then AsDollars(f1236_[b1]) else " "), f1236_.TakeValueColor());
AddChartBubble(showbubbles and !IsNaN(open[b1]) and IsNaN(open[b]), f1382_[b1], "-38.2% " + (if showbubble_price then AsDollars(f1382_[b1]) else " "), f1382_.TakeValueColor());