that code line fails because , close lastbar , isn't a valid formula .
here is a modified version of your code. i added a bubble to display ,
the close of the last bar of the day
and the day close and previous day close
sometimes they match, sometimes they don't. maybe someone else can explain why
on the last bar of the day, this formula updates the variable to be the close of the last bar, and keeps it until the next last bar.
def lastclose = if lastbar then close else lastclose[1];
Code:
# prevdaylastclose
#https://usethinkscript.com/threads/last-bar-close.11779/
#My last line has a syntax error. can someone help?
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBar = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBar[-1]) then 1 else 0;
def lastclose = if lastbar then close else lastclose[1];
#-----------------------
def agg = aggregationPeriod.day;
def close_agg = close(period = agg);
def prevdayclose = close_agg[1];
#------------------------
AddChartBubble( 1
, (if lastbar then high*1.01 else low*0.99),
lastclose + " last bar\n" +
"\n" +
close_agg + " day close\n" +
prevdayclose + " prev day close\n"
, (if lastbar then Color.yellow else color.gray)
, (if lastbar then yes else no));
AddChartBubble( 0 and lastBar, close,
"Last Bar",
Color.GREEN, no);
#plot x1 = lastbar;
# this shows a boolean value either on or off, one or zero.
#plot x2 = close lastbar;
#this gives a syntax error. I want to plot the close of the last bar. the label correctly shows the last bar close. but not when I try to plot it.
#