//@Name:BBand / price % //@Description:Returns the % change between the current mid price and the the upper or lower Bollinger Band //@Returns:Number //@Env:Production // Author: 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 maList = ["Simple","Exponential","Weighted","Triangular","VariableVHF","VariableCMO","VIDYA"]; var maTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA","TEMA"]; var MAtype = 0; var outputType = 0; var period = 20; var devs = 1.5; function init(status) { if (status == Loading || status == Editing) { MAtype = storage.getAt(0); period = storage.getAt(1); devs = storage.getAt(2); outputType = storage.getAt(3); } if (status == Adding || status == Editing) { dlg = new Dialog("Setup...", 155, 70); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,80,-1,maList,"","",MAtype); dlg.addIntEdit("INT1",8,-1,-1,-1,"","period",period,2,1000); dlg.addNumEdit("NUM1",8,-1,-1,-1,"","standard devs.",devs,0,100); dlg.addDropList("DL2",8,-1,80,-1,["Upper Band","Lower Band"],"","",outputType); if (dlg.show()==Dialog.Cancel) return false; MAtype = dlg.getValue("DL1"); period = dlg.getValue("INT1"); devs = dlg.getValue("NUM1"); outputType = dlg.getValue("DL2"); storage.setAt(0, MAtype); storage.setAt(1, period); storage.setAt(2, devs); storage.setAt(3, outputType); } setTitle((outputType?"Lower ":"Upper ")+period+" "+maTitleList[MAtype]+","+devs+" devs BBand / price %"); } function getVal(share) { var data = share.getPriceArray(period*4); if (data == undefined || data.length data[data.length-1].date) data[data.length] = iPrice[0]; var ma1 = new MA(period, MAtype); var av1 = []; var y1 = []; var v1 = []; var i = Math.max(data.length-(period*3), 0); for (i;i