//@Name:12mth Rolling Result //@Description:Returns the 12 month rolling value of the chosen result. This is calculated by adding the 4 most recent quarters or the 2 most recent halves. //@Returns:Number //@Width:60 // 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 outputType = 0; var outputList = ["Profit","Turnover","EPS","Dividend","Yield","P/E"]; function init(status) { if (status == Loading || status == Editing) { outputType = storage.getAt(0); } if (status == Adding || status == Editing) { dlg = new Dialog("Select Result", 145, 55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,80,-1,outputList,"","",outputType); if (dlg.show()==Dialog.Cancel) return false; outputType = dlg.getValue("DL1"); storage.setAt(0, outputType); } setTitle("12mth Rolling "+outputList[outputType]); } function getVal(share) { if (outputType==0) var resArray = share.getResultArray(-1,Result.Profit).concat(share.getResultArray(0,Result.Profit)).concat(share.getResultArray(1,Result.Profit)); if (outputType==1) var resArray = share.getResultArray(-1,Result.Turnover).concat(share.getResultArray(0,Result.Turnover)).concat(share.getResultArray(1,Result.Turnover)); if (outputType==2 || outputType==5) var resArray = share.getResultArray(-1,Result.EPS).concat(share.getResultArray(0,Result.EPS)).concat(share.getResultArray(1,Result.EPS)); if (outputType==3 || outputType==4) var resArray = share.getResultArray(-1,Result.Dividend).concat(share.getResultArray(0,Result.Dividend)).concat(share.getResultArray(1,Result.Dividend)); var resType = share.getResultArray(-1,Result.Type).concat(share.getResultArray(0,Result.Type)).concat(share.getResultArray(1,Result.Type)); var output = 0; for (var i=0;i=0;i--) { if (resType[i]=="Q1" || (resType[i] == "Interim" && resType[i-1] == "Final")) output+=resArray[i]; if (resType[i] == "Announced" || resType[i] == "Final" || resType[i] == "Q3" || (resType[i] == "Interim" && resType[i-1] == "Q1")) output+=(resArray[i]-resArray[i-1]); if (resType[i-1] == resType[resType.length-1] || (resType[i-1] == "Final" && resType[resType.length-1] == "Announced")) break; } if (outputType==4) return (output/share.getClose()*100).toFixed(2); else if (outputType==5) { if (output<=0) return 0; var pe = share.getClose()/output; if (pe>500) pe == 500; return pe; } return output; }