//@LibraryID:1077,0 //@Name:Average, highest and lowest close //@Description:Plots three horizontal lines at the average close, highest close and lowest close over the chosen lookback period. //@Future:yes //Author: Paul Hall, ShareScope 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 lookback = 30; var highCol = Colour.Blue; var highPen = Pen.Dot; var highWidth = 0; var lowCol = Colour.Red; var lowPen = Pen.Dot; var lowWidth = 0; var avCol = Colour.DarkGreen; var avPen = Pen.Dot; var avWidth = 0; var avBox = 1; var highBox = 1; var lowBox = 1; function init(status) { if (status == Loading || status == Editing) { var store1 = restore(storage.getAt(0),[[avPen,0,5],[avWidth,0,7],[highPen,0,5],[highWidth,0,7],[lowPen,0,5],[lowWidth,0,7],[avBox,0,1],[highBox,0,1],[lowBox,0,1]]); avPen = store1[0][0]; avWidth = store1[1][0]; highPen = store1[2][0]; highWidth = store1[3][0]; lowPen = store1[4][0]; lowWidth = store1[5][0]; avBox = store1[6][0]; highBox = store1[7][0]; lowBox = store1[8][0]; lookback = storage.getAt(1); avCol = storage.getAt(2); highCol = storage.getAt(3); lowCol = storage.getAt(4); } if (status == Adding || status == Editing) { dlg = new Dialog((status==Adding?"Add":"Edit")+" indicator", 230, 132); dlg.addOkButton(); dlg.addCancelButton(); dlg.addTickBox("VAL1",10,48,120,-1,"Draw line at the average close",avBox); dlg.addIntEdit("VAL2",110,8,-1,-1,"Use close prices over the last:","days",lookback,2,5000); dlg.addColLinePicker("VAL3",130,46,-1,-1,"","",avCol,avPen,avWidth); dlg.addTickBox("VAL5",10,31,120,-1,"Draw line at the highest close",highBox); dlg.addTickBox("VAL6",10,65,120,-1,"Draw line at the lowest close",lowBox); dlg.addColLinePicker("VAL7",130,30,-1,-1,"","",highCol,highPen,highWidth); dlg.addColLinePicker("VAL8",130,62,-1,-1,"","",lowCol,lowPen,lowWidth); if (dlg.show()==Dialog.Cancel) return false; avBox = dlg.getValue("VAL1"); lookback = dlg.getValue("VAL2"); avCol = dlg.getValue("VAL3").colour; avPen = dlg.getValue("VAL3").pen; avWidth = dlg.getValue("VAL3").width; highBox = dlg.getValue("VAL5"); lowBox = dlg.getValue("VAL6"); highCol = dlg.getValue("VAL7").colour; highPen = dlg.getValue("VAL7").pen; highWidth = dlg.getValue("VAL7").width; lowCol = dlg.getValue("VAL8").colour; lowPen = dlg.getValue("VAL8").pen; lowWidth = dlg.getValue("VAL8").width; storage.setAt(0, compress([[avPen,0,5],[avWidth,0,7],[highPen,0,5],[highWidth,0,7],[lowPen,0,5],[lowWidth,0,7],[avBox,0,1],[highBox,0,1],[lowBox,0,1]])); storage.setAt(1, lookback); storage.setAt(2, avCol); storage.setAt(3, highCol); storage.setAt(4, lowCol); } setSeriesColour(0,avCol); setSeriesLineStyle(0,avPen,avWidth); setSeriesColour(1,highCol); setSeriesLineStyle(1,highPen,highWidth); setSeriesColour(2,lowCol); setSeriesLineStyle(2,lowPen,lowWidth); setRange(Range.Parent) setTitle(lookback+" Average, highest & lowest close"); } function getGraph(share, data) { var ma1 = new MA(lookback); var max1 = 0; var min1 = 999999; var av; var avLine = new Array(); var highLine = new Array(); var lowLine = new Array(); for (var j =(data.length max1) { max1 = data[j].close; } if(data[j].close < min1) { min1 = data[j].close; } av = ma1.getNext(data[j].close); } for (var i=0; i8388608) print("Too much data for single storage space"); return output; } function restore(storage, data) { var remainder = storage; var rangeTot = 1; for (var i=0;i=0;i--) { if (i