//@Name:Alarm:Price change with Spread check. //@Description:An alarm script designed to trigger if the mid has changed a given percentage and the spread is less than a specified percentage, //@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 checkType = 0; var checkList = ["Open","Close"]; var spread = 2; var percent = 10; function init(status) { if (status == Loading || status == Editing) { percent = storage.getAt(0); checkType = storage.getAt(1); spread = storage.getAt(2); } if (status == Adding || status == Editing) { dlg = new Dialog("Price Change",290,50); dlg.addOkButton(); dlg.addCancelButton(); dlg.addNumEdit("Val1",78,8,-1,-1,"Price changes by +/-","% from the ",percent,0,1000); dlg.addDropList("Val2",150,8,-1,-1,checkList,"","",checkType); dlg.addNumEdit("Val3",100,25,-1,-1,"Spread less than or equal to","%",spread,0,1000); if (dlg.show()==Dialog.Cancel) return false; percent = dlg.getValue("Val1"); checkType = dlg.getValue("Val2"); spread = dlg.getValue("Val3"); storage.setAt(0, percent); storage.setAt(1, checkType); storage.setAt(2, spread); } setTitle("Mid from "+checkList[checkType]+" changes by "+percent+"% & Spread less than "+spread+"%"); } function getVal(share) { var basePrice = checkType==1?share.getClose():(share.getIOpen()==undefined?share.getClose():share.getIOpen()); if (basePrice == undefined) return; var bidOffer = share.getIBidOfferArray(); var marketOpen = share.getMarketOpenTime(); if (bidOffer == undefined || bidOffer.length<1 || bidOffer[bidOffer.length-1].timeNum < marketOpen) return; var spreadPercent = (bidOffer[bidOffer.length-1].offer/bidOffer[bidOffer.length-1].bid-1)*100; var currentPrice = share.getIMid(); var pricePercentChange = (currentPrice/basePrice-1)*100; //Check for Trigger if(isAlarmContext) { if (getValueForShare(share)!=1 && spreadPercentpercent) { setValueForShare(share, 1); return "Mid from "+checkList[checkType]+" rose "+pricePercentChange.toFixed(2); } else if (getValueForShare(share)!=-1 && spreadPercentspread && (pricePercentChange<=percent || pricePercentChange>=-percent)) { setValueForShare(share, 0); } } else { if (spreadPercentpercent || pricePercentChange<=-percent)) return (pricePercentChange.toFixed(2)+"% ch, "+spreadPercent.toFixed(2)+"% spread") } }