% Change custom column

marciokoko

New member
I saw a Ken Rose tutorial where he uses this script to add a % YTD change to a list of tickers but it doesnt work for me. I get the values but they are incorrect:

def date = getYear();
def JanFirstClose = fold counter2 = 0 to 255 while date == Date[counter2] do close[counter2];
Plot YTDReturn = ((close/janFirstClose)-1)*100;
AssignBackgroundColor(if YTDReturn > 0 then color.Green else color.Red);

So for example i get this data for NIO: -8.63 today when its trading at 30.5. i would have to look back to jan 19 2021, which tos says closed at 58.44 which would be a 58.44/30.5= 91% drop.

If it were back to the open of Jan22, when it traded at 33.47 on jan 3 2022 = 33.47/30.5 = 9.7%.

Any ideas what I might be doing wrong?

Thanks
 
Solution
I saw a Ken Rose tutorial where he uses this script to add a % YTD change to a list of tickers but it doesnt work for me. I get the values but they are incorrect:

def date = getYear();
def JanFirstClose = fold counter2 = 0 to 255 while date == Date[counter2] do close[counter2];
Plot YTDReturn = ((close/janFirstClose)-1)*100;
AssignBackgroundColor(if YTDReturn > 0 then color.Green else color.Red);

So for example i get this data for NIO: -8.63 today when its trading at 30.5. i would have to look back to jan 19 2021, which tos says closed at 58.44 which would be a 58.44/30.5= 91% drop.

If it were back to the open of Jan22, when it traded at 33.47 on jan 3 2022 = 33.47/30.5 = 9.7%.

Any ideas what I might be doing wrong?

Thanks

i'm not...
I saw a Ken Rose tutorial where he uses this script to add a % YTD change to a list of tickers but it doesnt work for me. I get the values but they are incorrect:

def date = getYear();
def JanFirstClose = fold counter2 = 0 to 255 while date == Date[counter2] do close[counter2];
Plot YTDReturn = ((close/janFirstClose)-1)*100;
AssignBackgroundColor(if YTDReturn > 0 then color.Green else color.Red);

So for example i get this data for NIO: -8.63 today when its trading at 30.5. i would have to look back to jan 19 2021, which tos says closed at 58.44 which would be a 58.44/30.5= 91% drop.

If it were back to the open of Jan22, when it traded at 33.47 on jan 3 2022 = 33.47/30.5 = 9.7%.

Any ideas what I might be doing wrong?

Thanks

i'm not sure how far back you want to look back.
in your 1st sentence, you mention YTD , year to date. which implies a change since the beginning of the year.
later you mention looking back to jan 19 , 2021 ?? which implies 1 year ago.

the study is looking at data from the 1st trading day of the year, so YTD.


then this
... 58.44/30.5= 91% drop. which is wrong. 58.44 to 30.50 is a 48% drop.
... at 33.47 on jan 3 2022 = 33.47/30.5 = 9.7%. 33.47 to 30.5 is a 8.9% drop

------------------------------------

to test your study, i copied it into a column. i set the time to day.

i set it to the most basic version it could be.
i changed it to plot just counter2, so i could see what index it was using.
the numbers in the column came out to 10. 10 days before today was the first day of the year.
that part is working.
Code:
def date = getYear();
def JanFirstClose = fold counter2 = 0 to 255
  while date == Date[counter2]
  do counter2;
plot z = JanFirstClose;


then i changed it so it just displayed the close price of x bars ago. (now i know it to be 10 bars ago, jan 3)
i compared the column numbers of several stocks, to chart bars and verified the prices are from jan 3.
Code:
def date = getYear();
def JanFirstClose = fold counter2 = 0 to 255
  while date == Date[counter2]
  do close[counter2];
plot z = JanFirstClose;

it is getting the correct daily close price, of the first trading day of the year.
so either that isn't the date you think it is or your % math is wrong.
 
Solution

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
437 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