# line_from_agg_bar_0
# https://usethinkscript.com/threads/auto-horizontal-line-at-the-close-of-the-first-5m-candle-after-the-open.13337/
# Auto horizontal line at the close of the first 5m candle after the open
def na = double.nan;
def bn = barnumber();
def diffday = if getday() != getday()[1] then 1 else 0;
def start = 0930;
input agg_time = AggregationPeriod.five_min;
def aggmin = agg_time/(1000*60);
def cls = close(period = agg_time);
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
def aggratio = (aggmin / chartmin);
input aggbar_of_day = 1;
def bar = ((aggbar_of_day - 0 ) * (aggmin / chartmin));
def aggbar2 = bar - 1;
def agg2min = aggbar2 * chartmin;
def time4 = if secondsfromTime(start) == (agg2min*60) then 1 else 0;
input vert_line = no;
addverticalline(vert_line and time4, "---", color.yellow);
input show_arrow = yes;
plot zz = if show_arrow and time4 then low*0.997 else na;
zz.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zz.SetDefaultColor(Color.cyan);
zz.setlineweight(3);
zz.hidebubble();
input price = close;
def level4 = if bn == 1 then na
else if diffday and time4 then price
else if diffday then na
else if time4 then price
else level4[1];
plot z = level4;
z.SetDefaultColor(Color.cyan);
#z.setlineweight(1);
z.hidebubble();
z.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#---------------------------
input test_labels = yes;
addlabel(test_labels, " ", color.black);
addlabel(test_labels, "close from xth agg bar /day", color.yellow);
addlabel(test_labels, "agg min " + aggmin, color.yellow);
addlabel(test_labels, "/", color.yellow);
addlabel(test_labels, "chart min " + chartmin, color.yellow);
addlabel(test_labels, "=", color.yellow);
addlabel(test_labels, "agg ratio " + aggratio, color.yellow);
addlabel(test_labels, "*", color.yellow);
addlabel(test_labels, "aggbar_of_day " + aggbar_of_day, color.yellow);
addlabel(test_labels, "=", color.yellow);
addlabel(test_labels, "bar " + bar, color.yellow);
addlabel(test_labels, " ", color.black);
addchartbubble(0, low*0.995,
aggbar_of_day + "\n" +
aggmin + "\n" +
chartmin + "\n" +
bar + "\n" +
(secondsfromTime(start)/60)
, color.yellow, no);
#