# day_same_line
def na = Double.NaN;
def bn = BarNumber();
def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;
def dowx = GetDayofWeek(GetYYYYMMDD());
def dyx = getday();
def wkx = getweek();
def mox = getmonth();
def yrx = getyear();
def dow;
def dy;
def wk;
def mo;
def t;
if GetAggregationPeriod() < AggregationPeriod.DAY then {
# draw vert lines for same day of week
dow = HighestAll(if lastbar then dowx else 0);
dy = 0;
wk = 0;
mo = 0;
t = 1;
} else if GetAggregationPeriod() < AggregationPeriod.week then {
# draw vert line for same day
dow = 0;
dy = HighestAll(if lastbar then dyx else 0);
wk = 0;
mo = 0;
t = 2;
} else if GetAggregationPeriod() < AggregationPeriod.month then {
# draw vert line for same week
dow = 0;
dy = 0;
wk = HighestAll(if lastbar then wkx else 0);
mo = 0;
t = 3;
} else {
# draw vert line for same month
dow = 0;
dy = 0;
wk = 0;
mo = HighestAll(if lastbar then mox else 0);
t = 4;
}
def valid = !isnan(close);
def dowz = (valid and dow == dowx);
addverticalline(dowz, "-", color.cyan);
def dyz = (valid and dy == dyx);
addverticalline(dyz, "-", color.cyan);
def wkz = (valid and wk == wkx);
addverticalline(wkz, "-", color.cyan);
def moz = (valid and mo == mox);
addverticalline(moz, "-", color.cyan);
addlabel(1,
(if t == 1 then "day of week " + dow
else if t == 2 then "day of week " + dy
else if t == 3 then "week of year " + wk
else if t == 4 then "month of year " + mo
else if t == 5 then "-"
else "-")
, color.cyan);
addverticalline(valid and yrx != yrx[1], " new year", color.gray);
#