//@LibraryID:200,0 //@Name:Keltner //@Description:Keltner channel indicator with 3 sets of editable bands // Author: 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","TEMA"]; var MAtype = 1; var maPeriod = 10; var atrPeriod = 10; var bandMult1 = 1; var bandMult2 = 2; var bandMult3 = 3; var lineCol1 = Colour.RGB(0,200,200); var lineStyle1 = Pen.Solid; var lineWidth1 = 0; var lineCol2 = Colour.RGB(235,170,0); var lineStyle2 = Pen.Solid; var lineWidth2 = 1; var lineStore = 0; var periods = 0; function init(status) { if (status == Loading || status == Editing) { if(storage.getAt(1)<1000000) {//if the script exists load settings from MAtype = storage.getAt(0); maPeriod = storage.getAt(1); keltnerPeriod = storage.getAt(2); bandMult1 = storage.getAt(3); bandMult2 = storage.getAt(4); bandMult3 = storage.getAt(5); lineCol1 = storage.getAt(6); lineCol2 = storage.getAt(7); } else { MAtype = storage.getAt(0); periods = storage.getAt(1); lineStore = storage.getAt(2); bandMult1 = storage.getAt(3); bandMult2 = storage.getAt(4); bandMult3 = storage.getAt(5); lineCol1 = storage.getAt(6); lineCol2 = storage.getAt(7); periods=periods.toString(); maPeriod = parseInt(periods.substr(1,3),10); atrPeriod = parseInt(periods.substr(4,3),10); lineStore=lineStore.toString(); lineStyle1 = parseInt(lineStore.substr(0,1),10)-1; lineWidth1 = parseInt(lineStore.substr(1,1),10)-1; lineStyle2 = parseInt(lineStore.substr(2,1),10)-1; lineWidth2 = parseInt(lineStore.substr(3,1),10)-1; } } if (status == Adding || status == Editing) { dlg = new Dialog("Keltner Bands",160,140); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",8,-1,80,-1,maList,"","",MAtype); dlg.addIntEdit("VAL2",8,-1,-1,-1,"","MA period",maPeriod,2,1000); dlg.addIntEdit("VAL3",8,-1,-1,-1,"","Keltner period",atrPeriod,2,1000); dlg.addNumEdit("VAL4",8,-1,-1,-1,"","1st Band",bandMult1,0,10); dlg.addNumEdit("VAL5",8,-1,-1,-1,"","2nd Band",bandMult2,0,10); dlg.addNumEdit("VAL6",8,-1,-1,-1,"","3rd Band",bandMult3,0,10); dlg.addColLinePicker("VAL7",8,-1,-1,-1,"","MA Line",lineCol1,lineStyle1,lineWidth1); dlg.addColLinePicker("VAL8",8,-1,-1,-1,"","Keltner Bands",lineCol2,lineStyle2,lineWidth2); if (dlg.show()==Dialog.Cancel) return false; MAtype = dlg.getValue("VAL1"); maPeriod = dlg.getValue("VAL2"); atrPeriod = dlg.getValue("VAL3"); bandMult1 = dlg.getValue("VAL4"); bandMult2 = dlg.getValue("VAL5"); bandMult3 = dlg.getValue("VAL6"); lineCol1 = dlg.getValue("VAL7").colour; lineStyle1 = dlg.getValue("VAL7").pen; lineWidth1 = dlg.getValue("VAL7").width; lineCol2 = dlg.getValue("VAL8").colour; lineStyle2 = dlg.getValue("VAL8").pen; lineWidth2 = dlg.getValue("VAL8").width; periods = 1000000+maPeriod*1000+atrPeriod; lineStore = (lineStyle1+1)*1000+(lineWidth1+1)*100+(lineStyle2+1)*10+(lineWidth2+1); storage.setAt(0, MAtype); storage.setAt(1, periods); storage.setAt(2, lineStore); storage.setAt(3, bandMult1); storage.setAt(4, bandMult2); storage.setAt(5, bandMult3); storage.setAt(6, lineCol1); storage.setAt(7, lineCol2); } setRange(Range.Parent); //sets the same data range as the main gaph setSeriesColour(0, lineCol1); setSeriesLineStyle(0, lineStyle1, lineWidth1); setSeriesColour(1, lineCol2); setSeriesLineStyle(1, lineStyle2, lineWidth2); setSeriesColour(2, lineCol2); setSeriesLineStyle(2, lineStyle2, lineWidth2); setSeriesColour(3, lineCol2); setSeriesLineStyle(3, lineStyle2, lineWidth2); setSeriesColour(4, lineCol2); setSeriesLineStyle(4, lineStyle2, lineWidth2); setSeriesColour(5, lineCol2); setSeriesLineStyle(5, lineStyle2, lineWidth2); setSeriesColour(6, lineCol2); setSeriesLineStyle(6, lineStyle2, lineWidth2); } function getGraph(share, data) { var ma1 = new MA(maPeriod, MAtype); //the 10 sma of the typical average price var ma2 = new MA(atrPeriod, MAtype); //the 10 sma of the high-low range var sma = new Array(); //the array of SMA values var atr1 = new ATR(atrPeriod); var atrValues = new Array(); var upperBand1 = new Array(); //the array of the upper Keltner band var upperBand2 = new Array(); var upperBand3 = new Array(); var lowerBand1 = new Array(); //the array of the lower Keltner band var lowerBand2 = new Array(); var lowerBand3 = new Array(); //the for loop runs from the first PriceData element to the last for (var i=0; i