//@Name:Ichimoku Value //@Description:Displays the latest value of the various Ichimoku lines //@Returns:Number //@Width:90 // Author: Richard, ShareScript Support // Modified: Philip. 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 slPeriod = 26; var tlPeriod = 9; var dlPeriod = 26; var advShift = 26; var secSpanPeriod = 52; var displayList = ["Standard Line","Turning Line","Delayed Line","1st preceding Span","2nd Preceding Span"] var displayType = 0; var useIntra=0; var dataList = ["Daily","Weekly","Monthly"]; var dataSource = 0; var dataOptionStorage = 0; var periodsAgo = 0; function init(status) { if (status == Loading || status == Editing) { slPeriod = storage.getAt(0); tlPeriod = storage.getAt(1); dlPeriod = storage.getAt(2); advShift = storage.getAt(3); secSpanPeriod = storage.getAt(4); displayType = storage.getAt(5); dataOptionStorage = storage.getAt(6); periodsAgo = storage.getAt(7); dataOptionStorage = dataOptionStorage.toString(); dataSource = parseInt(dataOptionStorage.substr(1,1),10)-1; useIntra = parseInt(dataOptionStorage.substr(2,1),10)-1; } if (status == Adding || status == Editing) { var dlg = new Dialog("Ichimoku settings", 200, 170); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("VAL1",5,5,-1,-1,"","Standard line period",slPeriod,2,2000); dlg.addIntEdit("VAL2",5,22,-1,-1,"","Turning line period",tlPeriod,2,2000); dlg.addIntEdit("VAL3",5,39,-1,-1,"","Delayed line period",dlPeriod,1,2000); dlg.addIntEdit("VAL4",5,56,-1,-1,"","Advance shift",advShift,0,2000); dlg.addIntEdit("VAL5",5,73,-1,-1,"","2nd span period",secSpanPeriod,2,2000); dlg.addDropList("VAL6",40,90,80,-1,displayList,"Output:","",displayType); dlg.addTickBox("VAL7",85,109,120,-1,"Include Intraday Data",useIntra); dlg.addDropList("VAL8",5,107,-1,-1,dataList,"","",dataSource); dlg.addIntEdit("VAL9",5,126,-1,-1,"","Periods Ago",periodsAgo,0,9999); if (dlg.show()==Dialog.Cancel) return false; slPeriod = dlg.getValue("VAL1"); tlPeriod = dlg.getValue("VAL2"); dlPeriod = dlg.getValue("VAL3"); advShift = dlg.getValue("VAL4"); secSpanPeriod = dlg.getValue("VAL5"); displayType = dlg.getValue("VAL6"); useIntra = dlg.getValue("VAL7"); dataSource = dlg.getValue("VAL8"); periodsAgo = dlg.getValue("VAL9"); dataOptionStorage = (dataSource+1)*10+(useIntra+1); storage.setAt(0, slPeriod); storage.setAt(1, tlPeriod); storage.setAt(2, dlPeriod); storage.setAt(3, advShift); storage.setAt(4, secSpanPeriod); storage.setAt(5, displayType); storage.setAt(6, dataOptionStorage); storage.setAt(7, periodsAgo); } setTitle(slPeriod+","+tlPeriod+","+dlPeriod+","+advShift+","+secSpanPeriod+" Ichimoku "+displayList[displayType]+(useIntra?" (i":" (")+dataList[dataSource]+") "+(periodsAgo>0?periodsAgo+" prds ago":"")); } function getVal(share) { var data = getData(share,dataSource,useIntra); if (data == undefined || data.length=(secSpanPeriod*2)+5) stfor = data.length-((secSpanPeriod*2)+5); for (var i=stfor;ihhl[i]) hhl[i] = data[i-j].high; if (lll[i]==null || data[i-j].lowhhm[i] && jhhs[i] && jadvShift) { fps[i] = (sl[i-advShift]+tl[i-advShift])/2; sps[i] = (hhl[i-advShift]+lll[i-advShift])/2; } } if (displayType==0) return sl[sl.length-(1+periodsAgo)]; if (displayType==1) return tl[tl.length-(1+periodsAgo)]; if (displayType==2) return dl[dl.length-(1+periodsAgo)]; if (displayType==3) return fps[fps.length-(1+periodsAgo)]; if (displayType==4) return sps[sps.length-(1+periodsAgo)]; } 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