//@Name:Follow through days //@Description:Returns 1 if previous day was a follow through day with input minimum price and volume increases (number of rally days can be 4-7) //@Width:60 //@Env:Production //@Update:Periodic,600 //Scripted by: Rebecca Farndale, ShareScope Support var priceRise = 5; var volRise = 5; function init(status) { if (status == Loading || status == Editing) { priceRise = storage.getAt(0); volRise = storage.getAt(1); } if (status == Adding || status == Editing) { dlg = new Dialog("Column Settings",210,40); dlg.addOkButton(); dlg.addCancelButton(); dlg.addNumEdit("VAL1",100,5,-1,-1,"Required price change:","%",priceRise,0,100); dlg.addNumEdit("VAL2",100,20,-1,-1,"Required volume change","%",volRise,0,100); if (dlg.show()==Dialog.Cancel) return false; priceRise = dlg.getValue("VAL1"); volRise = dlg.getValue("VAL2"); storage.setAt(0, priceRise); storage.setAt(1, volRise); } setTitle("Follow Through Day"); } function getVal(share) { var data = share.getPriceArray(); if (data.length < 90) return; data.splice(0, data.length - 90);; var i=data.length-1; var priceChange = (data[i].close/data[i-1].close-1)*100; var volChange = (data[i].volume/data[i-1].volume-1)*100; var rallyCount = 0; if (priceChange>priceRise && volChange>volRise) //met condition for current day to be a through day { var isRally= true; j=i while(isRally == true && j > i-7) // counting number of consecutive rally days in the last 7 days { if (data[j].close>data[j-1].close) { rallyCount++; j-- } else isRally = false; } if (rallyCount == 4) // identified that follow through day is day 4 (i) { //check rally days 2 and 3 don't undercut day 1 (i-3) if (data[i-1].lowdata[i-5].close || data[i-5].close>data[i-6].close || data[i-6].close>data[i-7].close) return 0; //check fallen at least 10% since last peak peakVal = peakFinder(data) if ((data[i-3].close/peakVal-1)*100 < -10) return 1; } else if (rallyCount == 5) // identified that follow through day is day 5 (i) { //check rally days 2,3 and 4 don't undercut day 1 (i-4) if (data[i-1].lowdata[i-6].close || data[i-6].close>data[i-7].close || data[i-7].close>data[i-8].close) return 0; //check fallen at least 10% since last peak peakVal = peakFinder(data) if ((data[i-4].close/peakVal-1)*100 < -10) return 1; } else if (rallyCount == 6) // identified that follow through day is day 6 (i) { //check rally days 2,3,4 and 5 don't undercut day 1 (i-5) if (data[i-1].lowdata[i-7].close || data[i-7].close>data[i-8].close || data[i-8].close>data[i-9].close) return 0; //check fallen at least 10% since last peak peakVal = peakFinder(data) if ((data[i-5].close/peakVal-1)*100 < -10) return 1; } else if (rallyCount == 7) // identified that follow through day is day 7 (i) { //check rally days 2,3,4,5 and 6 don't undercut day 1 (i-6) if (data[i-1].lowdata[i-8].close || data[i-8].close>data[i-9].close || data[i-9].close>data[i-10].close ) return 0; //check fallen at least 10% since last peak peakVal = peakFinder(data) if ((data[i-6].close/peakVal-1)*100 < -10) return 1; } else return 0; //rally longer than 6 days } else return 0; //current day cannot be a through day as price/volume didn't rise enough return 0; } function peakFinder(data) { var zz = zigZagCalcClose(data,5/100) for (i=zz.length-2;i>2;i--) { if (zz[i].value>zz[i+1].value && zz[i].value>zz[i-1].value) return zz[i].value; } return zz[i]; } function zigZagCalcClose(data,zzPerc) { var zz = []; var hh,ll; //start loop to calculate zig-zag line values zz[0] = {index:0,value:data[0].close}; for (var i=0;idata[i].close) ll = data[i].close; if (hh/zz[0].value-1>=zzPerc || 1-ll/zz[0].value>=zzPerc) { zz[1] = {index:i,value:data[i].close}; continue; } } else { if (zz[zz.length-1].value>zz[zz.length-2].value) { if (data[i].close>zz[zz.length-1].value) { zz[zz.length-1].value = data[i].close; zz[zz.length-1].index = i; continue; } else if (1-data[i].close/zz[zz.length-1].value>=zzPerc) { zz[zz.length] = {index:i,value:data[i].close}; } } else { if (data[i].close=zzPerc) { zz[zz.length] = {index:i,value:data[i].close}; } } } } if (zz[zz.length-1].index