Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@twingall
- //Projecting Lunar Cycles/ half-cycles forward in time
- //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/)
- //@version=5
- indicator(title="Lunar Cycles/Moon Phases Forward", shorttitle="Lunar Cycles Forward", overlay=true, max_boxes_count = 500)
- //moon cycle = 29.53059 days = 2551442000 ms
- mCycle = 2551442976
- halfCycle = math.round(mCycle/2) //math.round, in case you want to change mCycle to an non-perfectly-divisible number
- QrtCycle =math.round(mCycle /4)
- //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)
- 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)")
- 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
- isFullMoon = time==inputRecentFullMoon
- 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")
- showEmojis = input.bool(true, "show moon emojis",inline ='2')
- showHalfCycles = input.bool(true, "Half Cycle Boxes", inline ='1',group = 'half cycle projections')
- showText1 = input.bool(true, "show text",inline ='1',group = 'half cycle projections')
- txtCol1 = input.color(color.new(color.red, 30), "", inline ='1',group = 'half cycle projections')
- colWaning = input.color(color.new(color.gray, 90), "Waning", inline ='2', group = 'half cycle projections')
- colWaxing = input.color(color.new(color.yellow, 90), "Waxing", inline ='2', group = 'half cycle projections')
- borderColor=input.color(color.new(color.blue, 60), "Box Borders", inline ='3', group = 'half cycle projections')
- showQrtCycles =input.bool(true, "Quarter Cycle Boxes",inline ='1', group = 'quarter cycle projections')
- showText2 = input.bool(true, "show text",inline ='1', group = 'quarter cycle projections')
- txtCol2=input.color(color.new(color.green, 30), "", inline ='1', group = 'quarter cycle projections')
- colWanGibb =input.color(color.new(color.fuchsia, 90), "Waning Gibbous", inline ='2', group = 'quarter cycle projections')
- colWanCres=input.color(color.new(color.maroon, 90), "Waning Crescent", inline ='2', group = 'quarter cycle projections')
- colWaxCres=input.color(color.new(color.lime, 90), "Waxing Crescent", inline ='3', group = 'quarter cycle projections')
- colWaxGibb=input.color(color.new(color.teal, 90), "Waxing Gibbous", inline ='3', group = 'quarter cycle projections')
- borderColor2=input.color(color.new(color.olive, 60), "Box Borders", inline ='4', group = 'quarter cycle projections')
- colorNone = color.new(color.white, 100)
- atr =ta.atr(50)
- var box bx1 = na
- var box bx2 = na
- var label lab1 =na
- var label lab2 =na
- var array<box> boxArr1 = array.new<box>(0)
- var array<box> boxArr2 = array.new<box>(0)
- var array<label>labArr1= array.new<label>(0)
- var array<label>labArr2= array.new<label>(0)
- //function
- boxPaint(_int, col, borCol, txtCol, period, numBoxes, mult,spacerMult,offset)=>
- var box bx = na
- var array<box> boxArr = array.new<box>(0)
- for i=_int+1 to 0 by 2
- 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":
- 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)
- array.push(boxArr,bx)
- if array.size(boxArr)>numBoxes
- box.delete(array.shift(boxArr))
- bx
- labelPrint(_int,col, period, numBoxes,_size, mult,spacerMult)=>
- var label lab =na
- var array<label> labArr = array.new<label>(0)
- for i=_int+1 to 0 by 2
- 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 🌚 ☾ 🌚︎
- array.push(labArr,lab)
- if array.size(labArr)>numBoxes
- label.delete(array.shift(labArr))
- lab
- //painting the boxes
- if isFullMoon and showHalfCycles
- bx1:=boxPaint(53,colWaning,borderColor,showText1?txtCol1:colorNone, halfCycle,boxesToShow,boxHeight,1,0)
- array.push(boxArr1,bx1)
- bx2:=boxPaint(52,colWaxing,borderColor,showText1?txtCol1:colorNone, halfCycle,boxesToShow ,boxHeight,1,0)
- array.push(boxArr2,bx2)
- if isFullMoon and showEmojis
- lab1:=labelPrint(53,colWaning, halfCycle, boxesToShow, size.large,boxHeight,1)
- array.push(labArr1,lab1)
- lab2:=labelPrint(52,colWaxing, halfCycle, boxesToShow, size.large,boxHeight,1 )
- array.push(labArr2,lab2)
- var box bx3 = na
- var box bx4 = na
- var box bx5 = na
- var box bx6 = na
- 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)
- if isFullMoon and showQrtCycles
- bx3:=boxPaint(53,colWanGibb,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow, boxHeight,2,0)
- array.push(boxArr3,bx3)
- bx4:=boxPaint(52,colWaxCres,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow ,boxHeight,2,0)
- array.push(boxArr4,bx4)
- bx5:=boxPaint(53,colWanCres,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow, boxHeight,2,QrtCycle)
- array.push(boxArr5,bx5)
- bx6:=boxPaint(52,colWaxGibb,borderColor2,showText2?txtCol2:colorNone, QrtCycle,boxesToShow ,boxHeight,2,QrtCycle)
- array.push(boxArr6,bx6)
Advertisement
Add Comment
Please, Sign In to add comment