//@Name:Average EPS Growth //@Description:Returns the average of a range of yearly EPS growth % values //@Returns:Number //@Width:60 //@Env:Production var year1 = 0; var year2 = -1; var ignoreNegs = true; function init(status) { if (status == Loading || status == Editing) { year1 = storage.getAt(0); year2 = storage.getAt(1); ignoreNegs = storage.getAt(2); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings...", 190, 78); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","Year 1",year1,-10,3); dlg.addIntEdit("INT2",8,-1,-1,-1,"","Year 2",year2,-10,3); dlg.addTickBox("TB2",8,-1,120,-1,"Ignore negative EPS values",ignoreNegs); dlg.addText(8,50,170,25,"Use 0 for current value, 1 for 1 year forecast or -3 for 3 years ago.\nMake sure that Year 1 is larger than Year 2."); if (dlg.show()==Dialog.Cancel) return false; year1 = dlg.getValue("INT1"); year2 = dlg.getValue("INT2"); ignoreNegs = dlg.getValue("TB2"); storage.setAt(0, year1); storage.setAt(1, year2); storage.setAt(2, ignoreNegs); } } function getVal(share) { if (year1=year2;i--) { //gets the two eps values var eps1 = share.getResult(i, Result.EPS); var eps2 = share.getResult(i-1, Result.EPS); //if ignore option is ticked and eps is negative, terminate script if (ignoreNegs && (eps1<0 || eps2<0)) return; //calculates each individual growth value growth[growth.length] = (eps1 / eps2 - 1) * 100; //adds the growth to the total growth sum totGrowth += growth[growth.length-1]; } //divides the total growth by the number of growth values to obtain the average var avGrowth = totGrowth/growth.length; return avGrowth; }