xmd79

Lunar Cycles/Moon Phases Forward

May 22nd, 2023
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. //@twingall
  2. //Projecting Lunar Cycles/ half-cycles forward in time
  3. //credit to @yigdeli for the suggestion and @LuxAlgo for the input anchor time/cycle time idea (https://www.tradingview.com/script/yvDyq0pv-Moon-Phases-Strategy-LuxAlgo/)
  4. //@version=5
  5. indicator(title="Lunar Cycles/Moon Phases Forward", shorttitle="Lunar Cycles Forward", overlay=true, max_boxes_count = 500)
  6. //moon cycle = 29.53059 days = 2551442000 ms
  7. mCycle = 2551442976
  8. halfCycle = math.round(mCycle/2) //math.round, in case you want to change mCycle to an non-perfectly-divisible number
  9. QrtCycle =math.round(mCycle /4)
  10. //input recent full moon time based on UTC-4 timezone (New York SummerTime, since it's 1st of March now and we clocks change to that on 12th March)
  11. inputRecentFullMoon = input.time(timestamp("07 Mar 2023 08:00 GMT-4"), "Recent Full Moon:(UTC-4)", group = "input recent full mooon", tooltip ="NB: must be New York time, (UTC-4; daylight saving/summertime)\n\nRound to the nearest hour for this to work more reliably across more timeframes\n\nThis will need to be a time when the asset was trading (i.e. if Sunday 2pm on S&P, it will not work)")
  12. boxesToShow =input.int(8, "Full Lunar Cycles to project forward",maxval =25, minval = 1) //tweaking: maxval should be around half of first integers on lines 65,67,71,73,86,88,90,92
  13. isFullMoon = time==inputRecentFullMoon
  14. boxHeight = input.int(70, minval =20, maxval = 110, step =3, title ="Box Height", tooltip = "Arbitrary units, based on multiplier of ADR; 70 seems optimal for most timeframes")
  15. showEmojis = input.bool(true, "show moon emojis",inline ='2')
  16.  
  17. showHalfCycles = input.bool(true, "Half Cycle Boxes", inline ='1',group = 'half cycle projections')
  18. showText1 = input.bool(true, "show text",inline ='1',group = 'half cycle projections')
  19. txtCol1 = input.color(color.new(color.red, 30), "", inline ='1',group = 'half cycle projections')
  20. colWaning = input.color(color.new(color.gray, 90), "Waning", inline ='2', group = 'half cycle projections')
  21. colWaxing = input.color(color.new(color.yellow, 90), "Waxing", inline ='2', group = 'half cycle projections')
  22. borderColor=input.color(color.new(color.blue, 60), "Box Borders", inline ='3', group = 'half cycle projections')
  23.  
  24. showQrtCycles =input.bool(true, "Quarter Cycle Boxes",inline ='1', group = 'quarter cycle projections')
  25. showText2 = input.bool(true, "show text",inline ='1', group = 'quarter cycle projections')
  26. txtCol2=input.color(color.new(color.green, 30), "", inline ='1', group = 'quarter cycle projections')
  27. colWanGibb =input.color(color.new(color.fuchsia, 90), "Waning Gibbous", inline ='2', group = 'quarter cycle projections')
  28. colWanCres=input.color(color.new(color.maroon, 90), "Waning Crescent", inline ='2', group = 'quarter cycle projections')
  29. colWaxCres=input.color(color.new(color.lime, 90), "Waxing Crescent", inline ='3', group = 'quarter cycle projections')
  30. colWaxGibb=input.color(color.new(color.teal, 90), "Waxing Gibbous", inline ='3', group = 'quarter cycle projections')
  31. borderColor2=input.color(color.new(color.olive, 60), "Box Borders", inline ='4', group = 'quarter cycle projections')
  32. colorNone = color.new(color.white, 100)
  33. atr =ta.atr(50)
  34. var box bx1 = na
  35. var box bx2 = na
  36. var label lab1 =na
  37. var label lab2 =na
  38. var array<box> boxArr1 = array.new<box>(0)
  39. var array<box> boxArr2 = array.new<box>(0)
  40. var array<label>labArr1= array.new<label>(0)
  41. var array<label>labArr2= array.new<label>(0)
  42.  
  43. //function
  44. boxPaint(_int, col, borCol, txtCol, period, numBoxes, mult,spacerMult,offset)=>
  45. var box bx = na
  46. var array<box> boxArr = array.new<box>(0)
  47. for i=_int+1 to 0 by 2
  48. bx:=box.new(time+offset+(spacerMult*i)*period, high+mult*atr, time+offset+((spacerMult*i)+1)*period,low-mult*atr, xloc = xloc.bar_time, bgcolor = col, border_color = borCol, extend =extend.none, text =col==colWaning?"WANE":
  49. col==colWaxing?"WAX":col==colWanGibb?"Wane\nGibb\n\n\n\n\n\n":col==colWanCres?"\n\n\n\n\n\nWane\nCres":col==colWaxCres?"\n\n\n\n\n\nWax\nCres":col==colWaxGibb?"Wax\nGibb\n\n\n\n\n\n":"",text_color = txtCol , text_size = size.normal)
  50. array.push(boxArr,bx)
  51. if array.size(boxArr)>numBoxes
  52. box.delete(array.shift(boxArr))
  53. bx
  54. labelPrint(_int,col, period, numBoxes,_size, mult,spacerMult)=>
  55. var label lab =na
  56. var array<label> labArr = array.new<label>(0)
  57. for i=_int+1 to 0 by 2
  58. lab:=label.new(time+(spacerMult*i)*period, col==colWaning?high+mult*atr:col==colWaxing?low-mult*atr:na, text =col==colWaning?"🌕":col==colWaxing?"🌚︎":"", xloc=xloc.bar_time, style=label.style_none, size = _size )//other emoji choices 🌚 ☾ 🌚︎
  59. array.push(labArr,lab)
  60. if array.size(labArr)>numBoxes
  61. label.delete(array.shift(labArr))
  62. lab
  63. //painting the boxes
  64. if isFullMoon and showHalfCycles
  65. bx1:=boxPaint(53,colWaning,borderColor,showText1?txtCol1:colorNone, halfCycle,boxesToShow,boxHeight,1,0)
  66. array.push(boxArr1,bx1)
  67. bx2:=boxPaint(52,colWaxing,borderColor,showText1?txtCol1:colorNone, halfCycle,boxesToShow ,boxHeight,1,0)
  68. array.push(boxArr2,bx2)
  69.  
  70. if isFullMoon and showEmojis
  71. lab1:=labelPrint(53,colWaning, halfCycle, boxesToShow, size.large,boxHeight,1)
  72. array.push(labArr1,lab1)
  73. lab2:=labelPrint(52,colWaxing, halfCycle, boxesToShow, size.large,boxHeight,1 )
  74. array.push(labArr2,lab2)
  75.  
  76. var box bx3 = na
  77. var box bx4 = na
  78. var box bx5 = na
  79. var box bx6 = na
  80. var array<box> boxArr3 = array.new<box>(0)
  81. var array<box> boxArr4 = array.new<box>(0)
  82. var array<box> boxArr5 = array.new<box>(0)
  83. var array<box> boxArr6 = array.new<box>(0)
  84.  
  85. if isFullMoon and showQrtCycles
  86. bx3:=boxPaint(53,colWanGibb,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow, boxHeight,2,0)
  87. array.push(boxArr3,bx3)
  88. bx4:=boxPaint(52,colWaxCres,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow ,boxHeight,2,0)
  89. array.push(boxArr4,bx4)
  90. bx5:=boxPaint(53,colWanCres,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow, boxHeight,2,QrtCycle)
  91. array.push(boxArr5,bx5)
  92. bx6:=boxPaint(52,colWaxGibb,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow ,boxHeight,2,QrtCycle)
  93. array.push(boxArr6,bx6)
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment