Moon Phases/Apogee & Perigee/Eclipses/North Node by BT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © boratuncer

//@version=5
indicator(title="Moon Phases / Apogee & Perigee / Eclipses / North & South Nodes by BT", shorttitle="Moon by BT", overlay=true, max_lines_count=500, max_labels_count=500)

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
ig1="Generic Inputs"
year1 = input.int(2021, "Start Year", group=ig1)
year2 = input.int(2022, "Stop Year", group=ig1)
ig2="Moon Phases"
showMoonF = input.bool(true, "Show Full Moons", group=ig2)
color colorMP_F = input.color(color.white, "Full Moon Color", group=ig2)
showMoonN = input.bool(true, "Show New Moons", group=ig2)
color colorMP_N = input.color(color.gray, "New Moon Color", group=ig2)
ig3="Apogee / Perigee"
showApogee = input.bool(false, "Show Apogees", group=ig3)
color colorAPO = input.color(color.yellow, "Apogee Color", group=ig3)
showPerigee = input.bool(false, "Show Perigees", group=ig3)
color colorPER = input.color(color.red, "Perigee Color", group=ig3)
ig4="North Node"
showNorth = input.bool(false, "Show North Node ", group=ig4)
color colorNorth = input.color(color.blue, "North Node Color", group=ig4)
ig5="Solar & Lunar Eclipses"
showSolarA = input.bool(false, "Show Solar Eclipses (Annular) ", group=ig5)
showSolarP = input.bool(false, "Show Solar Eclipses (Parial) ", group=ig5)
showSolarT = input.bool(false, "Show Solar Eclipses (Total) ", group=ig5)
color colorEclipseS = input.color(color.green, "Solar Eclipses Color", group=ig5)
showLunarPE = input.bool(false, "Show Lunar Eclipses (Penumbral) ", group=ig5)
showLunarP = input.bool(false, "Show Lunar Eclipses (Parial) ", group=ig5)
showLunarT = input.bool(false, "Show Lunar Eclipses (Total) ", group=ig5)
color colorEclipseL = input.color(color.purple, "Lunar Eclipses Color", group=ig5)


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Variables
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//color colorMP_N = color.new(color.gray, 20)             // Moon phases new
//color colorMP_F = color.new(color.white, 20)            // Moon phases full
//color colorAPO = color.new(color.yellow, 20)            // Moon phases apogee
//color colorPER = color.new(color.red, 20)               // Moon phases apogee
//color colorNorth = color.new(color.blue, 20)            // North node
//color colorEclipseS = color.new(color.green, 20)        // Solar eclipses
//color colorEclipseL = color.new(color.purple, 20)       // Lunar eclipses


// Format as 2021-01-13T04:32
//var PHASES_N = array.from("2021-01-13")
string[] PHASES_N = array.from("2015-01-20", "2015-02-18", "2015-03-20", "2015-04-18", "2015-05-18", "2015-06-16", "2015-07-16", "2015-08-14", "2015-09-13", "2015-10-13", "2015-11-11", "2015-12-11",
                               "2016-01-10", "2016-01-08", "2016-03-09", "2016-04-07", "2016-05-06", "2016-06-05", "2016-07-04", "2016-08-02", "2016-09-01", "2016-10-01", "2016-10-30", "2016-11-29", "2016-12-29",
                               "2017-01-28", "2017-02-26", "2017-03-28", "2017-04-26", "2017-05-25", "2017-06-24", "2017-07-23", "2017-08-21", "2017-09-20", "2017-10-19", "2017-11-18", "2017-12-18",
                               "2018-01-17", "2018-02-15", "2018-03-17", "2018-04-16", "2018-05-15", "2018-06-13", "2018-07-13", "2018-08-11", "2018-09-09", "2018-10-09", "2018-11-07", "2018-12-07",
                               "2019-01-06", "2019-02-04", "2019-03-06", "2019-04-05", "2019-05-04", "2019-06-03", "2019-07-02", "2019-08-01", "2019-08-30", "2019-09-28", "2019-10-29", "2019-11-26", "2019-12-26",
                               "2020-01-24", "2020-02-23", "2020-03-24", "2020-04-23", "2020-05-22", "2020-06-21", "2020-07-20", "2020-08-19", "2020-09-17", "2020-10-16", "2020-11-15", "2020-12-14",
                               "2021-01-13", "2021-02-11", "2021-03-13", "2021-04-12", "2021-05-11", "2021-06-10", "2021-07-10", "2021-08-08", "2021-09-07", "2021-10-06", "2021-11-04", "2021-12-04",
                               "2022-01-02", "2022-02-01", "2022-03-02", "2022-04-01", "2022-04-30", "2022-05-30", "2022-06-29", "2022-07-28", "2022-08-27", "2022-09-25", "2022-10-25", "2022-11-23", "2022-12-23",
                               "2023-01-21", "2023-02-20", "2023-03-21", "2023-04-20", "2023-05-19", "2023-06-18", "2023-07-17", "2023-08-16", "2023-09-15", "2023-10-14", "2023-11-13", "2023-12-12")


