I am trying to set up a label in my watch list to show the annual return on a stock over the last year. I found a good video
that showed me how to code for annual return based on the current price of a stock vs. the price a year ago - so far, all good.
This is the code that accomplishes that:
input time_period = 252;
def MonthlyPeriod = (close-close[time_period])/close[time_period]*100;
# today's close - close 252 trading days ago ie (100 - # 75) /75 = .33 * 100 = 33.3%
AddLabel(yes, Concat(Round(MonthlyPeriod,2)," %"));
Now I want to add in the amount of any divdends paid over the past year so that the annual return percentage is accurate.
I modified the code as follows and am getting an error:
input time_period = 252;
def MonthlyPeriod = (close-close[time_period] + DividendsPerShareTTM )/close[time_period]*100;
AddLabel(yes, Concat(Round(MonthlyPeriod,2)," %"));
Since the only difference in the 2 snippets is the "DividendsPerShareTTM" I think that I must be using the function improperly or have failed to use the * sign correctly.
Any suggestions or substitute code would be very much appreciated. I hate to join a community and have my first post be seeking help, but at this point I don't have much to offer here.
Art
This is the code that accomplishes that:
input time_period = 252;
def MonthlyPeriod = (close-close[time_period])/close[time_period]*100;
# today's close - close 252 trading days ago ie (100 - # 75) /75 = .33 * 100 = 33.3%
AddLabel(yes, Concat(Round(MonthlyPeriod,2)," %"));
Now I want to add in the amount of any divdends paid over the past year so that the annual return percentage is accurate.
I modified the code as follows and am getting an error:
input time_period = 252;
def MonthlyPeriod = (close-close[time_period] + DividendsPerShareTTM )/close[time_period]*100;
AddLabel(yes, Concat(Round(MonthlyPeriod,2)," %"));
Since the only difference in the 2 snippets is the "DividendsPerShareTTM" I think that I must be using the function improperly or have failed to use the * sign correctly.
Any suggestions or substitute code would be very much appreciated. I hate to join a community and have my first post be seeking help, but at this point I don't have much to offer here.
Art