//@Name:R-squared //@Description:Returns the R-squared value of an instrument. A full description can be found at http://en.wikipedia.org/wiki/R-squared //@Returns:Number //@Width:60 // Coded by: 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 = 20; var lineCol = Colour.RGB(255,190,0); var lineStyle = Pen.Solid; var lineWidth = 1; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); lineCol = storage.getAt(1); lineStyle = storage.getAt(2); lineWidth = storage.getAt(3); } if (status == Adding || status == Editing) { dlg = new Dialog("Setup",150,60); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","Trend period",period,2,5000); dlg.addColLinePicker("LN1",8,-1,-1,-1,"","",lineCol,lineStyle,lineWidth); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("INT1"); lineCol = dlg.getValue("LN1").colour; lineStyle = dlg.getValue("LN1").pen; lineWidth = dlg.getValue("LN1").width; storage.setAt(0, period); storage.setAt(1, lineCol); storage.setAt(2, lineStyle); storage.setAt(3, lineWidth); } setTitle(period+" R-squared"); setSeriesLineStyle(0, lineStyle, lineWidth); setSeriesColour(0, lineCol); setHorizontalLine(50); } function getGraph(share, data) { var trend1 = new Trend(period); var ma1 = new MA(period); var output = [] for (var i=0;i