Bitcoin Halving Events
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kevindcarr

//@version=5
indicator(title='Bitcoin Halving Events', shorttitle='Bitcoin Halvings', overlay=true)
showLabels = input(defval=true, title="Show labels")

isDate(y, m, d) =>
    val = timestamp(y, m, d)
    if val <= time and val > time[1]
        true
    else
        false

// First Halving
if isDate(2012, 11, 28)
    line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, color=color.yellow)
    if (showLabels)
        label.new(bar_index, low, text='1st Halving - Nov 28, 2012', style=label.style_label_upper_left, textcolor=color.black, color=color.yellow, textalign=text.align_right)

// Second Halving
if isDate(2016, 7, 9)
    line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, color=color.yellow)
    if (showLabels)
        label.new(bar_index, low, text='2nd Halving - Jul 9, 2016', style=label.style_label_upper_left, textcolor=color.black, color=color.yellow, textalign=text.align_right)

// Third Halving
if isDate(2020, 5, 11)
    line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, color=color.yellow)
    if (showLabels)
        label.new(bar_index, low, text='3rd Halving - May 11, 2020', style=label.style_label_upper_left, textcolor=color.black, color=color.yellow, textalign=text.align_right)

// Fourth Halving (Estimated)
if isDate(2024, 8, 10)
    line.new(bar_index, low, bar_index, high, xloc.bar_index, extend.both, color=color.yellow)
    if (showLabels)
        label.new(bar_index, low, text='4th Halving - (approx) Aug 10, 2024', style=label.style_label_upper_left, textcolor=color.black, color=color.yellow, textalign=text.align_right)


