//@Name:Average Spread //@Description:Returns the average spread taken at a specified time over a specified number of days - does not include the current day. Note: It does NOT use today's spread value and does not refresh on an intraday value. This means it should work in data-mining. //@Returns:number //@Env:Production //@Width:50 // 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 numDays = 5; var hour = 12; var minute = 30; function init(status) { if (status == Loading || status == Editing) { numDays = storage.getAt(0); hour = storage.getAt(1); minute = storage.getAt(2); } if (status == Adding || status == Editing) { var dlg = new Dialog("Settings...",280,75); dlg.addOkButton(); dlg.addCancelButton(); dlg.addNumEdit("VAL1",65,5,-1,-1,"Number of days:","",numDays,1,50); dlg.addNumEdit("VAL2",65,22,20,-1,"Time:","",hour,0,23); dlg.addNumEdit("VAL3",93,22,20,-1,":","",minute,0,59); dlg.addText(5,39,200,10,"Note: Time uses a 24hr clock i.e. the LSE closes at 16:30"); if (dlg.show()==Dialog.Cancel) return false; numDays = dlg.getValue("VAL1"); hour = dlg.getValue("VAL2"); minute = dlg.getValue("VAL3"); storage.setAt(0, numDays); storage.setAt(1, hour); storage.setAt(2, minute); } setTitle(numDays+" trading day avg spread% taken at "+hour+":"+minute); } function getVal(share) { var avgSum = 0; //Turn the time specified by the user into a TimeNum var time = (hour*3600)+(minute*60); for(var i=1;i=0;j--) { if(quoteData[j].timeNum == time || (jtime))) { avgSum = avgSum + (quoteData[j].offer/quoteData[j].bid-1)*100; break; } } } } } return (avgSum/numDays).toFixed(3); }