//@Name:Raff Regression Channels //@Description:A trand line with channels based on the difference between the highest high/lowest low and the trend //@Future:Yes // 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 period = 20; var useClose = false; var lineCol1 = Colour.Blue var lineSytle1 = 0; var lineWidth1 = 0; var lineCol2 = Colour.Blue var lineSytle2 = 1; var lineWidth2 = 0; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); useClose = storage.getAt(1); lineCol1 = storage.getAt(2); lineSytle1 = storage.getAt(3); lineWidth1 = storage.getAt(4); lineCol2 = storage.getAt(5); lineSytle2 = storage.getAt(6); lineWidth2 = storage.getAt(7); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings",150,75); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","Period",period,2,1000); dlg.addTickBox("TB1",8,-1,-1,-1,"use close",useClose); dlg.addColLinePicker("LN1",8,-1,-1,-1,"","Trend Line",lineCol1,lineSytle1,lineWidth1); dlg.addColLinePicker("LN2",8,-1,-1,-1,"","Confidence Lines",lineCol2,lineSytle2,lineWidth2); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("INT1"); useClose = dlg.getValue("TB1"); lineCol1 = dlg.getValue("LN1").colour; lineSytle1 = dlg.getValue("LN1").pen; lineWidth1 = dlg.getValue("LN1").width; lineCol2 = dlg.getValue("LN2").colour; lineSytle2 = dlg.getValue("LN2").pen; lineWidth2 = dlg.getValue("LN2").width; storage.setAt(0, period); storage.setAt(1, useClose); storage.setAt(2, lineCol1); storage.setAt(3, lineSytle1); storage.setAt(4, lineWidth1); storage.setAt(5, lineCol2); storage.setAt(6, lineSytle2); storage.setAt(7, lineWidth2); } setSeriesColour(0, lineCol1); setSeriesColour(1, lineCol2); setSeriesColour(2, lineCol2); setSeriesLineStyle(0, lineSytle1, lineWidth1); setSeriesLineStyle(1, lineSytle2, lineWidth2); setSeriesLineStyle(2, lineSytle2, lineWidth2); setRange(Range.Parent); } function getGraph(share, data) { var trendLine = []; var upRRC = []; var downRRC = []; var trendValue; var trend1 = new Trend(period); for (var i=data.length-period;i=0;i--) { trendLine[i] = trendLine[i+1] - trend1.getSlope(); upRRC[i] = trendLine[i] + channel; downRRC[i] = trendLine[i] - channel; } return [trendLine,upRRC,downRRC] }