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