//@Name:Time Cycles 2 //@Description:Draws a vertical line at the market opening time, then at each successive set time interval //@Env:Production //@Editable:Yes //@Type:Intraday // 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. //Coded by: Richard Chiesa, ShareScript Support var cycleSize = 15; function init(status) { if (status == Loading || status == Editing) { cycleSize = storage.getAt(0); } if (status == Adding || status == Editing) { dlg = new Dialog("Settings...", 145, 55); dlg.addOkButton(); dlg.addCancelButton(); dlg.addIntEdit("INT1",8,-1,-1,-1,"","minute cycle",cycleSize,1,480); if (dlg.show()==Dialog.Cancel) return false; cycleSize = dlg.getValue("INT1"); storage.setAt(0, cycleSize); } setTitle(cycleSize+" minute cycle"); createButton("Increase Cycle", upCycle); createButton("Decrease Cycle", downCycle); } function onNewChart() { drawCycles(); } function upCycle() { cycleSize++; if (cycleSize>480) cycleSize=480; storage.setAt(1, cycleSize); drawCycles(); setTitle(cycleSize+" minute cycle"); } function downCycle() { cycleSize--; if (cycleSize<1) cycleSize=1; storage.setAt(1, cycleSize); drawCycles(); setTitle(cycleSize+" minute cycle"); } //this function gets called every time a Gann Level artifact needs to be drawn function drawCycles() { clearDisplay(); var s = getMinVisibleBarIndex() var f = getMaxVisibleBarIndex() var sDate = bars[s].date; var fDate = bars[f].date; setAltRange(0,1000); useAltRange(true); setPenStyle(Pen.Dot, 0, Colour.Red); var openTime = getCurrentShare().getMarketOpenTime(); var closeTime = getCurrentShare().getMarketCloseTime(); var cycleTimes = []; for (var i=openTime;i<=closeTime;i+=cycleSize*60) cycleTimes[cycleTimes.length] = i*1000; var currentDay; for (var i=s;i<=f;i++) { if (bars[i].date.getDay() == currentDay) continue; var midnight = new Date(bars[i].date.getFullYear(),bars[i].date.getMonth(),bars[i].date.getDate()) for (var j=0;j