ICT Macros
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © reastruth

//@version=4
_macroColor = input(title="Macro Color", type=input.color, defval=color.black)
_londonColor = input(title="London Macro Color", type=input.color, defval=color.black)
_dtccColor = input(title="", type=input.color, defval=color.rgb(54, 58, 69, 35))

study(title = "MACROS", overlay = true)

//New York Time
_2_33AM = timestamp("UTC-4", year, month, dayofmonth, 2, 33, 00)
_3AM = timestamp("UTC-4", year, month, dayofmonth, 3, 0, 00)
_4_03AM = timestamp("UTC-4", year, month, dayofmonth, 4, 3, 00)
_4_30AM = timestamp("UTC-4", year, month, dayofmonth, 4, 30, 00)
_2_10PM = timestamp("UTC-4", year, month, dayofmonth, 14, 10, 00)
_2_40PM = timestamp("UTC-4", year, month, dayofmonth, 14, 40, 00)
_3_15PM = timestamp("UTC-4", year, month, dayofmonth, 15, 15, 00)
_3_45PM = timestamp("UTC-4", year, month, dayofmonth, 15, 45, 00)
_8_50AM = timestamp("UTC-4", year, month, dayofmonth, 8, 50, 00)
_9_10AM = timestamp("UTC-4", year, month, dayofmonth, 9, 10, 00)
_9_50AM = timestamp("UTC-4", year, month, dayofmonth, 9, 50, 00)
_10_10AM = timestamp("UTC-4", year, month, dayofmonth, 10, 10, 00)
_1050AM = timestamp("UTC-4",year, month, dayofmonth, 10, 50, 00)
_1110AM = timestamp("UTC-4",year, month, dayofmonth, 11, 10, 00)
_1150AM = timestamp("UTC-4",year, month, dayofmonth, 11, 50, 00)
_1210PM = timestamp("UTC-4",year, month, dayofmonth, 12, 10, 00)
_1_10PM = timestamp("UTC-4",year, month, dayofmonth, 13, 10, 00)
_1_40PM = timestamp("UTC-4",year, month, dayofmonth, 13, 40, 00)
_8PM = timestamp("UTC-4",year, month, dayofmonth, 21, 00, 00)
_845PM = timestamp("UTC-4",year, month, dayofmonth, 21, 45, 00)

//2 Minute Warning
_2_30AM = timestamp("UTC-4", year, month, dayofmonth, 2, 30, 00)
_2_57AM = timestamp("UTC-4", year, month, dayofmonth, 2, 57, 00)
_3_00AM = timestamp("UTC-4", year, month, dayofmonth, 3, 0, 00)
_4_00AM = timestamp("UTC-4", year, month, dayofmonth, 4, 0, 00)
_4_27AM = timestamp("UTC-4", year, month, dayofmonth, 4, 27, 00)
_2_07PM = timestamp("UTC-4", year, month, dayofmonth, 14, 7, 00)
_2_37PM = timestamp("UTC-4", year, month, dayofmonth, 14, 37, 00)
_3_12PM = timestamp("UTC-4", year, month, dayofmonth, 15, 12, 00)
_3_42PM = timestamp("UTC-4", year, month, dayofmonth, 15, 42, 00)
_8_47AM = timestamp("UTC-4", year, month, dayofmonth, 8, 47, 00)
_9_07AM = timestamp("UTC-4", year, month, dayofmonth, 9, 7, 00)
_9_47AM = timestamp("UTC-4", year, month, dayofmonth, 9, 47, 00)
_10_07AM = timestamp("UTC-4", year, month, dayofmonth, 10, 7, 00)
_10_47AM = timestamp("UTC-4",year, month, dayofmonth, 10, 47, 00)
_11_07AM = timestamp("UTC-4",year, month, dayofmonth, 11, 7, 00)
_11_47AM = timestamp("UTC-4",year, month, dayofmonth, 11, 47, 00)
_12_07PM = timestamp("UTC-4",year, month, dayofmonth, 12, 7, 00)
_1_07PM = timestamp("UTC-4",year, month, dayofmonth, 13, 7, 00)
_1_37PM = timestamp("UTC-4",year, month, dayofmonth, 13, 37, 00)
_7_57PM = timestamp("UTC-4",year, month, dayofmonth, 19, 57, 00)
_8_42PM = timestamp("UTC-4",year, month, dayofmonth, 20, 42, 00)




// vertical line function
verticalLine(Color) =>
    line.new(bar_index, low - tr, bar_index, high + tr, xloc.bar_index, extend.both, Color, line.style_dotted, 1)

// vertical line label
verticalLabel(Color, Text) =>
    label.new(bar_index, high+tr, text=Text, textcolor=Color, style=label.style_none)

// M.O.
if(time==_8_50AM or time==_9_50AM or time==_1050AM or time==_1_10PM or time==_3_15PM or time==_1150AM)
    verticalLine(_macroColor)
    verticalLabel(_macroColor, "M.O.")

