Astro: Planetary Longitudes
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BarefootJoey

// ██████████████████████████████████████████████████████████████████████   _____ __   _      _______  _____  _______ _______ _______
// █▄─▄─▀██▀▄─██▄─▄▄▀█▄─▄▄─█▄─▄▄─█─▄▄─█─▄▄─█─▄─▄─███▄─▄█─▄▄─█▄─▄▄─█▄─█─▄█     |   | \  |      |______ |_____] |_____| |       |______
// ██─▄─▀██─▀─███─▄─▄██─▄█▀██─▄███─██─█─██─███─███─▄█─██─██─██─▄█▀██▄─▄██   __|__ |  \_|      ______| |       |     | |_____  |______ 
// █▄▄▄▄██▄▄█▄▄█▄▄█▄▄█▄▄▄▄▄█▄▄▄███▄▄▄▄█▄▄▄▄██▄▄▄██▄▄▄███▄▄▄▄█▄▄▄▄▄██▄▄▄██                                                            

//@version=5
indicator("Astro: Planetary Longitudes", overlay=false)

import BarefootJoey/AstroLib/1 as AL

showlast = input.int(1000, "Show last?", minval=1, tooltip="Number of historical plots to display. The fewer plots, the faster the load time (especially on loweer timeframes). Use the Time Machine feature for distant historical analysis.")
precision = input.float(6.0, "Aspect Precision (+/- °)", minval=0, maxval=15)

grtm = "🕜 Time Machine 🕜"
gsd = input.bool(false, "Activate Time Machine", group=grtm)
sdms = input.time(timestamp("2022-04-20T00:00:00"), "Select Date", group=grtm)
gt = gsd ? sdms : time

grol = "🔭 Observer Location 🔭"
htz = input.float(0, "Hour", step=0.5, inline="2", group=grol)
mtz = input.int(0, "Minute", minval=0, maxval=45, inline="2",  group=grol)
tz = htz + math.round(mtz / 60, 4)
latitude = input.float(0, "Latitude", inline="1", group=grol)
longitude = input.float(0, "Longitude", inline="1", group=grol)
geo = input.bool(false, "Geocentric?", tooltip="Leave this box unchecked for heliocentric.", group=grol)
geoout = geo ? 1 : 0

grsl = "Labels"
smoo = input.bool(true, "Moon", inline="3", group=grsl)
ssun = input.bool(true, "Sun", inline="3", group=grsl)
smer = input.bool(true, "Mercury", inline="3", group=grsl)
sven = input.bool(true, "Venus", inline="3", group=grsl)
sear = input.bool(true, "Earth", inline="4", group=grsl)
smar = input.bool(true, "Mars", inline="4", group=grsl)
sjup = input.bool(true, "Jupiter", inline="4", group=grsl)
ssat = input.bool(false, "Saturn", inline="4", group=grsl)
sura = input.bool(false, "Uranus", inline="5", group=grsl)
snep = input.bool(false, "Neptune", inline="5", group=grsl)
splu = input.bool(false, "Pluto", inline="5", group=grsl)

iTxtSize=input.string("Small", title="Text Size", options=["Auto", "Tiny", "Small", "Normal", "Large"], group=grsl, inline="1")
vTxtSize=iTxtSize == "Auto" ? size.auto : iTxtSize == "Tiny" ? size.tiny : iTxtSize == "Small" ? size.small : iTxtSize == "Normal" ? size.normal : iTxtSize == "Large" ? size.large : size.small

day = AL.J2000(AL.JDN(gt, 0, tz))
dayr = AL.J2000(AL.JDN(gt, 1, tz))

moonlon = AL.getmoon(geoout, day, dayr, latitude, longitude)
sunlon = AL.getsun(geoout, day, dayr, latitude, longitude, tz)
merclon = AL.getplanet(1,geoout, day, dayr, latitude, longitude, tz)
venulon = AL.getplanet(2,geoout, day, dayr, latitude, longitude, tz)
eartlon = AL.getplanet(3,geoout, day, dayr, latitude, longitude, tz)
marslon = AL.getplanet(4,geoout, day, dayr, latitude, longitude, tz)
jupilon = AL.getplanet(5,geoout, day, dayr, latitude, longitude, tz)
satulon = AL.getplanet(6,geoout, day, dayr, latitude, longitude, tz)
uranlon = AL.getplanet(7,geoout, day, dayr, latitude, longitude, tz)
neptlon = AL.getplanet(8,geoout, day, dayr, latitude, longitude, tz)
plutlon = AL.getplanet(9,geoout, day, dayr, latitude, longitude, tz)

