//@Name:ATR Multiplier Ratio //@Description:Returns true if short term ATR is less than chosen multiple of long term ATR //@Returns:Number //@Width:60 //@Update:Intraday, 120 //Author: Richard Chiesa, ShareScript Support //modified by: Paul Hall, 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 period1 = 5; var period2 = 14; var multiplier = 1.5; function init(status) { if (status == Loading || status == Editing) { period1 = storage.getAt(0); period2 = storage.getAt(1); multiplier = storage.getAt(2); } if (status == Adding || status == Editing) { dlg = new Dialog("Set ATR periods",180,55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",8,-1,-1,-1,"","Short ATR",period1,2,1000); dlg.addIntEdit("VAL2",8,-1,-1,-1,"","Long ATR",period2,2,1000); dlg.addNumEdit("VAL3",8,-1,-1,-1,"","Multiplier",multiplier,0.01,1000); if (dlg.show()==Dialog.Cancel) return false; period1 = dlg.getValue("VAL1"); period2 = dlg.getValue("VAL2"); multiplier = dlg.getValue("VAL3"); storage.setAt(0, period1); storage.setAt(1, period2); storage.setAt(2, multiplier); } setTitle(period1+" ATR < "+multiplier+"x "+period2+" ATR"); } function getVal(share) { var atrCalc1 = new ATR(period1); var atrCalc2 = new ATR(period2); var data = share.getPriceArray(period2*6); if (data.length<2) return; var idata = share.getIBarArray(0,86400); if (idata!=undefined && idata.length==1 && new Date().getDate()==idata[0].date.getDate() && new Date().getDate()!=data[data.length-1].date.getDate()) { var tclose = share.getIClose(); data[data.length]={open:idata[0].open,high:idata[0].high,low:idata[0].low,close:(tclose==null?share.getIMid():tclose),volume:idata[0].volume}; } for (i=0;i