// M.C.
if(time==_9_10AM or time==_10_10AM or time==_1110AM or time==_1_40PM or time==_3_45PM or time==_1210PM)
    verticalLine(_macroColor)
    verticalLabel(_macroColor, "M.C.")

// DTCC
if(time==_8PM or time==_845PM) 
    verticalLine(_dtccColor)
    verticalLabel(_dtccColor, "DTCC")    

// London Macros
if(time==_4_03AM or time==_2_33AM)
    verticalLine(_londonColor)
    verticalLabel(_londonColor, "L.M.O")
if(time==_3AM or time==_4_30AM)
    verticalLine(_londonColor)
    verticalLabel(_londonColor, "L.M.C")           

// Alert Any
if (time == _8_50AM)
    alert("8:50a Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _9_50AM)
    alert("9:50a Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _1_10PM)
    alert("1:10p Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _3_15PM)
    alert("3:15p Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _1150AM)
    alert("11:50a Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _1210PM)
    alert("12:10a Macro Close Alert", alert.freq_once_per_bar_close)    
if (time == _10_10AM)
    alert("10:10a Macro Close Alert", alert.freq_once_per_bar_close)
if (time == _1110AM)
    alert("11:10a Macro Close Alert", alert.freq_once_per_bar_close)
if (time == _1210PM)
    alert("12:10a Macro Close Alert", alert.freq_once_per_bar_close) 
if (time == _2_33AM)
    alert("2:33a London Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _3AM)
    alert("3:00a London Macro Close Alert", alert.freq_once_per_bar_close)
if (time == _4_03AM)
    alert("4:03a London Macro Open Alert", alert.freq_once_per_bar_close)
if (time == _4_30AM)
    alert("4:30a London Macro Close Alert", alert.freq_once_per_bar_close)
if (time == _9_10AM)
    alert("9:10a Macro Close Alert", alert.freq_once_per_bar_close)    

if (time == _8PM)
    alert("DTCC Open Alert", alert.freq_once_per_bar_close)
if (time == _845PM)
    alert("DTCC Close Alert", alert.freq_once_per_bar_close) 

// 2 min warning
if (time == _8_47AM)
    alert("8:50a Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _9_47AM)
    alert("9:50a Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _1_07PM)
    alert("1:10p Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _3_12PM)
    alert("3:15p Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _11_47AM)
    alert("11:50a Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _12_07PM)
    alert("12:10a Macro Close in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _10_07AM)
    alert("10:10a Macro Close in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _11_07AM)
    alert("11:10a Macro Close in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _12_07PM)
    alert("12:10a Macro Close in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _2_30AM)
    alert("2:33a London Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _2_57AM)
    alert("3:00a London Macro Close in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _4_00AM)
    alert("4:03a London Macro Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _4_27AM)
    alert("4:30a London Macro Close in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _9_07AM)
    alert("9:10a Macro Close in 2 Minutes", alert.freq_once_per_bar_close)

if (time == _7_57PM)
    alert("DTCC Open in 2 Minutes", alert.freq_once_per_bar_close)
if (time == _8_42PM)
    alert("DTCC Close in 2 Minutes", alert.freq_once_per_bar_close)


// Alert
alertcondition(time == _8_50AM, title="8:50a Macro Open Alert", message="8:50AM Macro Open")
alertcondition(time == _9_50AM, title="9:50a Macro Open Alert", message="9:50AM Macro Open")
alertcondition(time == _1050AM, title="10:50a Macro Open Alert", message="10:50AM Macro Open")
alertcondition(time == _1_10PM, title="1:10p Macro Open Alert", message="1:10PM Macro Open")
alertcondition(time == _1_40PM, title="1:40p Macro Close Alert", message="1:40PM Macro Close")
alertcondition(time == _3_15PM, title="3:15p Macro Open Alert", message="3:15PM Macro Open")
alertcondition(time == _9_10AM, title="9:10a Macro Close Alert", message="9:10AM Macro Close")
alertcondition(time == _10_10AM, title="10:10a Macro Close Alert", message="10:10AM Macro Close")
alertcondition(time == _1110AM, title="11:10a Macro Close Alert", message="11:10AM Macro Close")
alertcondition(time == _1210PM, title="12:10p Macro Close Alert", message="12:10PM Macro Close")
alertcondition(time == _1150AM, title="11:50a Macro Open Alert", message="11:50AM Macro Open")

alertcondition(time == _2_33AM, title="2:33a London Macro Open Alert", message="2:33AM London Macro Open")
alertcondition(time == _4_03AM, title="4:03a London Macro Open Alert", message="4:03AM London Macro Open")
alertcondition(time == _3AM, title="3:00a London Macro Close Alert", message="3:00AM London Macro Close")
alertcondition(time == _4_30AM, title="4:30a London Macro Close Alert", message="4:30AM London Macro Close")

//alertcondition(time == _9PM, title="DTCC Open Alert", message="DTCC Open")
//alertcondition(time == _945PM, title="DTCC Close Alert", message="DTCC Close")
