//@Name:Zero Trend //@Description:Normalises the trend line to 0 and draws an indicator to show the price in relation to the trend. // Author: Richard Chiesa, 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 period = 252; var devs = 1.5; var lineCol1 = Colour.RGB(255,190,0); var lineStyle1 = Pen.Solid; var lineWidth1 = 1; var lineCol2 = Colour.RGB(180,180,180); var lineStyle2 = Pen.Solid; var lineWidth2 = 0; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); devs = storage.getAt(1); lineCol = storage.getAt(2); lineStyle = storage.getAt(3); lineWidth = storage.getAt(4); } if (status == Adding || status == Editing) { var dlg = new Dialog("Settings...",160,105); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("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,"","Indicator",lineCol1,lineStyle1,lineWidth1); dlg.addColLinePicker("LN2",8,-1,-1,-1,"","Trend Lines",lineCol2,lineStyle2,lineWidth2); if (dlg.show()==Dialog.Cancel) return false; 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, period); storage.setAt(1, devs); storage.setAt(2, lineCol); storage.setAt(3, lineStyle); storage.setAt(4, lineWidth); } setTitle("Zero Trend "+period+", "+devs+" devs"); setSeriesLineStyle(0, lineStyle1, lineWidth1); setSeriesColour(0, lineCol1); setSeriesLineStyle(1, lineStyle2, lineWidth2); setSeriesColour(1, lineCol2); setSeriesLineStyle(2, lineStyle2, lineWidth2); setSeriesColour(2, lineCol2); setSeriesLineStyle(3, lineStyle2, lineWidth2); setSeriesColour(3, lineCol2); } function getGraph(share, data) { var trend1 = new Trend(period); var output = []; var line1 = []; var line2 = []; var line3 = []; for (var i=Math.max(data.length-period,0);i