string[] PHASES_F = array.from("2015-01-05", "2015-02-03", "2015-03-05", "2015-04-04", "2015-05-04", "2015-06-02", "2015-07-02", "2015-07-31", "2015-08-29", "2015-09-28", "2015-10-27", "2015-11-25", "2015-12-25",
                               "2016-01-24", "2016-01-22", "2016-03-23", "2016-04-22", "2016-05-21", "2016-06-20", "2016-07-19", "2016-08-10", "2016-09-16", "2016-10-06", "2016-11-14", "2016-12-14",
                               "2017-01-12", "2017-02-11", "2017-03-12", "2017-04-11", "2017-05-10", "2017-06-09", "2017-07-09", "2017-08-07", "2017-09-06", "2017-10-05", "2017-11-04", "2017-12-03",
                               "2018-01-02", "2018-01-31", "2018-03-02", "2018-03-31", "2018-04-30", "2018-05-29", "2018-06-28", "2018-07-27", "2018-08-26", "2018-09-25", "2018-10-24", "2018-11-23", "2018-12-22",
                               "2019-01-21", "2019-02-19", "2019-03-21", "2019-04-19", "2019-05-18", "2019-06-17", "2019-07-16", "2019-08-15", "2019-09-14", "2019-10-13", "2019-11-12", "2019-12-12",
                               "2020-01-10", "2020-02-09", "2020-03-09", "2020-04-08", "2020-05-07", "2020-06-05", "2020-07-05", "2020-08-03", "2020-09-02", "2020-10-01", "2020-10-31", "2020-11-30", "2020-12-30",
                               "2021-01-28", "2021-02-27", "2021-03-28", "2021-04-27", "2021-05-26", "2021-06-24", "2021-07-24", "2021-08-22", "2021-09-20", "2021-10-20", "2021-11-19", "2021-12-19",
                               "2022-01-17", "2022-02-16", "2022-03-18", "2022-04-16", "2022-05-16", "2022-06-14", "2022-07-13", "2022-08-12", "2022-09-10", "2022-10-09", "2022-11-08", "2022-12-08",
                               "2023-01-06", "2023-02-05", "2023-03-07", "2023-04-06", "2023-05-05", "2023-06-04", "2023-07-03", "2023-08-01", "2023-08-31", "2023-09-29", "2023-10-28", "2023-11-27", "2023-12-27")


