i'm going to cover a few things, that i hope will help you.
i may have been wrong to suggest using 2nd aggregation for finding what you want. i was thinking of trying to get it to work, when the chart time is not set to day. i am working on another study to work on any chart time. if i finish it, i will post later.
------------------------------------
notes on a study that is set to day
AddLabel(yes,"Previous Close: " + High[1], 60 Color.WHITE);
a couple things on your code
...you have , Previous Close: , and High[1] for a variable.
....if you want a close price from the past, you would use close[] with some offset , not high[]
...high[1] will read the high from the previous bar
...you have 60 after a comma then a color. addlabel wants just a color for the 3rd parameter
if you want the highest price of close for the past 60 bars,
def len = 60;
def x = highest(close, len);
addlabel(1, "highest " + x, color.white);
by default, a label will show the values calculated from the last bar on the chart
notice i said bars, not days. all charts work with data in variables, on each bar.
if you want that highest() formula to find the highest value over 60 days, the chart time will need to be set to days.
here is a study that,
..pick a number of bars to look back over
..show a label of the highest close
..yes/no show a verical line when the highest close is found
..yes/no show an arrow when the highest close is found
..yes/no show a verical line when the start of the period
Code:
# daychart60hicls_00
# use this on a chart set to day
def na = Double.NaN;
def bn = BarNumber();
def barCount = HighestAll(If(IsNaN(close), 0, bn));
# find the highest bar number on the chart. find highest bar number, when close is not an error
input price = close;
input len = 60;
def clshi = Highest(price, len);
# on each bar, look back 60 bars and find the highest close
addlabel(1, "highest close " + clshi, color.white);
# ================================
def clshi2 = if barcount == bn then clshi else 0;
# save the highest value , for the past 60 days, just on the last bar
def clshi3 = HighestAll(clshi2);
# find the highest value for past 60 days. this copies the value to a variable, to all bars. this allows a value defined in the future, to be used on earlier bar formulas.
# since only the lastbar of clshi2 will have a value, and the rest will be 0, that value will be used in the highestall().
def clshi4 = if ((bn >= (barcount - len) and bn <= barcount) ) then clshi3 else 0;
# if a bar is within 60 bars of the last bar, then set clshi4 equal to the high close value
def hibar = (close == clshi4);
# if the close of the bar is equal to the highest close value , then it will be true ( or 1)
input show_vertical_line_at_highest = yes;
AddVerticalLine( show_vertical_line_at_highest and hibar, "highest " + close, Color.CYAN);
# plot a vertical line just before te bar with the highest close
input show_arrow_at_highest = yes;
plot z = if show_arrow_at_highest then hibar else na;
z.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
z.SetDefaultColor(Color.WHITE);
# draw an arrow above the bar with the highest close
def periodstart = ( !isnan(close[-len]) and isnan(close[-(len+1)]) );
# find a bar 'len' (60) bars before the last bar
input show_vertical_line_start_of_period = yes;
AddVerticalLine(show_vertical_line_start_of_period and periodstart, len + " bars back" , Color.yellow);
# draw a vertical line 60 bars back from last bar
input test_values = no;
addchartbubble(test_values, low * 0.99, bn + "\n" + clshi3 + "\n" + periodstart, (if hibar then Color.YELLOW else Color.GRAY), no);
#
AAPL day chart length = 60