On Pace for % on year?

eugchen

Member
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!
 
@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);
 

@eugchen

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
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
234 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top