//@Name:S22-Elder's AutoEnvelope Values //@Description:Draws Elder's Auto Envelope and prints the current values in the Title Banner var period = 22; //MA period var sdPeriod = 100; //The lookback period var factor= 2.7; //number of standard deviations var LineCol1 = Colour.Red; var LineStyle1 = Pen.Solid; var LineWidth1 = 0; var LineCol2 = Colour.Black; var LineStyle2 = Pen.Solid; var LineWidth2 = 0; var LineCol3 = Colour.Blue; var LineStyle3 = Pen.Solid; var LineWidth3 = 0; var upperOption = 1; var maOption = 1; var lowerOption = 1; function init(status) { if (status==Loading || status==Editing) { period = storage.getAt(0); sdPeriod = storage.getAt(1); factor = storage.getAt(2); LineCol1 = storage.getAt(3); LineStyle1 = storage.getAt(4); LineWidth1 = storage.getAt(5); LineCol2 = storage.getAt(6); LineStyle2 = storage.getAt(7); LineWidth2 = storage.getAt(8); LineCol3 = storage.getAt(9); LineStyle3 = storage.getAt(10); LineWidth3 = storage.getAt(11); upperOption = storage.getAt(12); maOption = storage.getAt(13); lowerOption = storage.getAt(14); } if (status==Adding || status==Editing) { var dlg = new Dialog((status==Adding?"Add":"Edit")+" indicator",165,120) dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",5,5,-1,-1,"","EMA period",period,2,1000); dlg.addIntEdit("INT2",5,22,-1,-1,"","Lookback period",sdPeriod,2,1000); dlg.addNumEdit("INT3",5,39,-1,-1,"","Std Devs",factor,2,1000); dlg.addTickBox("TK1",5,58,15,-1,"",upperOption); dlg.addColLinePicker("CL1",20,56,-1,-1,"","Upper Line",LineCol1,LineStyle1,LineWidth1); dlg.addTickBox("TK2",5,75,15,-1,"",maOption); dlg.addColLinePicker("CL2",20,73,-1,-1,"","MA Line",LineCol2,LineStyle2,LineWidth2); dlg.addTickBox("TK3",5,92,15,-1,"",lowerOption); dlg.addColLinePicker("CL3",20,90,-1,-1,"","Lower Line",LineCol3,LineStyle3,LineWidth3); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("INT1"); sdPeriod = dlg.getValue("INT2"); factor = dlg.getValue("INT3"); LineCol1 = dlg.getValue("CL1").colour; LineStyle1 = dlg.getValue("CL1").pen; LineWidth1 = dlg.getValue("CL1").width; LineCol2 = dlg.getValue("CL2").colour; LineStyle2 = dlg.getValue("CL2").pen; LineWidth2 = dlg.getValue("CL2").width; LineCol3 = dlg.getValue("CL3").colour; LineStyle3 = dlg.getValue("CL3").pen; LineWidth3 = dlg.getValue("CL3").width; upperOption = dlg.getValue("TK1"); maOption = dlg.getValue("TK2"); lowerOption = dlg.getValue("TK3"); storage.setAt(0, period); storage.setAt(1, sdPeriod); storage.setAt(2, factor); storage.setAt(3, LineCol1); storage.setAt(4, LineStyle1); storage.setAt(5, LineWidth1); storage.setAt(6, LineCol2); storage.setAt(7, LineStyle2); storage.setAt(8, LineWidth2); storage.setAt(9, LineCol3); storage.setAt(10, LineStyle3); storage.setAt(11, LineWidth3); storage.setAt(12, upperOption); storage.setAt(13, maOption); storage.setAt(14, lowerOption); } } function onNewChart() { //calls the draw function when a new chart is displayed draw(); } function onNewBarUpdate() { //calls the draw function when the current chart updates with a new price draw(); } function draw() { clearDisplay(); var ma1 = new MA(period, MA.Exponential); //Setup of EMA, from which the envelopes will be set. var w = new Array(); var envelope //envelope size var x //standard deviation intermidiate value var av1 = new Array(); var upperEnvelope = new Array(); //the upper envelope array var lowerEnvelope = new Array(); //the lower envelope array for (var i=0;i