# remove_outer_lines_01
input percent_away_from_hilo = 5.0;
def per = percent_away_from_hilo/100;
addlabel(1, "line diff " + percent_away_from_hilo + "%" ,color.gray);
def na = double.nan;
def bn = barnumber();
#def hiz = if bn == 1 then high else if high > hiz[1] then high else hiz[1];
#def loz = if bn == 1 then low else if low < loz[1] then low else loz[1];
def hiz = highestall(high);
def loz = lowestall(low);
input show_highest_lowest = yes;
plot a = if (show_highest_lowest and !isnan(close))then hiz else na;
plot b = if (show_highest_lowest and !isnan(close)) then loz else na;
# day cnt is wrong. length of 1950 on 15 minute chart is not 90 days
# 390min in a day / 15min bars = 26 , 15min bars in a day
# 1950 / 26 = 75 days
input length = 1950;
input dAdjuster = .015;
def LastBar = HighestAll(if !IsNaN(close) then BarNumber() else Double.NaN);
def BarRem = LastBar - BarNumber();
def lastbar2 = if bn == lastbar then 1 else 0;
# high line ----
#def High1950 = if !BarRem then Highest(high, length) else Double.NaN;
def High1950 = if BarRem >= 0 then Highest(high, length) else Double.NaN;
#plot Line = if BarRem <= length then HighestAll(High1950) - HighestAll(High1950) * dAdjuster else Double.NaN;
def hi1950per = round(((high1950 - hiz)/hiz)*100,1);
def showhi = (high1950 - hiz) <= (hiz * per);
plot hix = if !showhi then na else high1950;
hix.setdefaultcolor(color.gray);
#plot e = high1950;
# low line ----
#def low1950 = if !BarRem then Lowest(low, length) else Double.NaN;
def low1950 = if BarRem >= 0 then Lowest(low, length) else Double.NaN;
#plot line2 = if BarRem <= length then LowestAll(low1950) + LowestAll(low1950) * dAdjuster else Double.NaN;
def lo1950per = round(((loz - low1950)/loz)*100,1);
def showlo = (loz - low1950) <= (loz * per);
plot lox = if !showlo then na else low1950;
lox.setdefaultcolor(color.gray);
# ------------------
#def whichline = if AbsValue(close - High1950) < AbsValue(close - low1950) then 1 else 0;
#AddLabel(yes, "whichline " + whichline);
input show_line_bubbles = yes;
addchartbubble(show_line_bubbles and showhi and lastbar2, High1950, "High1950: " + High1950 + " , " + hi1950per + "%" , color.yellow, no);
addchartbubble(show_line_bubbles and showlo and lastbar2, low1950, "Low1950: " + low1950 + " , " + lo1950per + "%" , color.orange, yes);
addchartbubble(show_line_bubbles and lastbar2, Hiz, "Highest " + Hiz, color.yellow, yes);
addchartbubble(show_line_bubbles and lastbar2, loz, "Lowest " + loz, color.orange, no);
# ---------------------
input show_line_labels = yes;
addlabel(show_line_labels, "High1950 " + High1950 + " | " + hi1950per + "%" + " above highest " + hiz, color.yellow);
addlabel(show_line_labels, "Low1950 " + low1950 + " | " + lo1950per + "%" + " below lowest " + loz, color.orange);
# ------ test data ------------------
input test1 = no;
addchartbubble(test1, low, bn + "\n" + barrem + "\n" + showhi + "\n" + (high1950 - hiz) + "\n" + (hiz * per), color.cyan, no);
#