Astro: Planetary Channel Lines
// 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 Channel Lines", overlay=true)

import BarefootJoey/AstroLib/1 as AL

tpi = math.pi * 2

planet1_in = input.string("☿ Mercury", "Which planets?", options=["☉︎ Sun", "☽︎ Moon", "☿ Mercury", "♀ Venus", "🜨 Earth", "♂ Mars", "♃ Jupiter", "♄ Saturn", "⛢ Uranus", "♆ Neptune", "♇ Pluto"], inline="1")
planet2_in = input.string("♂ Mars", " ", options=["None", "☉︎ Sun", "☽︎ Moon", "☿ Mercury", "♀ Venus", "🜨 Earth", "♂ Mars", "♃ Jupiter", "♄ Saturn", "⛢ Uranus", "♆ Neptune", "♇ Pluto"], inline="1")
base = input.int(0, "Base Multiple", minval=0, tooltip="Vertical offset")
scaler = input.float(1.0, "1° = $", minval=0, tooltip="Recommended factor of 10 (1000, 100, 10, 1, 0.1, 0.01, 0.001, etc)")
mirror_in = input.bool(false, "Mirror?")
showlast = input.int(250, "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.")
lontransp = input.int(50, "Transparency", minval=0, maxval=100)
precision = input.float(6.0, "Aspect Precision (+/- °)", minval=0, maxval=15)
iTxtSize=input.string("Small", title="Text Size", options=["Auto", "Tiny", "Small", "Normal", "Large"])
vTxtSize=iTxtSize == "Auto" ? size.auto : iTxtSize == "Tiny" ? size.tiny : iTxtSize == "Small" ? size.small : iTxtSize == "Normal" ? size.normal : iTxtSize == "Large" ? size.large : size.small
position = input.string(position.top_center, "Info Position", [position.top_center, position.top_right, position.middle_right, position.bottom_right, position.bottom_center, position.bottom_left, position.middle_left, position.top_left])

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, tooltip="East is positive (+), and West is negative (-).")
longitude = input.float(0, "Longitude", inline="1", group=grol, tooltip="North is positive (+), and South is negative (-).")
geo = input.bool(false, "Geocentric?", tooltip="Leave this box unchecked for heliocentric.", group=grol)
geoout = geo ? 1 : 0

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

