//@Name:Donchian Mid //@Description:Donchian Channels with an additional mid line. Bars can be coloured when above/below the mid line. // 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. //Coded by: Richard Chiesa, ShareScript Support var highPeriod= 20; //period high var lowPeriod = 20; //period low var colourBars = false; var colourMidLine = false; var highCol = Colour.Blue; var midCol = Colour.DarkGreen; var lowCol = Colour.Red; var highStyle = 0; var midStyle = 0; var lowStyle = 0; var highWidth = 1; var midWidth = 1; var lowWidth = 1; var shadeCol = Colour.RGB(240,255,240); var shadeChannel = false function init(status) { if (status == Loading || status == Editing) { highPeriod = storage.getAt(0); lowPeriod = storage.getAt(1); colourBars = storage.getAt(2); highCol = storage.getAt(3); midCol = storage.getAt(4); lowCol = storage.getAt(5); highStyle = storage.getAt(6); midStyle = storage.getAt(7); lowStyle = storage.getAt(8); highWidth = storage.getAt(9); midWidth = storage.getAt(10); lowWidth = storage.getAt(11); shadeCol = storage.getAt(12); shadeChannel = storage.getAt(13); colourMidLine = storage.getAt(14); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings...", 190, 145); dlg.addOkButton(); dlg.addCancelButton(); dlg.addGroupBox(8,5,120,55,"Donchian Channel Periods"); dlg.addIntEdit("INT1",13,18,-1,-1,"","High channel",highPeriod,1,4000); dlg.addColLinePicker("COL1",90,18,-1,-1,"","",highCol,highStyle,highWidth); dlg.addIntEdit("INT2",13,40,-1,-1,"","Low channel",lowPeriod,1,4000); dlg.addColLinePicker("COL2",90,40,-1,-1,"","",lowCol,lowStyle,lowWidth); dlg.addColLinePicker("COL3",90,65,-1,-1,"Mid channel","",midCol,midStyle,midWidth); dlg.addColPicker("COL4",90,84,-1,-1,"","",shadeCol); dlg.addTickBox("TB2",11,87,60,-1,"Shading",shadeChannel); dlg.addTickBox("TB1",11,-1,150,-1,"Colour bars when above/below mid line",colourBars); dlg.addTickBox("TB3",11,-1,150,-1,"Colour mid line when rising/falling",colourMidLine); if (dlg.show()==Dialog.Cancel) return false; highPeriod = dlg.getValue("INT1"); lowPeriod = dlg.getValue("INT2"); colourBars = dlg.getValue("TB1"); highCol = dlg.getValue("COL1").colour; highStyle = dlg.getValue("COL1").pen; highWidth = dlg.getValue("COL1").width; lowCol = dlg.getValue("COL2").colour; lowStyle = dlg.getValue("COL2").pen; lowWidth = dlg.getValue("COL2").width; midCol = dlg.getValue("COL3").colour; midStyle = dlg.getValue("COL3").pen; midWidth = dlg.getValue("COL3").width; shadeCol = dlg.getValue("COL4"); shadeChannel = dlg.getValue("TB2"); colourMidLine = dlg.getValue("TB3"); storage.setAt(0, highPeriod); storage.setAt(1, lowPeriod); storage.setAt(2, colourBars); storage.setAt(3, highCol); storage.setAt(4, midCol); storage.setAt(5, lowCol); storage.setAt(6, highStyle); storage.setAt(7, midStyle); storage.setAt(8, lowStyle); storage.setAt(9, highWidth); storage.setAt(10, midWidth); storage.setAt(11, lowWidth); storage.setAt(12, shadeCol); storage.setAt(13, shadeChannel); storage.setAt(14, colourMidLine); } setTitle("Donchian Channels ("+highPeriod+","+lowPeriod+")"); } function onNewChart() { draw(); } function onNewBarUpdate() { draw(); } function draw() { clearDisplay(); var highLine = []; var midLine = []; var lowLine = []; var a = Math.max(highPeriod,lowPeriod); if (a>=bars.length) return; for (var i=a;ibars[i-j].low) ll = bars[i-j].low; highLine[i] = hh; lowLine[i] = ll; midLine[i] = (hh+ll)/2; if (colourBars && bars[i].close>midLine[i]) bars[i].colour = highCol; else if (colourBars && bars[i].close=a;i--) lineTo(i,lowLine[i]); endPath() fillPath() } setPenStyle(highStyle,highWidth,highCol); moveTo(a,highLine[a]); for (var i=a+1;imidLine[i-1]) setPenStyle(midStyle,midWidth,highCol); if (colourMidLine && midLine[i]