# boxrange_per_00
def na = double.nan;
def bn = barnumber();
def lastbarbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbarbn) then 1 else 0;
#def lastbar = !isnan(close[0]) and isnan(close[-1]);
input sym1 = "SPY";
input s1_rng_hi = 0.0;
input s1_rng_lo = 0.0;
input sym2 = "TJX";
input s2_rng_hi = 0.0;
input s2_rng_lo = 0.0;
input sym3 = "WMT";
input s3_rng_hi = 0.0;
input s3_rng_lo = 0.0;
input sym4 = "Z";
input s4_rng_hi = 0.0;
input s4_rng_lo = 0.0;
input sym5 = "PM";
input s5_rng_hi = 0.0;
input s5_rng_lo = 0.0;
def rnghi;
def rnglo;
if GetSymbol() == sym1 then {
rnghi = s1_rng_hi;
rnglo = s1_rng_lo;
} else if GetSymbol() == sym2 then {
rnghi = s2_rng_hi;
rnglo = s2_rng_lo;
} else if GetSymbol() == sym3 then {
rnghi = s3_rng_hi;
rnglo = s3_rng_lo;
} else if GetSymbol() == sym4 then {
rnghi = s4_rng_hi;
rnglo = s4_rng_lo;
} else if GetSymbol() == sym5 then {
rnghi = s5_rng_hi;
rnglo = s5_rng_lo;
} else {
rnghi = 0;
rnglo = 0;
}
plot w1 = rnghi;
plot w2 = rnglo;
w1.setdefaultcolor(color.gray);
w2.setdefaultcolor(color.gray);
# ---------------------------
# box width, based on last bar
input bars_before_lastbar = 25;
input bars_after_lastbar = 10;
def barsb = bars_before_lastbar;
def barsa = bars_after_lastbar;
def x = if ( lastbarbn - barsb) <= bn and ( lastbarbn + barsa) >= bn then 1 else 0;
def cloudtop = if (rnghi == 0 or rnglo == 0 or !x ) then na else rnghi;
addcloud(cloudtop, rnglo, color.light_gray);
# ---------------------------
# bubbles
def bubx = if !isnan(close[barsa+1]) and isnan(close[barsa+0]) then 1 else 0;
def hiper = round(100*(rnghi[barsa+1] - close[barsa+1])/close[barsa+1],1);
def loper = round(100*(rnglo[barsa+1] - close[barsa+1])/close[barsa+1],1);
def rngper = round(100*(rnghi - rnglo)/rnglo,1);
def y2 = (( rnghi-rnglo)*0.4 ) + rnglo;
addchartbubble( bubx, rnghi, rnghi + "\n" + hiper + " %", color.yellow, yes);
addchartbubble( bubx, rnglo, rnglo + "\n" + loper + " %", color.yellow, no);
addchartbubble( bubx, y2, rngper + " %", color.yellow, yes);
#