Previous Year


I want to calculate the net change since YTD.

My script is the following:

// Getting the Last Trading Day of the Previous Year
Line1 = BARDATE()==STRDATE(DATE=2023-12-29) ;

// Getting the Value of the Last Trading Day of the Previous Year
Line2 = VALUEWHEN(Line1) ;

// Calculating the Absolute Change since the Last Trading Day of the Previous Year
Line3 = CLOSE() - Line2 ;

The script works as it should.

BUT is it possible to change Line1 in a way that the last trading day of each year is automatically selected without manually selecting the date using the STRDATE() function?

Many thanks in advance.

How can I make it possible that the code lines are in color?

Hi Thomas,

Do you mean like a YTD time series that resets every year? The YEAR() function gets the close of the year, so YEAR()[1] is the close of the previous year. Does this work?


To show as a percentage:


So $SPX has gained 252 points so far this year, or 5.3%, and you can see the previous years.

1 Like

Hi Darren,

Thank you for your help. Your suggestions are exactly what I wanted.

I have not considered the possibilities of the YEAR() function.

Your ShowPlot example with the “Last Year’s close” was very inspiring.


1 Like