//@Name:Alarm:Volume greater than ADV over specified period. //@Description:An alarm script designed to trigger if the current intraday volume is x percent greater than the average daily volume. //@Returns:Text //@Width:50 //@Update:Intraday //Coded by: Phil Tolhurst, 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 = 25; var percent = 50; function init(status) { if (status == Loading || status == Editing) { period = storage.getAt(0); percent = storage.getAt(1); } if (status == Adding || status == Editing) { dlg = new Dialog("Volume Vs ADV",150,50); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,8,-1,-1,"","period length",period,2,1000); dlg.addIntEdit("INT2",8,23,-1,-1,"","percentage",percent,2,1000); if (dlg.show()==Dialog.Cancel) return false; period = dlg.getValue("INT1"); percent = dlg.getValue("INT2"); storage.setAt(0, period); storage.setAt(1, percent); } setTitle("Intra Volume VS ADV"); } function getVal(share) { var data = share.getPriceArray(); var adv = 0; var advResult = 0; var pcntVal = 0; var idata = share.getIBarArray(0,86400); if (idata==undefined || idata.length!=1 || new Date().getDate()!=idata[0].date.getDate()) return; var iVolume = idata[0].volume if (data==undefined || data.lengthdata.length-(period+1);i--) { adv=adv+data[i].volume; } advResult = adv/period var pcntVal = (((iVolume/advResult)-1)*100).toFixed(2); //Check for Trigger if(isAlarmContext) { if (getValueForShare(share)!=1 && pcntVal>percent) { setValueForShare(share, 1); return "iVol "+pcntVal+"% greater than the ADV("+period+")"; } } else { if ( pcntVal>percent) { return "iVol "+pcntVal+"% greater than the ADV("+period+")"; } } }