//@Name:Total Return //@Description:Overlays a total return line to the graph. Dividends are counted from the ex-dividend date. // Care has been taken in preparing this code but it is provided without guarantee. // You are welcome to modify and extend it. Please add your name as a modifier if you distribute it. //Coded by: Richard Chiesa, ShareScript Support var exDates = []; var divAmount = []; var divType = []; function onNewChart() { exDates = []; divAmount = []; divType = []; var share = getCurrentShare() if (share==null) return; for (var i=-25;i<=1;i++) { exDates = exDates.concat(share.getResultArray(i,Result.ExDivDate)); divAmount = divAmount.concat(share.getResultArray(i,Result.Dividend)); divType = divType.concat(share.getResultArray(i,Result.Type)); } for (var i=divAmount.length;i>0;i--) { if (divType[i] == "Announced" || divType[i] == "Final" || divType[i] == "Q3" || (divType[i] == "Interim" && divType[i-1] == "Q1")) { if (divType[i-1]=="Special") divAmount[i] -= divAmount[i-2]; else divAmount[i] -= divAmount[i-1]; } } //remove any blank pay dates for (i=0;i=bars[s].date) break; } moveTo(s,bars[s].close); for (var i=s;i<=f;i++) { if (divi=exDates[divi]) { totDividend += divAmount[divi]; divi++; } lineTo(i,bars[i].close+totDividend); } if (getBarLength() == "1d") var yield = ((Math.pow(totDividend/bars[s].close+1,252/(f-s))-1)*100).toFixed(2); else if (getBarLength() == "1w") var yield = ((Math.pow(totDividend/bars[s].close+1,52/(f-s))-1)*100).toFixed(2); else if (getBarLength() == "1m") var yield = ((Math.pow(totDividend/bars[s].close+1,12/(f-s))-1)*100).toFixed(2); else var yield = "-"; setTitle("Annualised Yield: "+yield+"%"); setInfoText("The yield is based on the total \ndividend paid over the period \nand the closing price on the \nleftmost date on the graph.\nTotal Dividend :"+ totDividend.toFixed(2)+"\nClose: "+bars[s].close.toFixed(2)); }