string[] APOGEE = array.from("2015-01-09", "2015-02-06", "2015-03-05", "2015-04-01", "2015-04-29", "2015-05-26", "2015-06-23", "2015-07-21", "2015-08-18", "2015-09-14", "2015-10-11", "2015-11-07", "2015-12-05",
                             "2016-01-02", "2016-01-30", "2016-02-27", "2016-03-25", "2016-04-21", "2016-05-18", "2016-06-15", "2016-07-13", "2016-08-10", "2016-09-16", "2016-10-04", "2016-10-31", "2016-11-27", "2016-12-25",
                             "2017-01-22", "2017-02-18", "2017-03-18", "2017-04-15", "2017-05-12", "2017-06-08", "2017-07-06", "2017-08-02", "2017-08-30", "2017-09-27", "2017-10-25", "2017-11-21", "2017-12-19",
                             "2018-01-15", "2018-02-11", "2018-03-11", "2018-04-08", "2018-05-06", "2018-06-02", "2018-06-30", "2018-07-27", "2018-08-23", "2018-09-20", "2018-10-17", "2018-11-14", "2018-12-12",
                             "2019-01-09", "2019-02-05", "2019-03-04", "2019-04-01", "2019-04-28", "2019-05-26", "2019-06-23", "2019-07-21", "2019-08-17", "2019-09-13", "2019-10-10", "2019-11-07", "2019-12-05",
                             "2020-01-02", "2020-01-29", "2020-02-26", "2020-03-24", "2020-04-20", "2020-05-18", "2020-06-15", "2020-07-12", "2020-08-09", "2020-09-06", "2020-10-03", "2020-10-30", "2020-11-27", "2020-12-24",
                             "2021-01-21", "2021-02-18", "2021-03-18", "2021-04-14", "2021-05-11", "2021-06-08", "2021-07-05", "2021-08-02", "2021-08-30", "2021-09-26", "2021-10-24", "2021-11-21", "2021-12-18",
                             "2022-01-14", "2022-02-11", "2022-03-10", "2022-04-07", "2022-05-05", "2022-06-02", "2022-06-29", "2022-07-26", "2022-08-22", "2022-09-19", "2022-10-17", "2022-11-14", "2022-12-12",
                             "2023-01-08", "2023-02-04", "2023-03-03", "2023-03-31", "2023-04-28", "2023-05-26", "2023-06-22", "2023-07-20", "2023-08-16", "2023-09-12", "2023-10-10", "2023-11-06", "2023-12-04")


string[] PERIGEE = array.from("2015-01-21", "2015-02-19", "2015-03-19", "2015-04-17", "2015-05-15", "2015-06-10", "2015-07-05", "2015-08-02", "2015-08-30", "2015-09-28", "2015-10-26", "2015-11-23", "2015-12-21",
                              "2016-01-15", "2016-02-11", "2016-03-10", "2016-04-07", "2016-05-06", "2016-06-03", "2016-07-01", "2016-07-27", "2016-08-22", "2016-09-18", "2016-10-16", "2016-11-14", "2016-12-12",
                              "2017-01-10", "2017-02-06", "2017-03-03", "2017-03-30", "2017-04-27", "2017-05-26", "2017-06-23", "2017-07-21", "2017-08-18", "2017-09-13", "2017-10-09", "2017-11-06", "2017-12-04",
                              "2018-01-01", "2018-01-30", "2018-02-27", "2018-03-26", "2018-04-20", "2018-05-17", "2018-06-14", "2018-07-13", "2018-08-10", "2018-09-08", "2018-10-05", "2018-10-31", "2018-11-26", "2018-12-24",
                              "2019-01-21", "2019-02-19", "2019-03-19", "2019-04-16", "2019-05-13", "2019-06-07", "2019-07-05", "2019-08-02", "2019-08-30", "2019-09-28", "2019-10-26", "2019-11-23", "2019-12-18",
                              "2020-01-13", "2020-02-10", "2020-03-10", "2020-04-07", "2020-05-06", "2020-06-03", "2020-06-30", "2020-07-25", "2020-08-21", "2020-09-18", "2020-10-16", "2020-11-14", "2020-12-12",
                              "2021-01-09", "2021-02-03", "2021-03-02", "2021-03-30", "2021-04-27", "2021-05-26", "2021-06-23", "2021-07-21", "2021-08-17", "2021-09-11", "2021-10-08", "2021-11-05", "2021-12-04",
                              "2022-01-01", "2022-01-30", "2022-02-26", "2022-03-23", "2022-04-19", "2022-05-17", "2022-06-14", "2022-07-13", "2022-08-10", "2022-09-07", "2022-10-04", "2022-10-29", "2022-11-26", "2022-12-24",
                              "2023-01-21", "2023-02-19", "2023-03-19", "2023-04-16", "2023-05-11", "2023-06-06", "2023-07-04", "2023-08-02", "2023-08-30", "2023-09-28", "2023-10-26", "2023-11-21", "2023-12-16")

