#day_avg
#https://usethinkscript.com/threads/average-from-open-till-now.18062/
def na = double.nan;
def bn = barnumber();
input start = 0930;
input end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def day_start = (secondsfromTime(start) == 0);
def day_end = (secondsfromTime(end) == 0);
# add up close prices during a day
# cnt the bars during a day
def day_total;
def day_cnt;
if bn == 1 then {
day_total = 0;
day_cnt = 0;
} else if day_start then {
day_total = close;
day_cnt = 1;
} else if daytime then {
day_total = day_total[1] + close;
day_cnt = day_cnt[1] + 1;
} else {
day_total = day_total[1];
day_cnt = day_cnt[1];
}
def avg = (day_total / day_cnt);
# skip day last bar, so line doesn't cross from day to day
def daytime2 = if daytime and getday() == getday()[-1] then 1 else 0;
plot a = if daytime2 then avg else double.nan;
a.SetDefaultColor(Color.white);
a.setlineweight(1);
a.hidebubble();
#