xmd79

week & day boxes projected forward

Mar 10th, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. //@twingall
  2. //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
  3. //@version=5
  4. indicator(title="week & day boxes projected forward", shorttitle="week/day boxes forward", overlay=true, max_boxes_count = 500)
  5. //user inputs
  6. 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")
  7. inputSession = input.session('0000-0001:2', title='input week/day start time', group = "Custom Start Time?")
  8. 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"])
  9. isSession = time ==(time(timeframe.period, str.tostring(inputSession), userTimezone))
  10. cond = useMidnight? isSession:timeframe.change("W")
  11.  
  12. showWeekly = input.bool(true, "show weekly", group = 'weekly projections')
  13. 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
  14. boxColorW1 = input.color(color.new(color.red, 90), "Box", inline ='1', group = 'weekly projections')
  15. boxColorW2 = input.color(color.new(color.blue, 90), "Box", inline ='1', group = 'weekly projections')
  16. borderColorW=input.color(color.new(color.blue, 60), "Border", inline ='1', group = 'weekly projections')
  17.  
  18. showDaily = input.bool(true, "show daily", group = 'daily projections')
  19. 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
  20. boxColorD1 = input.color(color.new(color.green, 90), "Box", inline ='1', group = 'daily projections')
  21. boxColorD2 = input.color(color.new(color.orange, 90), "Box", inline ='1', group = 'daily projections')
  22. borderColorD=input.color(color.new(color.red, 60), "Border", inline ='1', group = 'daily projections')
  23. showDoWtxt = input.bool(true, "show day of week labels", inline ='2', group = 'daily projections')
  24. dayTxtCol = input.color(color.new(color.gray, 30), "", inline ='2', group = 'daily projections')
  25.  
  26. showHourly = input.bool(false, 'show hourly',group = 'hourly projections')
  27. boxesToShowH =input.int(14, "No. of 2hour blocks project forward",maxval =24, minval = 1, group = 'hourly projections')
  28. boxColorH1 = input.color(color.new(color.blue, 90), "Box", inline ='1', group = 'hourly projections')
  29. boxColorH2 = input.color(color.new(color.fuchsia, 90), "Box", inline ='1', group = 'hourly projections')
  30. borderColorH=input.color(color.new(color.gray, 60), "Border", inline ='1', group = 'hourly projections')
  31. week = 24*7*3600*1000, day = 24*3600*1000, _hour = 3600*1000
  32. colorNone = color.new(color.white, 100)
  33. atr =ta.atr(50)
  34. var box bx1 = na, var box bx2 = na, var box bx3 = na, var box bx4 = na, var box bx5 = na, var box bx6 = na
  35. var array<box> boxArr1 = array.new<box>(0), var array<box> boxArr2 = array.new<box>(0),var array<box> boxArr3 = array.new<box>(0)
  36. var array<box> boxArr4 = array.new<box>(0), var array<box> boxArr5 = array.new<box>(0), var array<box> boxArr6 = array.new<box>(0)
  37.  
  38. //functions
  39. dayOfWeek (num)=>
  40. dayofweek(num) ==1 and syminfo.type != 'crypto'?"mon":dayofweek(num) ==2 and syminfo.type != 'crypto'?"tues":dayofweek(num) ==3 and syminfo.type != 'crypto'?"weds":
  41. dayofweek(num) ==4 and syminfo.type != 'crypto'?"thurs":dayofweek(num) ==5 and syminfo.type != 'crypto'?"fri":
  42. 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":
  43. 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
  44.  
  45. boxPaint(_int, col, borCol, period, numBoxes, mult)=>
  46. var box bx = na
  47. var array<box> boxArr = array.new<box>(0)
  48. for i=_int+1 to 0 by 2
  49. 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)
  50. array.push(boxArr,bx)
  51. if array.size(boxArr)>numBoxes
  52. box.delete(array.shift(boxArr))
  53. bx
  54. //painting the boxes
  55. if cond and showWeekly
  56. bx1:=boxPaint(53,boxColorW1,borderColorW, week,boxesToShowW, 65)
  57. array.push(boxArr1,bx1)
  58. bx2:=boxPaint(52,boxColorW2,borderColorW, week,boxesToShowW ,65)
  59. array.push(boxArr2,bx2)
  60.  
  61. if cond and showDaily //timeframe.change("W") and showDaily
  62. bx3:=boxPaint(41,boxColorD1,borderColorD,day,boxesToShowD,50)
  63. array.push(boxArr3,bx3)
  64. bx4:=boxPaint(40,boxColorD2,borderColorD, day,boxesToShowD,50)
  65. array.push(boxArr4,bx4)
  66. isSessionH = time ==(time(timeframe.period, '0000-0001', "America/New_York"))
  67. condH = useMidnight? isSessionH:timeframe.change("D")
  68.  
  69. if condH and showHourly //timeframe.change("W") and showDaily
  70. bx5:=boxPaint(50,boxColorH1,borderColorH,_hour,boxesToShowH,35)
  71. array.push(boxArr5,bx5)
  72. bx6:=boxPaint(49,boxColorH2,borderColorH, _hour,boxesToShowH,35)
  73. array.push(boxArr6,bx6)
Advertisement
Add Comment
Please, Sign In to add comment