planet1_out = planet1_in == "☉︎ Sun" ? AL.getsun(geoout, day, dayr, latitude, longitude, tz) : planet1_in == "☽︎ Moon" ? AL.getmoon(geoout, day, dayr, latitude, longitude) : planet1_in == "☿ Mercury" ? AL.getplanet(1, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "♀ Venus" ? AL.getplanet(2, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "🜨 Earth" ? AL.getplanet(3, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "♂ Mars" ? AL.getplanet(4, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "♃ Jupiter" ? AL.getplanet(5, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "♄ Saturn" ? AL.getplanet(6, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "⛢ Uranus" ? AL.getplanet(7, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "♆ Neptune" ? AL.getplanet(8, geoout, day, dayr, latitude, longitude, tz) : planet1_in == "♇ Pluto" ? AL.getplanet(9, geoout, day, dayr, latitude, longitude, tz) : na
col1_out = planet1_in == "☉︎ Sun" ? color.yellow : planet1_in == "☽︎ Moon" ? color.silver : planet1_in == "☿ Mercury" ? color.maroon : planet1_in == "♀ Venus" ? color.green : planet1_in == "🜨 Earth" ? color.blue : planet1_in == "♂ Mars" ? color.red : planet1_in == "♃ Jupiter" ? color.orange : planet1_in == "♄ Saturn" ? color.gray : planet1_in == "⛢ Uranus" ? color.navy : planet1_in == "♆ Neptune" ? color.fuchsia : planet1_in == "♇ Pluto" ? color.black : na

planet2_out = planet2_in == "☉︎ Sun" ? AL.getsun(geoout, day, dayr, latitude, longitude, tz) : planet2_in == "☽︎ Moon" ? AL.getmoon(geoout, day, dayr, latitude, longitude) : planet2_in == "☿ Mercury" ? AL.getplanet(1, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "♀ Venus" ? AL.getplanet(2, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "🜨 Earth" ? AL.getplanet(3, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "♂ Mars" ? AL.getplanet(4, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "♃ Jupiter" ? AL.getplanet(5, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "♄ Saturn" ? AL.getplanet(6, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "⛢ Uranus" ? AL.getplanet(7, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "♆ Neptune" ? AL.getplanet(8, geoout, day, dayr, latitude, longitude, tz) : planet2_in == "♇ Pluto" ? AL.getplanet(9, geoout, day, dayr, latitude, longitude, tz) : na
col2_out = planet2_in == "☉︎ Sun" ? color.yellow : planet2_in == "☽︎ Moon" ? color.silver : planet2_in == "☿ Mercury" ? color.maroon : planet2_in == "♀ Venus" ? color.green : planet2_in == "🜨 Earth" ? color.blue : planet2_in == "♂ Mars" ? color.red : planet2_in == "♃ Jupiter" ? color.orange : planet2_in == "♄ Saturn" ? color.gray : planet2_in == "⛢ Uranus" ? color.navy : planet2_in == "♆ Neptune" ? color.fuchsia : planet2_in == "♇ Pluto" ? color.black : na

mirror_out = mirror_in ? -1 : 1

plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 0) + (scaler * 360 * base), "Planet 1.0 (Lo)", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 1) + (scaler * 360 * base), "Planet 1.1", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 2) + (scaler * 360 * base), "Planet 1.2", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 3) + (scaler * 360 * base), "Planet 1.3", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 4) + (scaler * 360 * base), "Planet 1.4", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 5) + (scaler * 360 * base), "Planet 1.5", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 6) + (scaler * 360 * base), "Planet 1.6", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 7) + (scaler * 360 * base), "Planet 1.7", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 8) + (scaler * 360 * base), "Planet 1.8", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet1_out * scaler) + (scaler * 360 * 9) + (scaler * 360 * base), "Planet 1.9 (Hi)", color=color.new(col1_out,lontransp), style=plot.style_circles, show_last=showlast)

plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 0) + (scaler * 360 * base), "Planet 2.0 (Lo)", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 1) + (scaler * 360 * base), "Planet 2.1", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 2) + (scaler * 360 * base), "Planet 2.2", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 3) + (scaler * 360 * base), "Planet 2.3", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 4) + (scaler * 360 * base), "Planet 2.4", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 5) + (scaler * 360 * base), "Planet 2.5", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 6) + (scaler * 360 * base), "Planet 2.6", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 7) + (scaler * 360 * base), "Planet 2.7", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 8) + (scaler * 360 * base), "Planet 2.8", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)
plot((mirror_out * planet2_out * scaler) + (scaler * 360 * 9) + (scaler * 360 * base), "Planet 2.9 (Hi)", color=color.new(col2_out,lontransp), style=plot.style_circles, show_last=showlast)

retro_bg1(deg) => deg > deg[1]? color.new(color.black,100) : color.new(col1_out, 80)
bgcolor(retro_bg1(planet1_out), title="Retrograde Background 1", show_last=showlast, display=display.none)

retro_bg2(deg) => deg > deg[1]? color.new(color.black,100) : color.new(col2_out, 80)
bgcolor(retro_bg2(planet2_out), title="Retrograde Background 2", show_last=showlast, display=display.none)

var table Info = na
table.delete(Info)
Info := table.new(position, 3, 1)
if barstate.islast
    table.cell(Info, 0, 0, 
      text = planet1_in, 
      text_size = vTxtSize, 
      text_color = color.new(col1_out,0),
      tooltip = AL.aspectsignprecisionV2ext(planet1_out, precision) + "°\nPrecision: +/- " + str.tostring(precision) + "°")
    table.cell(Info, 1, 0, 
      text = " ")
    table.cell(Info, 2, 0, 
      text = planet2_in, 
      text_size = vTxtSize, 
      text_color = color.new(col2_out,0),
      tooltip = AL.aspectsignprecisionV2ext(planet2_out, precision) + "°\nPrecision: +/- " + str.tostring(precision) + "°")

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