The part in bold changes the data to Yearly bars before calculating the change function.
Here is the result of that.
Note that each value is the final value for the year. 2019 is correctly showing a gain of 6.3% (in the Dutch Market at least) which is the year to date.
The script works well on daily chart, but when i apply it on the watch list, this script doesn't work anymore. Notice that all the data shown for the year 2019 are identical compared to the 2018's.
So something must be wrong here. Can you check this out ?