//@Name:Bid/Offer at Close //@Description:Returns the bid or offer at close for the selected day. If no close bid/offer is available the script will return null. //@Returns:Number //@Width:60 //@Env:Production // 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 inputDate = new Date(); var inputType = 0; function init(status) { if (status == Loading || status == Editing) { inputType = storage.getAt(0); inputDate = new Date(dateNumGetYear(storage.getAt(1)),dateNumGetMonth(storage.getAt(1)),dateNumGetDay(storage.getAt(1))); } if (status == Adding || status == Editing) { dlg = new Dialog("Select date...", 155, 55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,80,-1,["Bid","Offer"],"","",inputType); dlg.addDatePicker("DP1",8,-1,-1,-1, "", "", inputDate); if (dlg.show()==Dialog.Cancel) return false; inputType = dlg.getValue("DL1"); inputDate = dlg.getValue("DP1"); storage.setAt(0, inputType); storage.setAt(1, dateNum(inputDate)); } setTitle("Closing "+(inputType?"Offer":"Bid")+" on "+dateToString(inputDate)); } function getVal(share) { var data = share.getIBidOfferArrayOnDate(inputDate); var closeTime = share.getMarketCloseTime(); var closeBid; if (data == undefined || data.length<2) return closeBid; for (var i=1;i=closeTime) { if (inputType==0) closeBid = data[i-1].bid; else closeBid = data[i-1].offer; break; } } return closeBid; } function dateToString(date) { var day = String(date.getDate()); var dateStr = (day.length==1) ? ('0'+day) : day; dateStr += '/'; var month = String(1+date.getMonth()); dateStr += (month.length==1) ? ('0'+month) : month; dateStr += '/'; var year = String(date.getFullYear()); dateStr += (year[2]+year[3]); return dateStr; }