//@Name:BandWidth //@Description:Returns the distance between two Bollinger Bands as a % of Close, % of the MA or % of the MA of the HL range /* Author: ShareScript Support The script returns the value of the BB convergence expressed either as a % of the close or as a % of the average HL spread. You can change the output by either chosing result1 or result2 in the return line at the bottom of the script */ // 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","TEMA"]; var maTitleList = ["SMA","EMA","WMA","TMA","VVHF","VCMO","VIDYA","TEMA"]; var dataList = ["Daily","Weekly","Monthly"]; var period = 20; var devs = 1.5; var MAtype = 0 var outputType = 0; var lineCol = Colour.RGB(255,190,0); var lineStyle = Pen.Solid; var lineWidth = 1; function init(status) { if (status == Loading || status == Editing) { MAtype = storage.getAt(0); outputType = storage.getAt(1); period = storage.getAt(2); devs = storage.getAt(3); lineCol = storage.getAt(4); lineStyle = storage.getAt(5); lineWidth = storage.getAt(6); } if (status == Adding || status == Editing) { var dlg = new Dialog("Settings...",160,105); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("DL1",8,-1,80,-1,maList,"","",MAtype); dlg.addDropList("DL2",8,-1,80,-1,["% of Close","% of MA","% of HL range"],"","",outputType); dlg.addNumEdit("INT1",8,-1,-1,-1,"","Period",period,2,1000); dlg.addNumEdit("NUM1",8,-1,-1,-1,"","St. Devs.",devs,0.5,5); dlg.addColLinePicker("LN1",8,-1,-1,-1,"","",lineCol,lineStyle,lineWidth); if (dlg.show()==Dialog.Cancel) return false; MAtype = dlg.getValue("DL1"); outputType = dlg.getValue("DL2"); period = dlg.getValue("INT1"); devs = dlg.getValue("NUM1"); lineCol = dlg.getValue("LN1").colour; lineStyle = dlg.getValue("LN1").pen; lineWidth = dlg.getValue("LN1").width; storage.setAt(0, MAtype); storage.setAt(1, outputType); storage.setAt(2, period); storage.setAt(3, devs); storage.setAt(4, lineCol); storage.setAt(5, lineStyle); storage.setAt(6, lineWidth); } if (outputType==0) var outputTxt = "Close"; else if (outputType==1) var outputTxt = "MA"; else var outputTxt = "HL range"; setTitle(period+" "+maTitleList[MAtype]+","+devs+" devs BandWidth as % of "+outputTxt); setSeriesLineStyle(0, lineStyle, lineWidth); setSeriesColour(0, lineCol); } function getGraph(share, data) { var ma1 = new MA(period, MAtype); //type of MA var v1 = new Array(); var av1 = new Array(); var av2 = new Array(); var y1 = new Array(); var result1 = new Array(); var result2 = new Array(); var result3 = new Array(); var ma2 = new MA(period); for (var i=period;i