Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@twingall
- //project week and/or day and/or hour boxes forward into the future, as an aide in framing the shape of the coming weeks/day's profiles
- //@version=5
- indicator(title="week & day boxes projected forward", shorttitle="week/day boxes forward", overlay=true, max_boxes_count = 500)
- //user inputs
- useMidnight = input.bool(true, "use custom start time",group = "Custom Start Time?", tooltip="default is toggled off, default is TV week start time which is Sunday 6pm NY time (for ES)\n Recommended to Toggle this ON for BTC")
- inputSession = input.session('0000-0001:2', title='input week/day start time', group = "Custom Start Time?")
- userTimezone = input.string("America/New_York", "input your timezone",group = "Custom Start Time?", options =["America/New_York", "UTC-10", "UTC-9", "UTC-8", "UTC-7", "UTC-6", "UTC-5", "UTC-4", "UTC-3","UTC-2", "UTC-1","UTC", "UTC+1", "UTC+2", "UTC+3", "UTC+4","UTC+5","UTC+6","UTC+7","UTC+8","UTC+9","UTC+10","UTC+11","UTC+12","UTC+13"])
- isSession = time ==(time(timeframe.period, str.tostring(inputSession), userTimezone))
- cond = useMidnight? isSession:timeframe.change("W")
- showWeekly = input.bool(true, "show weekly", group = 'weekly projections')
- boxesToShowW =input.int(8, "No. of 2week blocks project forward",maxval =25, minval = 1, group = 'weekly projections') //tweak maxval alongside first integers on lines 56 and 58
- boxColorW1 = input.color(color.new(color.red, 90), "Box", inline ='1', group = 'weekly projections')
- boxColorW2 = input.color(color.new(color.blue, 90), "Box", inline ='1', group = 'weekly projections')
- borderColorW=input.color(color.new(color.blue, 60), "Border", inline ='1', group = 'weekly projections')
- showDaily = input.bool(true, "show daily", group = 'daily projections')
- boxesToShowD =input.int(10, "No. of 2day blocks project forward",maxval =18, minval = 1, group = 'daily projections') //tweak maxval alongside first integers on lines 62 and 64
- boxColorD1 = input.color(color.new(color.green, 90), "Box", inline ='1', group = 'daily projections')
- boxColorD2 = input.color(color.new(color.orange, 90), "Box", inline ='1', group = 'daily projections')
- borderColorD=input.color(color.new(color.red, 60), "Border", inline ='1', group = 'daily projections')
- showDoWtxt = input.bool(true, "show day of week labels", inline ='2', group = 'daily projections')
- dayTxtCol = input.color(color.new(color.gray, 30), "", inline ='2', group = 'daily projections')
- showHourly = input.bool(false, 'show hourly',group = 'hourly projections')
- boxesToShowH =input.int(14, "No. of 2hour blocks project forward",maxval =24, minval = 1, group = 'hourly projections')
- boxColorH1 = input.color(color.new(color.blue, 90), "Box", inline ='1', group = 'hourly projections')
- boxColorH2 = input.color(color.new(color.fuchsia, 90), "Box", inline ='1', group = 'hourly projections')
- borderColorH=input.color(color.new(color.gray, 60), "Border", inline ='1', group = 'hourly projections')
- week = 24*7*3600*1000, day = 24*3600*1000, _hour = 3600*1000
- colorNone = color.new(color.white, 100)
- atr =ta.atr(50)
- var box bx1 = na, var box bx2 = na, var box bx3 = na, var box bx4 = na, var box bx5 = na, var box bx6 = na
- var array<box> boxArr1 = array.new<box>(0), var array<box> boxArr2 = array.new<box>(0),var array<box> boxArr3 = array.new<box>(0)
- var array<box> boxArr4 = array.new<box>(0), var array<box> boxArr5 = array.new<box>(0), var array<box> boxArr6 = array.new<box>(0)
- //functions
- dayOfWeek (num)=>
- dayofweek(num) ==1 and syminfo.type != 'crypto'?"mon":dayofweek(num) ==2 and syminfo.type != 'crypto'?"tues":dayofweek(num) ==3 and syminfo.type != 'crypto'?"weds":
- dayofweek(num) ==4 and syminfo.type != 'crypto'?"thurs":dayofweek(num) ==5 and syminfo.type != 'crypto'?"fri":
- dayofweek(num)==1 and syminfo.type == 'crypto'?"sun":dayofweek(num)==2 and syminfo.type == 'crypto'?"mon":dayofweek(num)==3 and syminfo.type == 'crypto'?"tues":dayofweek(num)==4 and syminfo.type == 'crypto'?"weds":
- dayofweek(num)==5 and syminfo.type == 'crypto'?"thurs":dayofweek(num)==6 and syminfo.type == 'crypto'?"fri":dayofweek(num)==7 and syminfo.type == 'crypto'?"sat":na
- boxPaint(_int, col, borCol, period, numBoxes, mult)=>
- var box bx = na
- var array<box> boxArr = array.new<box>(0)
- for i=_int+1 to 0 by 2
- bx:=box.new(time+i*period, high+mult*atr, time+(i+1)*period,low-mult*atr, xloc = xloc.bar_time, bgcolor = col, border_color = borCol, extend =extend.none , text =period == day?dayOfWeek(time+i*period):"", text_color = showDoWtxt?dayTxtCol:colorNone , text_size = size.normal)
- array.push(boxArr,bx)
- if array.size(boxArr)>numBoxes
- box.delete(array.shift(boxArr))
- bx
- //painting the boxes
- if cond and showWeekly
- bx1:=boxPaint(53,boxColorW1,borderColorW, week,boxesToShowW, 65)
- array.push(boxArr1,bx1)
- bx2:=boxPaint(52,boxColorW2,borderColorW, week,boxesToShowW ,65)
- array.push(boxArr2,bx2)
- if cond and showDaily //timeframe.change("W") and showDaily
- bx3:=boxPaint(41,boxColorD1,borderColorD,day,boxesToShowD,50)
- array.push(boxArr3,bx3)
- bx4:=boxPaint(40,boxColorD2,borderColorD, day,boxesToShowD,50)
- array.push(boxArr4,bx4)
- isSessionH = time ==(time(timeframe.period, '0000-0001', "America/New_York"))
- condH = useMidnight? isSessionH:timeframe.change("D")
- if condH and showHourly //timeframe.change("W") and showDaily
- bx5:=boxPaint(50,boxColorH1,borderColorH,_hour,boxesToShowH,35)
- array.push(boxArr5,bx5)
- bx6:=boxPaint(49,boxColorH2,borderColorH, _hour,boxesToShowH,35)
- array.push(boxArr6,bx6)
Advertisement
Add Comment
Please, Sign In to add comment