//@LibraryID:42,2 // @Name:William's %R // @Description:Returns the latest value of William's %R indicator // @Returns:Number //@Update:Periodic,15 // 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. // Coded by: Phil Tolhurst, ShareScope Support var period = 20; var dataSource = 0; var dataList = ["Daily","Weekly","Monthly"]; var daysAgo = 0; var useIntra = 0; function init(status) { if (status == Loading || status == Editing) { dataSource = storage.getAt(0); period = storage.getAt(1); daysAgo = storage.getAt(2); useIntra = storage.getAt(3); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings",200,90); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",8,-1,-1,-1,dataList,"","",dataSource); dlg.addIntEdit("VAL2",8,-1,-1,-1,"","Period",period,2,1000); dlg.addIntEdit("VAL3",8,-1,-1,-1,"","trading days ago",daysAgo,0,9999); dlg.addTickBox("VAL4",8,-1,130,-1,"use latest intraday data", useIntra); if (dlg.show()==Dialog.Cancel) return false; dataSource = dlg.getValue("VAL1") period = dlg.getValue("VAL2"); daysAgo = dlg.getValue("VAL3"); useIntra = dlg.getValue("VAL4"); storage.setAt(0, dataSource); storage.setAt(1, period); storage.setAt(2, daysAgo); storage.setAt(3, useIntra); } //setTitle(period+" "+maTitleList[maType]+" ("+dataList[dataSource]+") "+(dataSource==0?(daysAgo+" days ago"):(dataSource==1?(daysAgo+" weeks ago"):(daysAgo+" months ago")))); } function getVal(share) { var data = getData(share,dataSource,useIntra) if (data.lengthdata[data.length-1].high?idata[0].high:data[data.length-1].high), low:(idata[0].lowdata[data.length-1].high?idata[0].high:data[data.length-1].high), low:(idata[0].low