transp=0
plot(moonlon, "Moon", color=color.new(color.silver,transp), style=plot.style_circles, show_last=showlast)
plot(sunlon, "Sun", color=color.new(color.yellow,transp), style=plot.style_circles, show_last=showlast)
plot(merclon, "Mercury", color=color.new(color.maroon,transp), style=plot.style_circles, show_last=showlast)
plot(venulon, "Venus", color=color.new(color.green,transp), style=plot.style_circles, show_last=showlast)
plot(eartlon, "Earth", color=color.new(color.blue,transp), style=plot.style_circles, show_last=showlast)
plot(marslon, "Mars", color=color.new(color.red,transp), style=plot.style_circles, show_last=showlast)
plot(jupilon, "Jupiter", color=color.new(color.orange,transp), style=plot.style_circles, show_last=showlast)
plot(satulon, "Saturn", color=color.new(color.gray,transp), style=plot.style_circles, show_last=showlast, display=display.none)
plot(uranlon, "Uranus", color=color.new(color.navy,transp), style=plot.style_circles, show_last=showlast, display=display.none)
plot(neptlon, "Neptune", color=color.new(color.fuchsia,transp), style=plot.style_circles, show_last=showlast, display=display.none)
plot(plutlon, "Pluto", color=color.new(color.black,transp), style=plot.style_circles, show_last=showlast, display=display.none)

var label sun = na
var label moon = na
var label mercury = na
var label venus = na
var label earth = na
var label mars = na
var label jupiter = na
var label saturn = na
var label uranus = na
var label neptune = na
var label pluto = na

bull_emo="🟢"
bear_emo="🔴"

retro_tt(deg) => deg > deg[1] ? "" : " ℞" 

if ssun 
    sun := label.new(bar_index, y=sunlon, text="☉︎ Sun" + retro_tt(sunlon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.yellow,0), tooltip="☉︎ Sun" + retro_tt(sunlon) +  AL.virinchiaspectemo(sunlon, bull_emo, bear_emo) + "\n" + AL.degsignf(sunlon) + "\n" + AL.degnash(sunlon) + "\n" + str.tostring(sunlon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(sunlon), precision) + "°")
    label.delete(sun[1])
if smoo 
    moon := label.new(bar_index, y=moonlon, text="☽︎ Moon" + retro_tt(moonlon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(3),0), tooltip="☽︎ Moon" + retro_tt(moonlon) + AL.virinchiaspectemo(moonlon, bull_emo, bear_emo) + "\n" + AL.degsignf(moonlon) + "\n" + AL.degnash(moonlon) + "\n" + str.tostring(moonlon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(moonlon), precision) + "°")
    label.delete(moon[1])
if smer 
    mercury := label.new(bar_index, y=merclon, text="☿ Mercury" + retro_tt(merclon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(1),0), tooltip="☿ Mercury" + retro_tt(merclon) + AL.virinchiaspectemo(merclon, bull_emo, bear_emo) + "\n" + AL.degsignf(merclon) + "\n" + AL.degnash(merclon) + "\n" + str.tostring(merclon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(merclon), precision) + "°")
    label.delete(mercury[1])
if sven 
    venus := label.new(bar_index, y=venulon, text="♀ Venus" + retro_tt(venulon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(2),0), tooltip="♀ Venus" + retro_tt(venulon) + AL.virinchiaspectemo(venulon, bull_emo, bear_emo) + "\n" + AL.degsignf(venulon) + "\n" + AL.degnash(venulon) + "\n" + str.tostring(venulon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(venulon), precision) + "°")
    label.delete(venus[1])
if sear  
    earth := label.new(bar_index, y=eartlon, text="🜨 Earth" + retro_tt(eartlon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.blue,0), tooltip="🜨 Earth" + retro_tt(eartlon) + AL.virinchiaspectemo(eartlon, bull_emo, bear_emo) + "\n" + AL.degsignf(eartlon) + "\n" + AL.degnash(eartlon) + "\n" + str.tostring(eartlon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(eartlon), precision) + "°")
    label.delete(earth[1])
