 and I wanted to look at this dividend return script okay that was as promised in the video and the SNPs 500 sectors and I will share these scripts with you guys in the comments below as well I'll do a little refresher on how to share scripts so let's see if we can cover this dividend script as well so we what we want is again this is script for calculating return return from price and dividend okay so since we've been looking at these return scripts I thought it was a natural script to go and end this video with you define a close you know call it close x or whatever and this is going to be the first close so the first close that you find on your way back you know that is the first close that we have right now and then you're also going to define a total dividend right and the total dividend is going to be whatever the dividend is right now plus the dividend function which is getDividend but if it is not a number then we just assign it a value of zero because if there's something weird or odd with the dividend that we don't want to return some weird value and then screw up our our script so if it's you know if it's not a number right if getDividend returns something that is not a number then we would just give total dividend the value of zero otherwise we will actually get that dividend and add it to whatever the current dividend is okay so now what is the price return going to be it's going to be and this is the long format it's going to be whatever today's close is minus the close you know a certain time period back and divided by that close and we multiply that by 100 and we give it two decimals just as before and now the dividend return if that total div which we calculated above is greater than zero then it makes sense we're going to use it so then do a rounding function on the total total dividend paid out right so this is this is the dollar value of dividends also divided by the close right by that first close because that's going to give us the actual dividend return over the investment which was originally close x okay and else that means that you know dividend is zero so you won't get a dividend so what we're going to return is a label which is immediately visible and the price return is this price return calculated up here which you which we've already seen how to do plus we tag on that percent and then the dividend return is going to be whatever dividend return we calculated above plus that percent and then the total return is going to be the sum of both of those and rounded to two decimal points okay so let's go ahead and save the script because we modified it a little bit and let's go see what that looks like so we come over here to charts and remember we have our average volume study displaying here so I'm actually going to remove that one just so we don't start where's our average volume here it is okay average volume actually you know what I wanted to show you guys something since I'm here if you go over here and you hit the cog wheel you can actually modify whatever script variables you coded as being modifiable and in this case you know we be defined the the symbol variable as an input type Tesla which means that you know the user can come in here and type in whatever he wants of course that doesn't didn't make much sense in that script so I didn't I didn't go into it but there's other things that you can change such as or they can have the user modify such as moving average time periods and whatnot okay so we're going to remove that and we're actually going to add in our year dividend something something here your dividend price okay so let's drag that into it gets added it adds it it knows exactly where to add it okay so let's hit apply and there is our red label okay and that is we are getting a 26% negative return for Pfizer which is obviously a very bearish graph as you can clearly see but it does return a 3.2 so you can immediately see that you're getting an actual negative 23% return in this case for Pfizer I wanted to look over the script that we just created right the dividend yearly price script so what we have here is a monthly is a daily chart sorry let me actually go back to the script if you recall we covered a couple of new things here the first function right and this re rec or which stands for recursion right so you can right click over here on this first function and then go down info and it'll tell you what it does it returns value of the parameter expression in the first bar okay and what that does is it's actually going to look at the close and it's going to look at the first bar close value for whatever time frame you are looking at alright and that makes it different from our previous scripts where we actually hard-coded if you will the number of of bars that you wanted to go back and look so this is a little bit more dynamic way to to code in think script alright so we're looking at the first bar if you will on a daily chart would be a daily bar on a 50 minute chart would be a 50 minute bar on one hour chart would be a one hour bar so on and so forth okay so that is what the first close is giving us which can come in handy right with a lot of the different parameters that we used to program that is what the first function does alright and the other thing that we looked at was the rec which is the recursion one okay and recursion goes back and does the same thing it looks for it does say it carries out a particular function in the past of historical values right and eventually we'll get to the fold command but this is a similar way to go back and get data and but in a little simpler way because the fold function actually allows you to do some calculations and include conditions and other variables and whatnot their recursion one is a little bit simpler because it just goes back and fetches some values so the recursion we used it for the total dividend right which is different what we wanted to do was not just you know get you know the the first bar close here and then the no one now but we also in the total dividend we wanted to recurse back if you will right so we wanted to go get historical values or reference historical values which in this case were dividend values which were given to us by the get dividend function right so now we basically went back in time and we got the historical dividends right the ones that are within this time frame window that we're looking at that is what the recursion function does alright so we now calculate the price return and the dividend return right based on the data that we have collected so far and we plotted on the chart this is what it looks like again this is the daily one month right and there it is the one month time window or frame and then it goes with daily bars it can't you count back 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 22 bars so there's 22 you know bars here in this month that that it is counting and if you notice the price return label up here we're returning we're returning an actual positive return which is 0.87 percent right and the dividend return is 0 because there has been no dividend this time window and the total return is obviously then going to be just the point 87 given to us by the price return what that means is this if it opens here at 3704 right that would be our starting price 3704 for this window and it goes up to about here which is 3721 so it went up about 16 17 points right so that would be a 0.87 return on the price okay and because it's only one month let me see if well it's not gonna work on the five minute that's gonna be worse but three months let's see if we cover three months and I want you to watch the difference because you see how this dividend here has not yet been paid so that's gonna be paid on 7 27 today is July 26th so dividend is actually going to be paid tomorrow so tomorrow this is going to change I'm gonna try to remember and come back and and do the same chart so we can look at the difference between right now which is only a 0% return for the dividend but we can go back here and look at that three month and now look at the results so now we have a dividend that was actually paid back here on 5 11 which is May 11 41 set dividend so now our price return must include that dividend calculation right the dividend calculation is now 1.07% as you can see on our label and the price is is now negative negative 2.64 so if it weren't for this dividend we would be in worse shape than we are so to speak because now instead of the negative 264 2.64% from the price we only have negative 1.57 I think it is because you take the minus 264 but you add the 1.07 and you get an actual negative 157 which is less negative than we otherwise would have had now if you go to six months it's obviously worse it's a minus 15% return from the price and even though the dividend return is has jumped from 187 to 1 from 107 to 187 because now you have two dividends right your total return is still negative if you go to the one year well that's the one we originally saw which was negative 26% right and even though the dividend return again is now including one two three dividends right it's the total return is still going to be negative overall negative 23 so that is how the dividend price return script works and we're going to be looking at some some of these functions again later on in different scripts so you get a better feel for how they work all right so as promised there is the dividend price right and we will be looking at more scripts in the videos to videos to come so don't forget to subscribe to the YouTube channel and drop your comments and your likes and whatever it is that you want to see in future videos so I hope you enjoyed this video and I will see you in the next one where I hope to finally get to the S&P 500 sectors and labels and a lot more stuff that I'm going to throw in there for you guys so hope you enjoyed it and have a great day see you on the next trading day hey guys so I did remember and here we are looking at Pfizer again and remember I was going to update you on the dividend return which was the script that we made earlier and as you can clearly see now the price return is 53 that's lower because it dropped somewhat as you can clearly see today but the on the plus side we now have a dividend return of 114 because today dividend was paid and so now the total return is 1.6 something