Last 1 year percent change


Category:
0
0

Creating a new post asking for help with a little variation of the “YTD % change” topic that was already discussed. It would be nice to have a customized column in a watchlist or scan that will show the stock price change in % during the course of last 356 days (or actual trading days in past 1 year). The YTD % change criteria is not very useful when you are at the beginning of the year. Being able to go past 12 months instead of from January would be useful. Below is the script for YTD% change: The two lines need to be changed?

def startOfYear = GetYear() <> GetYear()[1];
rec startingClose = if startOfYear then close[1] else startingClose[1];
plot percentChange = 100 * (close / startingClose – 1);
percentChange.AssignValueColor(if percentChange > 1.0 then Color.BLACK else if percentChange < -1.0 then Color.BLACK else Color.CURRENT); AssignBackgroundColor(if percentChange > 1.0 then Color.GREEN else if percentChange < -1.0 then Color.RED else Color.CURRENT);

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on February 25, 2020 8:40 pm
210 views
0
Private answer

Actually for this request the modification is very simple. We can remove the first line entirely and update the second line to look back 251 days (the average number of trading days in any given year):

def startingClose = close[251];
plot percentChange = 100 * (close / startingClose – 1);
percentChange.AssignValueColor(if percentChange > 1.0 then Color.BLACK else if percentChange < -1.0 then Color.BLACK else Color.CURRENT); AssignBackgroundColor(if percentChange > 1.0 then Color.GREEN else if percentChange < -1.0 then Color.RED else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on February 26, 2020 8:03 am
0
Excellent!! Thank you.
( at February 26, 2020 9:55 am)