//@LibraryID:806,0 //@Name:Trade Count //@Description:Displays the trade count for a given number of trading days. //@Returns:Number //@Update:Periodic, 60 //@Width:80 //@Env:Production // Author: Phil Tolhurst, ShareScript Support // 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. var period = 5; var incToday = 1; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); incToday = storage.getAt(1); } if (status == Adding || status == Editing) { dlg = new Dialog("Select number of trading days",165,50); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",8,-1,-1,-1,"","Trading Days",period,2,1000); dlg.addTickBox("VAL2",8,-1,80,-1,"Include Today's Data",incToday); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("VAL1"); incToday = dlg.getValue("VAL2"); storage.setAt(0, period); storage.setAt(1, incToday); } //sets the title of the column setTitle("Trade Count for "+period+"tds"+(incToday==1?"(inc.)":"(ex.)")); } function getVal(share) { var mainTradeArray = []; for (var i = period;i>=(incToday==1?1:0);i--) { var tempTradeArray = share.getITradeArray(i); if(tempTradeArray!=undefined) { mainTradeArray = mainTradeArray.concat(tempTradeArray); } } return mainTradeArray.length }