On Pace for % on year?


anyway to create a chart label for on pace for year? for instance, lets say AAPL is up 1% on jan 31. this would have Year gains to be on pace for 12%.

so the formula would be something like this...

(((close-year start price)/year start price)/days so far this year)*365

(close-year start price)/year start price) is basically a YTD performance label.
i dont know how to get "days so far this year). so for Jan 31, need that value to be 31.

this is my code below for YTD.

declare hide_on_intraday;

input price = close;
input length = 1;
input displace = 0;
input Show_Labels = yes;

def newyear = if getYear() != getYear()[1] then 1 else 0;
def yo = compoundValue(1, if newyear then open else yo[1], open);
def yearopen = yo;
def SMA = Average(price[-displace], length);
def yochange = (sma - yearopen) / yearopen ;

AddLabel(Show_Labels, concat("YTD: ", AsPercent(yochange)), CreateColor(255,162,231));

if anyone can help, i appreciate it!


Well-known member
@eugchecn I don't have time to look deep into this issue but thought I should mention that there are 252 trading days in a year, not 365... Charts are based on trading days, not calendar days...


For those interested, i was able to get someone at TOS to help me the code. check it out!

declare hide_on_intraday;

def YearOpen = if GetYear() != GetLastYear() then close else YearOpen[1];

def value = Round(100 * ((close - YearOpen) / YearOpen), 2);

def yearstart = GetYear() * 10000 + 101;

def daysFromDate = (CountTradingDays(yearstart, GetYYYYMMDD()));

def daystillDate = (CountTradingDays(yearstart, 20211231));

def value2 = round(100 *((((close - YearOpen) / YearOpen) / daysFromDate)*daystillDate));

AddLabel(yes, "Year Pace: " + value2 + "%", if value2 == 0

then Color.LIGHT_GRAY

else if value2 > 0

then CreateColor(51, 204, 0)

else Color.RED);


Well-known member


you may also possibly be interested in CAGR ... compound annual growth rate. if you find it interesting there is a thread and label for CAGR somehwere on this forum