#open_prices_yrmoday
#https://usethinkscript.com/threads/adding-historical-open-prices-to-a-chart-label.19758/#post-146643
def na = double.nan;
def bn = barnumber();
def dat = GetYYYYMMDD();
input Year_date = 20240102;
input Month_date = 20240801;
input week_date = 20240826;
input Day_date = 20240917;
# change code to retain the 1st bar in period
def firsty = dat[1] != Year_date and dat == Year_date;
def PriceY = if firsty then round(open,2) else PriceY[1];
def firstm = dat[1] != Month_date and dat == month_date;
def PriceM = if firstm then round(open,2) else PriceM[1];
def firstw = dat[1] != week_date and dat == week_date;
def Pricew = if firstw then round(open,2) else Pricew[1];
def firstd = dat[1] != Day_date and dat == day_date;
def PriceD = if firstd then round(open,2) else PriceD[1];
input labels = yes;
AddLabel(labels, "Year " + AsPrice(Year_date) + " " + PriceY, COLOR.CYAN);
AddLabel(labels, "Month " + AsPrice(Month_date) + " " + PriceM, COLOR.YELLOW);
AddLabel(labels, "Week " + AsPrice(week_date) + " " + Pricew, COLOR.magenta);
AddLabel(labels, "Day " + AsPrice(Day_date) + " " + PriceD, COLOR.LIGHT_ORANGE);
input bubbles = yes;
addchartbubble(bubbles and firsty, high*1.001, "Year\n"+pricey, color.gray, yes);
addchartbubble(bubbles and firstm, high*1.001, "Month\n"+pricem, color.gray, yes);
addchartbubble(bubbles and firstw, high*1.001, "Week\n"+pricew, color.gray, yes);
addchartbubble(bubbles and firstd, high*1.001, "Day\n"+priced, color.gray, yes);
#