//@Name:Volatility/Spread Ratio //@Description:Displays the ratio between the share's volatility and the bid/offer spread % //@Returns:Number //@Update:Intraday //@Width:60 // Coded by: Richard Chiesa, 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 = 20; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); } if (status == Adding || status == Editing) { dlg = new Dialog("Setup",150,50); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","Volatility period",period,2,5000); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("INT1"); storage.setAt(0, period); } setTitle(period+" Volatility / Spread Ratio"); } function getVal(share) { var data = share.getPriceArray(period*6); if (data.length<2) return; var idata = share.getIBarArray(0,86400); if (idata!=undefined && idata.length==1 && new Date().getDate()==idata[0].date.getDate() && new Date().getDate()!=data[data.length-1].date.getDate()) { var tclose = share.getIClose(); var topen = share.getIOpen(); data[data.length]={open:(topen==null?idata[0].open:topen),high:idata[0].high,low:idata[0].low,close:(tclose==null?share.getIMid():tclose),volume:idata[0].volume}; } var vol1 = new Volatility(period); for (var i=0;i