//@LibraryID:978,1 //@Name:ATR Indicator //@Description:Draws an indicator of the ATR value or as expressed as a percentage of the current price //@Env:Production // Author: Phil Tolhurst, ShareScript Support //modified by: Paul Hall, SS Support. 18/02/20 - added signal and colour picker for each 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. var colour1=11862016; var width1=0; var pen1=0; var colour2=Colour.Red; var width2=0; var pen2=0; var period = 14; var maPeriod = 20; var outputChoice = 0; var outputList = ["ATR value","ATR/Price ratio %"]; function init(status) { if (status == Loading || status == Editing) { var store1 = restore(storage.getAt(0),[[width1,0,7],[width2,0,7],[pen1,0,4],[pen2,0,4]]); width1 = store1[0][0]; width2 = store1[1][0]; pen1 = store1[2][0]; pen2 = store1[3][0]; period = storage.getAt(1); outputChoice = storage.getAt(2); colour1 = storage.getAt(3); colour2 = storage.getAt(4); maPeriod = storage.getAt(5); } if (status == Adding || status == Editing) { dlg = new Dialog("ATR Value",200,55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",55,5,20,-1,"ATR Period","",period,2,1000); dlg.addIntEdit("VAL4",55,22,20,-1,"Signal period","",maPeriod,2,1000); dlg.addDropList("VAL2",55,39,75,-1,outputList,"Return the ","",outputChoice);+ dlg.addColLinePicker("VAL3",100,5,-1,-1,"","",colour1,pen1,width1); dlg.addColLinePicker("VAL5",100,22,-1,-1,"","",colour2,pen2,width2); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("VAL1"); maPeriod = dlg.getValue("VAL4"); outputChoice = dlg.getValue("VAL2"); colour1 = dlg.getValue("VAL3").colour; pen1 = dlg.getValue("VAL3").pen; width1 = dlg.getValue("VAL3").width; colour2 = dlg.getValue("VAL5").colour; pen2 = dlg.getValue("VAL5").pen; width2 = dlg.getValue("VAL5").width; storage.setAt(0, compress([[width1,0,7],[width2,0,7],[pen1,0,4],[pen2,0,4]])); storage.setAt(1, period); storage.setAt(2, outputChoice); storage.setAt(3, colour1); storage.setAt(4, colour2); storage.setAt(5, maPeriod); } //Set the line and style of the indicator setSeriesColour(0, colour1); setSeriesLineStyle(0, pen1, width1); setSeriesColour(1, colour2); setSeriesLineStyle(1, pen2, width2); //sets the title of the column setTitle(period+" ATR"+(outputChoice==0?"":"/price %")+" ("+maPeriod+" sig.)"); } function getGraph(share,data) { var atrCalc = new ATR(period); var atrRes = []; var ma1 = new MA(maPeriod); var sma = []; 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