string[] NORTHN = array.from("2015-11-10", "2017-04-28", "2018-10-16", "2020-06-05", "2021-12-25", "2023-07-12", "2025-01-29", "2026-08-18", "2028-03-07", "2029-09-24", "2031-04-14")

string[] SOLAR_E_A = array.from("2020-06-21", "2021-06-10", "2023-10-14", "2024-10-02")
string[] SOLAR_E_P = array.from("2015-03-20", "2022-04-30","2022-10-25", "2025-03-29", "2025-09-21")
string[] SOLAR_E_T = array.from("2020-12-14", "2021-12-04", "2023-04-20", "2024-04-08")

string[] LUNAR_E_PE = array.from("2016-09-16", "2017-02-11", "2018-01-31", "2020-01-10", "2020-06-05", "2020-07-04", "2020-11-29", "2023-05-05", "2024-03-24")
string[] LUNAR_E_P = array.from("2017-08-07", "2019-07-16", "2021-11-18", "2023-10-29", "2024-10-17")
string[] LUNAR_E_T = array.from("2015-09-28", "2018-07-27", "2019-01-21", "2021-05-25", "2022-05-15", "2022-11-07", "2024-10-17", "2025-03-13", "2025-09-07")

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

debug(string labeltext) =>
    if barstate.islast
        label.new(bar_index, close, labeltext, style=label.style_label_left, textalign=text.align_left)


vlineTime(BarIndex, Color, LineStyle, LineWidth, Text) => // Verticle Line Function, ≈50-54 lines maximum allowable per indicator
    //m=ta.lowest(200) * 0.90
    label.new(x=BarIndex, y=0, color=Color, text=Text, xloc=xloc.bar_time)
    ret = line.new(BarIndex, low - ta.tr, BarIndex, high + ta.tr, xloc=xloc.bar_time, extend=extend.both, style=LineStyle, width=LineWidth, color=Color)
    line.delete(ret[1])

drawLines(show, inputarray, year1, year2, colorLine, inputtext) =>
    for i = 0 to array.size(inputarray) - 1
        arr = str.split(array.get(inputarray, i), '-')
        int y = math.round(str.tonumber(str.tostring(array.get(arr, 0))))
        int m = math.round(str.tonumber(str.tostring(array.get(arr, 1))))
        int d = math.round(str.tonumber(str.tostring(array.get(arr, 2))))

        for var j=year1 to year2
            if(y == j)
                vlineTime((show) ? timestamp(y, m, d, 00, 00) : na, colorLine, line.style_dashed, 2, inputtext)
                //debug(str.tostring(y))


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Script body
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
drawLines(showMoonN, PHASES_N, year1, year2, colorMP_N, "New Moon")                 // Draw new moons
drawLines(showMoonF, PHASES_F, year1, year2, colorMP_F, "Full Moon")                // Draw full moons

drawLines(showApogee, APOGEE, year1, year2, colorAPO, "Apogee")                     // Draw apogee
drawLines(showPerigee, PERIGEE, year1, year2, colorPER, "Perigee")                  // Draw perigee

drawLines(showNorth, NORTHN, year1, year2, colorNorth, "North Node")                  // Draw north node

drawLines(showSolarA, SOLAR_E_A, year1, year2, colorEclipseS, "Solar Eclipses (Annular)")                    // Solar Exlipses (Annular)
drawLines(showSolarP, SOLAR_E_P, year1, year2, colorEclipseS, "Solar Eclipses (Partial)")                    // Solar Exlipses (Partial)
drawLines(showSolarT, SOLAR_E_T, year1, year2, colorEclipseS, "Solar Eclipses (Total)")                      // Solar Exlipses (Total)

drawLines(showLunarPE, LUNAR_E_PE, year1, year2, colorEclipseL, "Lunar Eclipses (Penumbral)")                // Lunar Exlipses (Annular)
drawLines(showLunarP, LUNAR_E_P, year1, year2, colorEclipseL, "Lunar Eclipses (Partial)")                    // Lunar Exlipses (Partial)
drawLines(showLunarT, LUNAR_E_T, year1, year2, colorEclipseL, "Lunar Eclipses (Total)")                      // Lunar Exlipses (Total)


