//@LibraryID:28,7 //@Name:Trend Cross //@Description:Finds shares that have crossed above or below the trend's confidence lines //@Returns:Number //@Width:60 //@Update:Periodic, 60 //@DefaultRangeMax:1 //@DefaultRangeMin:-1 /* Author: ShareScript Support The script returns 1 if the high has crossed above the top confidence line and -1 if the low has crossed below the bottom confidence line. */ // 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 num = 125; var devs = 1.5; var useClose = false; var useIntra=0; var dataList = ["Daily","Weekly","Monthly"]; var dataSource = 0; function init(status) { if (status == Loading || status == Editing) { num = storage.getAt(0); devs = storage.getAt(1); useClose = storage.getAt(2); useIntra = storage.getAt(3); dataSource = storage.getAt(4); } if (status == Adding || status == Editing) { dlg = new Dialog("Trend Settings", 180, 80); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",8,-1,20,-1,"","periods",num); dlg.addNumEdit("VAL2",65,5,20,-1,"","deviations",devs); dlg.addTickBox("VAL3",10,27,105,-1,"use close instead of high/low",useClose); dlg.addText(8,60,164,16,"Returns 1 if the high crosses the upper conf line Returns -1 if the low crosses the lower conf line"); dlg.addTickBox("VAL4",75,42,120,-1,"Include Intraday Data",useIntra); dlg.addDropList("VAL5",5,40,-1,-1,dataList,"","",dataSource); if (dlg.show()==Dialog.Cancel) return false; num = dlg.getValue("VAL1"); devs = dlg.getValue("VAL2"); useClose = dlg.getValue("VAL3"); useIntra = dlg.getValue("VAL4"); dataSource = dlg.getValue("VAL5"); storage.setAt(0, num); storage.setAt(1, devs); storage.setAt(2, useClose); storage.setAt(3, useIntra); storage.setAt(4, dataSource); } setTitle((useClose?"Close":"H/L")+" Cross("+num+" trend, "+devs+" devs "+(useIntra?"i":"")+dataList[dataSource]+")"); } function getVal(share) { var data = getData(share,dataSource,useIntra); if (data == undefined || data.lengthtrendCalc.getValue()+confVal && Hp1trendCalc.getValue()-trendCalc.getSlope()-confVal) x = -1; return x; } 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