//@LibraryID:845,2 //@Name:Improved EPS //@Description:Plots the EPS on the graph, each point can be highlighted by a symbol. // 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: Phil Tolhurst, ShareScope Support var drawMain = true; var drawInterim = true; var drawForecast = true; var drawCircles = true; var drawZero = true; var colour1 = Colour.Red var colour2 = Colour.Red var colour3 = Colour.Red var colour4 = Colour.Black var colour5 = Colour.Black var colour6 = Colour.Grey var pen1 = 0; var pen2 = 1; var pen3 = 1; var pen4 = 0; var width1 = 1; var width2 = 0; var width3 = 0; var width4 = 0; var circSize = 1; var circFilled = false; var circSizeList = ["Small","Medium","Large"]; function init(status) { if (status == Loading || status == Editing) { drawMain = storage.getAt(0); drawInterim = storage.getAt(1); drawForecast = storage.getAt(2); drawCircles = storage.getAt(3); drawZero = storage.getAt(4); colour1 = storage.getAt(5); colour2 = storage.getAt(6); colour3 = storage.getAt(7); colour4 = storage.getAt(8); colour5 = storage.getAt(9); pen1 = storage.getAt(10); pen2 = storage.getAt(11); pen3 = storage.getAt(12); pen4 = storage.getAt(13); width1 = storage.getAt(14); width2 = storage.getAt(15); width3 = storage.getAt(16); width4 = storage.getAt(17); circSize = storage.getAt(18); circFilled = storage.getAt(19); colour6 = storage.getAt(20); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings...",270,115); dlg.addOkButton(); dlg.addCancelButton(); dlg.addTickBox("VAL1",5,5,105,-1,"Year End EPS Line",drawMain); dlg.addColLinePicker("VAL2",120,5,-1,-1,"","",colour1,pen1,width1); dlg.addTickBox("VAL3",5,22,105,-1,"Interim & Quaterly EPS Values",drawInterim); dlg.addColLinePicker("VAL4",120,22,-1,-1,"","",colour2,pen2,width2); dlg.addTickBox("VAL5",5,39,105,-1,"Draw circles at results",drawCircles); dlg.addColPicker("VAL6",120,39,-1,-1,"","",colour5); dlg.addTickBox("VAL12",90,56,30,-1,"Filled",circFilled); dlg.addDropList("VAL7",40,56,45,-1,circSizeList,"Circle Size","",circSize); dlg.addColPicker("VAL13",120,56,-1,-1,"","",colour6); dlg.addTickBox("VAL8",5,73,105,-1,"Show Forecast Y/E Values",drawForecast); dlg.addColLinePicker("VAL9",120,73,-1,-1,"","",colour3,pen3,width3); dlg.addTickBox("VAL10",5,90,105,-1,"Draw line at zero",drawZero); dlg.addColLinePicker("VAL11",120,90,-1,-1,"","",colour4,pen4,width4); if (dlg.show()==Dialog.Cancel) return false; drawMain = dlg.getValue("VAL1"); colour1 = dlg.getValue("VAL2").colour; pen1 = dlg.getValue("VAL2").pen; width1 = dlg.getValue("VAL2").width; drawInterim = dlg.getValue("VAL3"); colour2 = dlg.getValue("VAL4").colour; pen2 = dlg.getValue("VAL4").pen; width2 = dlg.getValue("VAL4").width; drawCircles = dlg.getValue("VAL5"); colour5 = dlg.getValue("VAL6"); circSize = dlg.getValue("VAL7"); drawForecast = dlg.getValue("VAL8"); colour3 = dlg.getValue("VAL9").colour; pen3 = dlg.getValue("VAL9").pen; width3 = dlg.getValue("VAL9").width; drawZero = dlg.getValue("VAL10"); colour4 = dlg.getValue("VAL11").colour; pen4 = dlg.getValue("VAL11").pen; width4 = dlg.getValue("VAL11").width; circFilled = dlg.getValue("VAL12"); colour6 = dlg.getValue("VAL13"); storage.setAt(0, drawMain); storage.setAt(1, drawInterim); storage.setAt(2, drawForecast); storage.setAt(3, drawCircles); storage.setAt(4, drawZero); storage.setAt(5, colour1); storage.setAt(6, colour2); storage.setAt(7, colour3); storage.setAt(8, colour4); storage.setAt(9, colour5); storage.setAt(10, pen1); storage.setAt(11, pen2); storage.setAt(12, pen3); storage.setAt(13, pen4); storage.setAt(14, width1); storage.setAt(15, width2); storage.setAt(16, width3); storage.setAt(17, width4); storage.setAt(18, circSize); storage.setAt(19, circFilled); storage.setAt(20, colour6); } buttonHandle = createButton("Set", onButton0); } function onNewChart() { draw(); } function onBarClose(preExisting) { if (!preExisting) draw(); } function onNewBarUpdate(preExisting) { if (!preExisting) draw(); } function draw() { clearDisplay(); var share=getCurrentShare(); var epsValues = []; var epsDateNum = []; var epsTypes = []; for (var i=3;i>=-40;i--) { var epsValuesTemp = share.getResultArray(i,Result.EPS); if (epsValuesTemp=="") { continue; } var epsDateTemp = share.getResultArray(i,Result.Date); var epsTypesTemp = share.getResultArray(i,Result.Type); var epsDateNumTemp = []; if(epsValuesTemp.length<1) break; for (var j=0;j0) { var newRangeCalc = new MinMax(epsValues.length) for (var m=0;m0) { var minRange = -5; } else { var minRange = newRangeCalc.getMin()*1.05; } if(newRangeCalc.getMax()<0) { var maxRange = 5; } else { var maxRange = newRangeCalc.getMax()*1.05; } setAltRange(minRange,maxRange); useAltRange(true); if(drawZero==true) {//draw 0 line setPenStyle(pen4,width4,colour4); beginPath() for (var a=0;a=0;i--) { if(k<0) break; if(bars[i].dateNum<=epsDateNum[k]) { if (epsTypes[k]=="Final" || epsTypes[k]=="Announced") { if (firstFinal==0) { moveTo(i,epsValues[k]); firstFinal=1; k--; continue; } else { lineTo(i,epsValues[k]); k--; } } else { k-- continue; } } } } if(drawForecast==true) {//draw the forecast EPS line setPenStyle(pen3,width3,colour3) var forecast=0; if (epsTypes[epsValues.length-1]=="Forecast") { for(var k=epsValues.length-1;k>=0;k--) { if (epsTypes[k]=="Forecast" && k==epsValues.length-1) { var forecast=1; moveTo([epsDateNum[k],43200],epsValues[k]); continue; } if (epsTypes[k]=="Forecast") { lineTo([epsDateNum[k],43200],epsValues[k]); continue; } if (epsTypes[k]=="Final" || epsTypes[k]=="Announced" && forecast==1) { lineTo([epsDateNum[k],43200],epsValues[k]); break; } } } } if(drawInterim==true) {//draw the interim EPS line setPenStyle(pen2,width2,colour2); var k = epsValues.length-1; var firstOther=0; for (var i=bars.length-1;i>=0;i--) { if(k<0) break; if(bars[i].dateNum<=epsDateNum[k]) { if(epsTypes[k]!="Special" && epsTypes[k]!="Forecast" || (epsDateNum>bars[bars.length-1].dateNum && epsTypes[k]!="Announced")) { if (firstOther==0) { moveTo(i,epsValues[k]); firstOther=1; k--; continue; } else { if((epsTypes[k]=="Final" || epsTypes[k]=="Announced") && epsTypes[k-1]!=undefined) { lineTo(i,0); moveTo(i,epsValues[k]); } else lineTo(i,epsValues[k]); } } k--; } } } if(drawCircles==true) {//draw the circles if (circSize==0) var size=6; if (circSize==1) var size=10; if (circSize==2) var size=14; setBrushColour(colour6); var k = epsValues.length-1; for (var i=bars.length-1;i>=0;i--) { if(k<0) break; if(bars[i].dateNum<=epsDateNum[k]) { if(epsTypes[k]!="Special" && epsTypes[k]!="Forecast") { if(epsTypes[k]=="Final" && drawMain==true) { setPenStyle(0,width1,colour5); drawSymbol(i,epsValues[k],Symbol.Circle,null,BoxAlign.Center,size,circFilled); if(k!=epsValues.length-1 && epsTypes[k-1]!=undefined && drawInterim==true) { setPenStyle(0,width2,colour5); drawSymbol(i,0,Symbol.Circle,null,BoxAlign.Center,size,circFilled); } } else if(drawInterim==true) { setPenStyle(0,width2,colour5); drawSymbol(i,epsValues[k],Symbol.Circle,null,BoxAlign.Center,size,circFilled); } } k=k-1; } } //draw the forecast circles if(drawForecast==true) { for(var k=epsValues.length-1;k>=0;k--) { if(epsTypes[k]=="Forecast") { setPenStyle(0,width3,colour5); drawSymbol([epsDateNum[k],43200],epsValues[k],Symbol.Circle,null,BoxAlign.Center,size,circFilled); } } } } } } function onButton0() { drawMain = storage.getAt(0); drawInterim = storage.getAt(1); drawForecast = storage.getAt(2); drawCircles = storage.getAt(3); drawZero = storage.getAt(4); colour1 = storage.getAt(5); colour2 = storage.getAt(6); colour3 = storage.getAt(7); colour4 = storage.getAt(8); colour5 = storage.getAt(9); pen1 = storage.getAt(10); pen2 = storage.getAt(11); pen3 = storage.getAt(12); pen4 = storage.getAt(13); width1 = storage.getAt(14); width2 = storage.getAt(15); width3 = storage.getAt(16); width4 = storage.getAt(17); circSize = storage.getAt(18); circFilled = storage.getAt(19); colour6 = storage.getAt(20); dlg = new Dialog("Settings...",270,115); dlg.addOkButton(); dlg.addCancelButton(); dlg.addTickBox("VAL1",5,5,105,-1,"Year End EPS Line",drawMain); dlg.addColLinePicker("VAL2",120,5,-1,-1,"","",colour1,pen1,width1); dlg.addTickBox("VAL3",5,22,105,-1,"Interim & Quaterly EPS Values",drawInterim); dlg.addColLinePicker("VAL4",120,22,-1,-1,"","",colour2,pen2,width2); dlg.addTickBox("VAL5",5,39,105,-1,"Draw circles at results",drawCircles); dlg.addColPicker("VAL6",120,39,-1,-1,"","",colour5); dlg.addTickBox("VAL12",90,56,30,-1,"Filled",circFilled); dlg.addDropList("VAL7",40,56,45,-1,circSizeList,"Circle Size","",circSize); dlg.addColPicker("VAL13",120,56,-1,-1,"","",colour6); dlg.addTickBox("VAL8",5,73,105,-1,"Show Forecast Y/E Values",drawForecast); dlg.addColLinePicker("VAL9",120,73,-1,-1,"","",colour3,pen3,width3); dlg.addTickBox("VAL10",5,90,105,-1,"Draw line at zero",drawZero); dlg.addColLinePicker("VAL11",120,90,-1,-1,"","",colour4,pen4,width4); if (dlg.show()==Dialog.Cancel) return false; drawMain = dlg.getValue("VAL1"); colour1 = dlg.getValue("VAL2").colour; pen1 = dlg.getValue("VAL2").pen; width1 = dlg.getValue("VAL2").width; drawInterim = dlg.getValue("VAL3"); colour2 = dlg.getValue("VAL4").colour; pen2 = dlg.getValue("VAL4").pen; width2 = dlg.getValue("VAL4").width; drawCircles = dlg.getValue("VAL5"); colour5 = dlg.getValue("VAL6"); circSize = dlg.getValue("VAL7"); drawForecast = dlg.getValue("VAL8"); colour3 = dlg.getValue("VAL9").colour; pen3 = dlg.getValue("VAL9").pen; width3 = dlg.getValue("VAL9").width; drawZero = dlg.getValue("VAL10"); colour4 = dlg.getValue("VAL11").colour; pen4 = dlg.getValue("VAL11").pen; width4 = dlg.getValue("VAL11").width; circFilled = dlg.getValue("VAL12"); colour6 = dlg.getValue("VAL13"); storage.setAt(0, drawMain); storage.setAt(1, drawInterim); storage.setAt(2, drawForecast); storage.setAt(3, drawCircles); storage.setAt(4, drawZero); storage.setAt(5, colour1); storage.setAt(6, colour2); storage.setAt(7, colour3); storage.setAt(8, colour4); storage.setAt(9, colour5); storage.setAt(10, pen1); storage.setAt(11, pen2); storage.setAt(12, pen3); storage.setAt(13, pen4); storage.setAt(14, width1); storage.setAt(15, width2); storage.setAt(16, width3); storage.setAt(17, width4); storage.setAt(18, circSize); storage.setAt(19, circFilled); storage.setAt(20, colour6); draw(); }