//@Name:High Breakout //@Description:Returns 1 if a share has breached it's highest high or highest close. //@Update:Periodic //@Width:70 //@Returns:Number //@Env:Production var lookBack = 252; var choice1List = ["Highest High","Highest Close",]; var choice1 = 0; var choice2List = ["High","Close"]; var choice2 = 1; var yesterday = 0; var dataList = ["Daily","Weekly","Monthly"]; var dataSource = 0; var useIntra = 0; function init(status) { if (status == Loading || status == Editing) { lookBack = storage.getAt(0); choice1 = storage.getAt(1); choice2 = storage.getAt(2); yesterday = storage.getAt(3); dataSource = storage.getAt(4); useIntra = storage.getAt(5); } if (status == Adding || status == Editing) { var dlg = new Dialog("Settings....", 340, 100); dlg.addOkButton(); dlg.addCancelButton(); dlg.addDropList("VAL1",60,5,40,-1,choice2List,"Check if the last ","",choice2); dlg.addDropList("VAL2",175,5,-1,-1,choice1List,"is above the previous ","",choice1); dlg.addTickBox("VAL3",5,22,210,-1,"And the Highest High/Close was achieved on the previous day.",yesterday); dlg.addNumEdit("VAL4",42,39,-1,-1,"Look Back:" ,"periods",lookBack,2,10000); dlg.addDropList("VAL5",5,56,-1,-1,dataList,"","",dataSource); dlg.addTickBox("VAL6",75,58,100,-1,"Include Intraday Data",useIntra); if (dlg.show() == Dialog.Cancel) return; lookBack = dlg.getValue("VAL4"); choice2 =dlg.getValue("VAL1"); choice1 = dlg.getValue("VAL2"); yesterday= dlg.getValue("VAL3"); dataSource = dlg.getValue("VAL5"); useIntra = dlg.getValue("VAL6"); storage.setAt(0, lookBack); storage.setAt(1, choice1); storage.setAt(2,choice2); storage.setAt(3,yesterday); storage.setAt(4,dataSource); storage.setAt(5,useIntra); } setTitle((useIntra?(choice2?"Mid":"High"):choice2List[choice2])+" > "+choice1List[choice1]+"("+lookBack+") "+(useIntra?"i":"")+dataList[dataSource]); } function getVal(share) { var data = getData(share,dataSource,useIntra); if (data==undefined || data.length<2*lookBack) return; var hh = new MinMax(lookBack); var highRes = []; for (var i=0;ihighRes[highRes.length-2]) { setValueForShare(share,1); return 1; } } } else { if((choice2==0?data[data.length-1].high:data[data.length-1].close)>highRes[highRes.length-2]) return 1; } } function getData(share,dataSource,useIntra) { if (dataSource == 0)var data = share.getPriceArray(); if (dataSource == 1)var data = share.getWeeklyBarArray(); if (dataSource == 2)var data = share.getMonthlyBarArray(); if (data.length<2) return; if (dataSource==0 && useIntra==1) { //get a 24hour intraday bar var idata = share.getIBarArray(0,86400); //Check the bar is not undefined and has the correct length. //Check the date of the intraday data is today's date. //Check the date of the end-of-day data is not today's date. if (idata!=undefined && idata.length==1 && new Date().getDate()==idata[0].date.getDate() && new Date().getDate()!=data[data.length-1].date.getDate()) {//Add a new bar to the end of the current data array that adds the intraday Open,High,Low & Close data[data.length]={ open:share.getIOpen(), high:idata[0].high, low:idata[0].low, close:(share.getIClose()==null?share.getIMid():share.getIClose()), volume:idata[0].volume, dateNum:idata[0].dateNum}; } } if (dataSource==1 && useIntra==1) { //get a 24hour intraday bar var idata = share.getIBarArray(0,86400); //Check the bar is not undefined and has the correct length. //Check the date of the intraday data is today's date. //Check the date of the end-of-day data is not today's date. if (idata!=undefined && idata.length==1 && new Date().getDate()==idata[0].date.getDate() && new Date().getDate()!=data[data.length-1].date.getDate()) { if (idata[0].date.getDay()data[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