if smar 
    mars := label.new(bar_index, y=marslon, text="♂ Mars" + retro_tt(marslon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(4),0), tooltip="♂ Mars" + retro_tt(marslon) + AL.virinchiaspectemo(marslon, bull_emo, bear_emo) + "\n" + AL.degsignf(marslon) + "\n" + AL.degnash(marslon) + "\n" + str.tostring(marslon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(marslon), precision) + "°")
    label.delete(mars[1])
if sjup 
    jupiter := label.new(bar_index, y=jupilon, text="♃ Jupiter" + retro_tt(jupilon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(5),0), tooltip="♃ Jupiter" + retro_tt(jupilon) + AL.virinchiaspectemo(jupilon, bull_emo, bear_emo) + "\n" + AL.degsignf(jupilon) + "\n" + AL.degnash(jupilon) + "\n" + str.tostring(jupilon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(jupilon), precision) + "°")
    label.delete(jupiter[1])
if ssat 
    saturn := label.new(bar_index, y=satulon, text="♄ Saturn" + retro_tt(satulon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(6),0), tooltip="♄ Saturn" + retro_tt(satulon) + AL.virinchiaspectemo(satulon, bull_emo, bear_emo) + "\n" + AL.degsignf(satulon) + "\n" + AL.degnash(satulon) + "\n" + str.tostring(satulon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(satulon), precision) + "°")
    label.delete(saturn[1])
if sura 
    uranus := label.new(bar_index, y=uranlon, text="⛢ Uranus" + retro_tt(uranlon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.navy,0), tooltip="⛢ Uranus" + retro_tt(uranlon) + AL.virinchiaspectemo(uranlon, bull_emo, bear_emo) + "\n" + AL.degsignf(uranlon) + "\n" + AL.degnash(uranlon) + "\n" + str.tostring(uranlon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(uranlon), precision) + "°")
    label.delete(uranus[1])
if snep 
    neptune := label.new(bar_index, y=neptlon, text="♆ Neptune" + retro_tt(neptlon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(8),0), tooltip="♆ Neptune" + retro_tt(neptlon) + AL.virinchiaspectemo(neptlon, bull_emo, bear_emo) + "\n" + AL.degsignf(neptlon) + "\n" + AL.degnash(neptlon) + "\n" + str.tostring(neptlon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(neptlon), precision) + "°")
    label.delete(neptune[1])
if splu 
    pluto := label.new(bar_index, y=plutlon, text="♇ Pluto" + retro_tt(plutlon), size=vTxtSize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(AL.PlanetColor(9),0), tooltip="♇ Pluto" + retro_tt(plutlon) + AL.virinchiaspectemo(plutlon, bull_emo, bear_emo) + "\n" + AL.degsignf(plutlon) + "\n" + AL.degnash(plutlon) + "\n" + str.tostring(plutlon, "#.##") + "°" + "\n" + AL.aspectsignprecisionV2ext(AL.degtolowest180(plutlon), precision) + "°")
    label.delete(pluto[1])

hf_transp = 66
h1 = hline(0, "Aries", color.new(color.red,hf_transp))
h2 = hline(30, "Taurus", color.new(color.orange,hf_transp))
h3 = hline(60, "Gemini", color.new(color.yellow,hf_transp))
h4 = hline(90, "Cancer",color.new(color.green,hf_transp))
h5 = hline(120, "Leo",color.new(color.aqua,hf_transp))
h6 = hline(150, "Virgo",color.new(color.navy,hf_transp))
h7 = hline(180, "Libra",color.new(color.purple,hf_transp))
h8 = hline(210, "Scorpio",color.new(color.navy,hf_transp))
h9 = hline(240, "Saggitarius",color.new(color.aqua,hf_transp))
h10 = hline(270, "Capricorn",color.new(color.green,hf_transp))
h11 = hline(300, "Aquarius",color.new(color.yellow,hf_transp))
h12 = hline(330, "Pisces",color.new(color.orange,hf_transp))
h13 = hline(360, "↻ Aries",color.new(color.red,hf_transp))

// EoS made w/ ❤ by @BarefootJoey ✌💗📈