//@Name:ADV Change //@Description:Returns the change between to average daily volume figures from two specified dates either in percentage or absolute terms. //@Returns:Number //@Width:125 // 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. // Author: Phil Tolhurst, ShareScope Support var ADVperiod1 = 21; var ADVperiod2 = 21; var ADVdate1 = new Date(new Date()-86400000); var ADVdate2 = new Date(new Date()-864000000) var outputList = ["Pecentage Change","Absolute Change"]; var outputChoice = 0; function init(status) { if (status == Loading || status == Editing) { ADVperiod1 = storage.getAt(0); ADVperiod2 = storage.getAt(1); ADVdate1 = storage.getAt(2); ADVdate2 = storage.getAt(3); outputChoice = storage.getAt(4); } if (status == Adding || status == Editing) { dlg = new Dialog("Change between to ADVs....",270,100); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",63,5,-1,-1,"From ADV period:","",ADVperiod1,2,1000); dlg.addDatePicker("VAL2",125,5,-1,-1, "on date:","",new Date(ADVdate1)); dlg.addIntEdit("VAL3",63,39,-1,-1,"To ADV period:","",ADVperiod2,2,1000); dlg.addDatePicker("VAL4",125,39,-1,-1, "on date:","",new Date(ADVdate2)); dlg.addDropList("VAL5",55,73,80,-1,outputList,"Return the:","",outputChoice); if (dlg.show()==Dialog.Cancel) return false; ADVperiod1 = dlg.getValue("VAL1"); ADVdate1 = dlg.getValue("VAL2"); ADVperiod2 = dlg.getValue("VAL3"); ADVdate2 = dlg.getValue("VAL4"); outputChoice = dlg.getValue("VAL5"); storage.setAt(0, ADVperiod1); storage.setAt(1, ADVperiod2); storage.setAt(2, ADVdate1); storage.setAt(3,ADVdate2); storage.setAt(4, outputChoice); } var titleDate1 = (ADVdate1.getDate()<10?"0"+ADVdate1.getDate():ADVdate1.getDate())+":"+ (ADVdate1.getMonth()+1<10?"0"+(ADVdate1.getMonth()+1):ADVdate1.getMonth()+1)+":"+(ADVdate1.getYear()-100); var titleDate2 = (ADVdate2.getDate()<10?"0"+ADVdate2.getDate():ADVdate2.getDate())+":"+ (ADVdate2.getMonth()+1<10?"0"+(ADVdate2.getMonth()+1):ADVdate2.getMonth()+1)+":"+(ADVdate2.getYear()-100); setTitle(titleDate1+" ADV("+ADVperiod1+")"+(outputChoice?" - ":" / ")+titleDate2+" ADV("+ADVperiod2+")"+(outputChoice?" m":" %")); } function getVal(share) { var data = share.getPriceArray(); var advCalc1 = new MA(ADVperiod1); var advRes1; var advCalc2 = new MA(ADVperiod2); var advRes2; var advOutput1; var testDate1 = dateNum(ADVdate1.getFullYear(),ADVdate1.getMonth(),ADVdate1.getDate()) var advOutput2; var testDate2 = dateNum(ADVdate2.getFullYear(),ADVdate2.getMonth(),ADVdate2.getDate()) if (data.length<(ADVperiod1>ADVperiod2?ADVperiod1:ADVperiod2)) return; for (var i=0;i= testDate1 && advOutput1 == undefined) advOutput1 = advRes1; if(data[i].dateNum>= testDate2 && advOutput2 == undefined) advOutput2 = advRes2; } if(outputChoice == 1) { return((advOutput1-advOutput2)/1000000).toFixed(2); } else return(((advOutput1-advOutput2)/advOutput1)*100).toFixed(2); }