BullBear_
New member
Hello!
I was wondering if the more savvy coders here can help me with the below code. I'd like to get percentage change of underlying for the last month, last 2 weeks and YTD without having to manually update the code everytime. Is this possible?
Thanks!
I was wondering if the more savvy coders here can help me with the below code. I'd like to get percentage change of underlying for the last month, last 2 weeks and YTD without having to manually update the code everytime. Is this possible?
Thanks!
Code:
#follow @KRose_TDA on twitter for updates to this and other custom scripts
#Script below finds the percentage return for the dates inputed
#Enter BegDate and EndDate using YYYYMMDD format (note the dates must
#be market open days Weekends will not work
#You can go back 250 bar days, 105 bar weekly, 110+ bar Monthly
#If you get NAN or other error message, check your dates to make sure they are #trading dates. If that does not correct the problem try using a longer aggregation #like Mo for Month.
input BegDate = 20220103;
input EndDate = 20220902;
def condBegDate = if condBegDate[1] > 0 then condBegDate[1] else if GetYYYYMMDD() == begDate then close else 0;
def condEndDate = if condEndDate[1] > 0 then condEndDate[1] else if GetYYYYMMDD() == endDate then close else 0;
def Pcond = ((condEndDate - condBegDate)/ condBegDate) * 100;
def Days = endDate - begDate;
plot Percnt = (Round(Pcond,2));
Percnt.AssignValueColor(if Percnt > 1.0 then Color.white else if Percnt < -1.0 then Color.white else Color.CURRENT); AssignBackgroundColor(if Percnt > 1.0 then Color.dark_GREEN else if Percnt < -1.0 then Color.dark_RED else Color.CURRENT);
#AddLabel(yes, Concat(Round(Pcond,2), "%"));