Key Levels (Time Frames - Weekly,Monthly,Quarterly,Yearly)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gunebakan

//@version=4
study("Key Levels (Time Frames - Weekly,Monthly,Quarterly,Yearly)", shorttitle = "Key Levels (Time Frames-W,M,Q,Y)", overlay = true)

distanceright = input(defval = 20, title = "Distance", type = input.integer)
labelsize =  input(defval="Medium",title="Text Size", options=["Small", "Medium", "Large"])
linesize =  input(defval="Small",title="Line Width", options=["Small", "Medium", "Large"])
var show_tails = input(defval = false, title = "Always Show", type = input.bool)

var check_4h = 0
var check_4h_high = 1
var check_4h_low = 2
var check_4h_mid = 3
var check_daily = 10
var check_previous_daily = 11
var check_previous_daily_high = 12
var check_previous_daily_low = 13
var check_previous_daily_mid = 14
var check_weekly = 20
var check_weekly_low = 21
var check_weekly_high = 22
var check_previous_weekly = 23
var check_monthly = 30
var check_monthly_high = 31
var check_monthly_low = 32
var check_monthly_mid = 33
var check_previous_monthly = 34
var check_quarterly = 40
var check_quarterly_high = 41
var check_quarterly_low = 42
var check_quarterly_mid = 43
var check_previous_quarterly = 44
var check_yearly = 50
var check_yearly_high = 51
var check_yearly_low = 52
var check_yearly_mid = 53
var check_previous_yearly = 54
var check_monday_high = 61
var check_monday_low = 62
var check_monday_mid = 63

[daily_time, daily_open] = security(syminfo.tickerid, 'D', [time, open], lookahead = barmerge.lookahead_on)
[dailypo_time, dailyp_open] = security(syminfo.tickerid, 'D', [time[1], open[1]], lookahead = barmerge.lookahead_on)
[dailyph_time, dailyp_high] = security(syminfo.tickerid, 'D', [time[1], high[1]], lookahead = barmerge.lookahead_on)
[dailypl_time, dailyp_low] = security(syminfo.tickerid, 'D', [time[1], low[1]], lookahead = barmerge.lookahead_on)
dailyp_mid = (dailyp_low + dailyp_high ) / 2

cdailyp_high = security(syminfo.tickerid, 'D',high, lookahead = barmerge.lookahead_on)
cdailyp_low = security(syminfo.tickerid, 'D',low, lookahead = barmerge.lookahead_on)
var monday_time = time
var monday_high = high
var monday_low = low
var monday_mid = (monday_high + monday_low ) / 2

[weekly_time, weekly_open] = security(syminfo.tickerid, 'W', [time, open], lookahead = barmerge.lookahead_on)
[weeklypo_time, weeklyp_open] = security(syminfo.tickerid, 'W', [time[1], open[1]], lookahead = barmerge.lookahead_on)
[weeklyph_time, weeklyp_high] = security(syminfo.tickerid, 'W', [time[1], high[1]], lookahead = barmerge.lookahead_on)
[weeklypl_time, weeklyp_low] = security(syminfo.tickerid, 'W', [time[1], low[1]], lookahead = barmerge.lookahead_on)
weekly_mid_open = (weeklyp_high + weeklyp_low ) / 2

[monthly_time, monthly_open] = security(syminfo.tickerid, 'M', [time, open], lookahead = barmerge.lookahead_on)
[monthlypo_time, monthlyp_open] = security(syminfo.tickerid, 'M', [time[1], open[1]], lookahead = barmerge.lookahead_on)
[monthlyph_time, monthlyp_high] = security(syminfo.tickerid, 'M', [time[1], high[1]], lookahead = barmerge.lookahead_on)
[monthlypl_time, monthlyp_low] = security(syminfo.tickerid, 'M', [time[1], low[1]], lookahead = barmerge.lookahead_on)
monthly_mid_open = (monthlyp_high + monthlyp_low ) / 2


[quarterly_time, quarterly_open] = security(syminfo.tickerid, '3M', [time, open], lookahead = barmerge.lookahead_on)
[quarterlypo_time, quarterlyp_open] = security(syminfo.tickerid, '3M', [time[1], open[1]], lookahead = barmerge.lookahead_on)
[quarterlyph_time, quarterlyp_high] = security(syminfo.tickerid, '3M', [time[1], high[1]], lookahead = barmerge.lookahead_on)
[quarterlypl_time, quarterlyp_low] = security(syminfo.tickerid, '3M', [time[1], low[1]], lookahead = barmerge.lookahead_on)
quarterly_mid = (quarterlyp_high + quarterlyp_low ) / 2


[yearly_time, yearly_open] = security(syminfo.tickerid, '12M', [time, open], lookahead = barmerge.lookahead_on)
[yearlypo_time, yearlyp_open] = security(syminfo.tickerid, '12M', [time[1], open[1]], lookahead = barmerge.lookahead_on)
[yearlyph_time, yearlyp_high] = security(syminfo.tickerid, '12M', [time, high], lookahead = barmerge.lookahead_on)
[yearlypl_time, yearlyp_low] = security(syminfo.tickerid, '12M', [time, low], lookahead = barmerge.lookahead_on)
yearly_mid = (yearlyp_high + yearlyp_low ) / 2


[intra_time, intra_open] = security(syminfo.tickerid, '240', [time, open], lookahead = barmerge.lookahead_on)
[intraph_time, intrap_high] = security(syminfo.tickerid, '240', [time[1], high[1]], lookahead = barmerge.lookahead_on)
[intrapl_time, intrap_low] = security(syminfo.tickerid, '240', [time[1], low[1]], lookahead = barmerge.lookahead_on)
//------------------------------ Inputs -------------------------------

var is_daily_enabled = input(defval = true, title = "Daily Open", type = input.bool, group = "Daily",inline = "Daily")
var is_previous_daily_open_enabled = input(defval = false, title = "Previous Daily Open", type = input.bool, group = "Daily",inline = "Daily")
var is_dailyrange_enabled = input(defval = false, title = "Previous H/L", type = input.bool, group = "Daily", inline = "Daily")
var is_dailym_enabled = input(defval = false, title = "Previous Mid", type = input.bool, group = "Daily", inline =  "Daily")

var is_monday_enabled = input(defval = true, title = "Monday Range", type = input.bool, group = "Monday Range", inline =  "Monday")
var is_monday_mid = input(defval = true, title = "Monday Mid", type = input.bool, group = "Monday Range", inline =  "Monday")
var untested_monday = false
var is_weekly_enabled = input(defval = true, title = "Weekly Open", type = input.bool, group = "Weekly", inline = "Weekly")
var is_previous_weekly_open_enabled = input(defval = true, title = "Previous Weekly Open", type = input.bool, group = "Weekly", inline = "Weekly")
var is_weeklyrange_enabled = input(defval = true, title = "Previous H/L", type = input.bool, group = "Weekly", inline = "Weekly")
var is_previous_weekly_mid_enabled = input(defval = true, title = "Previous Mid", type = input.bool, group = "Weekly", inline = "Weekly")


var is_monthly_enabled = input(defval = true, title = "Monthly Open", type = input.bool, group = "Monthly", inline = "Monthly")
var is_previous_monthly_open_enabled = input(defval = true, title = "Previous Monthly Open", type = input.bool, group = "Monthly", inline = "Monthly")
var is_monthlyrange_enabled = input(defval = true, title = "Previous H/L", type = input.bool, group = "Monthly", inline = "Monthly")
var is_previous_monthly_mid_enabled = input(defval = true, title = "Previous Mid", type = input.bool, group = "Monthly", inline = "Monthly")

var is_quarterly_enabled = input(defval = true, title = "Quarterly Open", type = input.bool, group = "Quarterly", inline = "Quarterly")
var is_previous_quarterly_open_enabled = input(defval = false, title = "Previous Quarterly Open", type = input.bool, group = "Quarterly", inline = "Quarterly")
var is_quarterlyrange_enabled = input(defval = false, title = "Previous H/L", type = input.bool, group = "Quarterly", inline = "Quarterly")
var is_previous_quarterly_mid_enabled = input(defval = false, title = "Previous Mid", type = input.bool, group = "Quarterly", inline = "Quarterly")

var is_yearly_enabled = input(defval = true, title = "Yearly Open", type = input.bool, group = "Yearly", inline = "Yearly")
var is_previous_yearly_enabled = input(defval = false, title = "Previous Yearly Open", type = input.bool, group = "Yearly", inline = "Yearly")
var is_yearlyrange_enabled = input(defval = false, title = "Current H/L", type = input.bool, group = "Yearly", inline = "Yearly")
var is_yearly_mid_enabled = input(defval = false, title = "Current Mid", type = input.bool, group = "Yearly", inline = "Yearly")

var is_intra_enabled = input(defval = false, title = "4H Open", type = input.bool, group = "4H", inline = "4H")
var is_intrarange_enabled = input(defval = false, title = "Previous H/L", type = input.bool, group = "4H", inline = "4H")
var is_intram_enabled = input(defval = false, title = "Previous Mid", type = input.bool, group = "4H", inline =  "4H")


DailyColor = input(title="Daily Color", type = input.color, defval = #08bcd4, group = "Daily")
MondayColor = input(title="Monday Color", type = input.color, defval = color.white, group = "Monday Range")
WeeklyColor = input(title="Weekly Color", type = input.color, defval = color.yellow, group = "Weekly")
MonthlyColor = input(title="Monthly Color", type = input.color, defval = color.green,  group = "Monthly")
YearlyColor = input(title="Yearly Color", type = input.color, defval = color.red,  group = "Yearly")
QuarterlyColor = input(title="Quarterly Color", type = input.color, defval = color.orange,  group = "Quarterly")
IntraColor = input(title="4H Color", type = input.color, defval = color.purple,  group = "4H")


//if is_monday_enabled == true and dayofweek == dayofweek.monday
if (is_monday_enabled == true or is_monday_mid == true) and dayofweek == dayofweek.monday 
    monday_time := daily_time
    monday_high := cdailyp_high
    monday_low := cdailyp_low
    monday_mid := (monday_high + monday_low ) / 2

linewidthint = 1
if linesize == "Small"
    linewidthint := 1
if linesize == "Medium"
    linewidthint := 2
if linesize == "Large"
    linewidthint := 3
    
var DEFAULT_LINE_WIDTH = linewidthint
var DEFAULT_TAIL_WIDTH = linewidthint

fontsize = size.small

if labelsize == "Small"
    fontsize := size.small
    
if labelsize == "Medium"
    fontsize := size.normal

if labelsize == "Large"
    fontsize := size.large

var DEFAULT_LABEL_SIZE = fontsize
var DEFAULT_LABEL_STYLE = label.style_none
var DEFAULT_EXTEND_RIGHT = distanceright


check_intersection_open(label_id, check_period) =>
    if daily_open==weekly_open
        if is_daily_enabled and is_weekly_enabled 
            if check_period==check_daily or check_period==check_weekly
                label.set_text(label_id, "DO / WO")

    if daily_open==monthly_open
        if is_daily_enabled and is_monthly_enabled
            if check_period==check_daily or check_period==check_monthly
                label.set_text(label_id, "DO / MO")

    if daily_open==quarterly_open
        if is_daily_enabled and is_quarterly_enabled
            if check_period==check_daily or check_period==check_quarterly
                label.set_text(label_id, "DO / QO")

    if daily_open==yearly_open
        if is_daily_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_yearly
                label.set_text(label_id, "DO / YO")

    if weekly_open==monthly_open
        if is_weekly_enabled and is_monthly_enabled
            if check_period==check_weekly or check_period==check_monthly
                label.set_text(label_id, "WO / MO")

    if weekly_open==quarterly_open
        if is_weekly_enabled and is_quarterly_enabled
            if check_period==check_weekly or check_period==check_quarterly
                label.set_text(label_id, "WO / QO")

    if weekly_open==yearly_open
        if is_weekly_enabled and is_yearly_enabled
            if check_period==check_weekly or check_period==check_yearly
                label.set_text(label_id, "WO / YO")

    if monthly_open==quarterly_open
        if is_monthly_enabled and is_quarterly_enabled
            if check_period==check_monthly or check_period==check_quarterly
                label.set_text(label_id, "MO / QO")

    if monthly_open==yearly_open
        if is_monthly_enabled and is_yearly_enabled
            if check_period==check_monthly or check_period==check_yearly
                label.set_text(label_id, "MO / YO")

    if quarterly_open==yearly_open
        if is_quarterly_enabled and is_yearly_enabled
            if check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "QO / YO")
                
    if weeklyp_high==monthlyp_high
        if is_weeklyrange_enabled and is_monthlyrange_enabled
            if check_period==check_weekly_high or check_period==check_monthly_high
                label.set_text(label_id, "PWH / PMH")
    
    if weeklyp_low==monthlyp_low
        if is_weeklyrange_enabled and is_monthlyrange_enabled
            if check_period==check_weekly_low or check_period==check_monthly_low
                label.set_text(label_id, "PWL / PML")

    if weeklyp_high==yearlyp_high
        if is_weeklyrange_enabled and is_yearlyrange_enabled
            if check_period==check_weekly_high or check_period==check_yearly_high
                label.set_text(label_id, "PWH / YH")
    
    if weeklyp_low==yearlyp_low
        if is_weeklyrange_enabled and is_yearlyrange_enabled
            if check_period==check_weekly_low or check_period==check_yearly_low
                label.set_text(label_id, "PWL / YL")

    if monthlyp_high==quarterlyp_high
        if is_monthlyrange_enabled and is_quarterlyrange_enabled 
            if check_period==check_monthly_high or check_period==check_quarterly_high
                label.set_text(label_id, "PMH / PQH")

    if monthlyp_low==quarterlyp_low
        if is_monthlyrange_enabled and is_quarterlyrange_enabled 
            if check_period==check_monthly_low or check_period==check_quarterly_low
                label.set_text(label_id, "PML / PQL")

    if monthlyp_high==yearlyp_high
        if is_monthlyrange_enabled and is_yearlyrange_enabled 
            if check_period==check_monthly_high or check_period==check_yearly_high
                label.set_text(label_id, "PMH / YH")

    if monthlyp_low==yearlyp_low
        if is_monthlyrange_enabled and is_yearlyrange_enabled 
            if check_period==check_monthly_low or check_period==check_yearly_low
                label.set_text(label_id, "PML / YL")

    if quarterlyp_high==yearlyp_high
        if is_quarterlyrange_enabled and is_yearlyrange_enabled
            if check_period==check_quarterly_high or check_period==check_yearly_high
                label.set_text(label_id, "PQH / YH")

    if quarterlyp_low==yearlyp_low
        if is_quarterlyrange_enabled and is_yearlyrange_enabled
            if check_period==check_quarterly_low or check_period==check_yearly_low
                label.set_text(label_id, "PQL / YL")

    if dailyp_high==yearlyp_high
        if is_dailyrange_enabled and is_yearlyrange_enabled
            if check_period==check_previous_daily_high or check_period==check_yearly_high
                label.set_text(label_id, "PDH / YH")

    if dailyp_low==yearlyp_low
        if is_dailyrange_enabled and is_yearlyrange_enabled
            if check_period==check_previous_daily_low or check_period==check_yearly_low
                label.set_text(label_id, "PDL / YL")


    if weeklyp_low==yearlyp_low
        if is_weeklyrange_enabled and is_yearlyrange_enabled
            if check_period==check_weekly_low or check_period==check_yearly_low
                label.set_text(label_id, "PWL / YL")

    if dailyp_high==weeklyp_high
        if is_dailyrange_enabled and is_dailyrange_enabled
            if check_period==check_previous_daily_high or check_period==check_weekly_high 
                label.set_text(label_id, "PDH / PWH")

    if dailyp_low==weeklyp_low
        if is_dailyrange_enabled and is_dailyrange_enabled
            if check_period==check_previous_daily_low or check_period==check_weekly_low 
                label.set_text(label_id, "PDL / PWL")

    if monday_high==dailyp_high
        if is_monday_enabled and is_dailyrange_enabled
            if check_period==check_monday_high or check_period==check_previous_daily_high
                label.set_text(label_id, "MondayH / PDH")

    if monday_low==dailyp_low
        if is_monday_enabled and is_dailyrange_enabled
            if check_period==check_monday_low or check_period==check_previous_daily_low
                label.set_text(label_id, "MondayL / PDL")

    if monday_mid==dailyp_mid
        if is_monday_mid and is_dailyrange_enabled
            if check_period==check_monday_mid or check_period==check_previous_daily_mid
                label.set_text(label_id, "MondayM / PDM")

    if dailyp_open==monthly_open
        if is_previous_daily_open_enabled and is_monthly_enabled 
            if check_period==check_previous_daily or check_period==check_monthly
                label.set_text(label_id, "PDO / MO")


    if monthly_mid_open==yearly_mid
        if is_previous_monthly_mid_enabled and is_yearly_mid_enabled
            if check_period==check_monthly_mid or check_period==check_yearly_mid
                label.set_text(label_id, "PMM / YM")



    if weeklyp_high==monthlyp_high and monthlyp_high==yearlyp_high
        if is_weeklyrange_enabled and is_monthlyrange_enabled and is_yearlyrange_enabled
            if check_period==check_weekly_high or check_period==check_monthly_high or check_period==check_yearly_high
                label.set_text(label_id, "PWH / PMH / YH")
    
    if weeklyp_low==monthlyp_low and monthlyp_low==yearlyp_low
        if is_weeklyrange_enabled and is_monthlyrange_enabled and is_yearlyrange_enabled
            if check_period==check_weekly_low or check_period==check_monthly_low or check_period==check_yearly_low
                label.set_text(label_id, "PWL / PML / YL")

    if intrap_high==monday_high and timeframe.isintraday
        if is_intrarange_enabled and is_monday_enabled 
            if check_period==check_4h_high or check_period==check_monday_high
                label.set_text(label_id, "P4hH / MondayH")

    if intra_open==daily_open and timeframe.isintraday
        if is_intra_enabled and is_daily_enabled 
            if check_period==check_4h or check_period==check_daily
                label.set_text(label_id, "4hO / DO")

    if intra_open==daily_open and daily_open==weekly_open and timeframe.isintraday
        if is_intra_enabled and is_daily_enabled and is_weekly_enabled 
            if check_period==check_4h or check_period==check_daily or check_period==check_weekly
                label.set_text(label_id, "4hO / DO / WO")

    if intra_open==daily_open and daily_open==weekly_open and weekly_open==monthly_open and timeframe.isintraday
        if is_intra_enabled and is_daily_enabled and is_weekly_enabled and is_monthly_enabled  
            if check_period==check_4h or check_period==check_daily or check_period==check_monthly
                label.set_text(label_id, "4hO / DO / WO / MO")

    //-------------------
    if weeklyp_low==monthlyp_low and monthlyp_low==yearlyp_low
        if is_weeklyrange_enabled and is_monthlyrange_enabled and is_yearlyrange_enabled
            if check_period==check_weekly_low or check_period==check_monthly_low or check_period==check_yearly_low
                label.set_text(label_id, "PWL / PML / YL")

    if daily_open==weekly_open and weekly_open==monthly_open
        if is_daily_enabled and is_weekly_enabled and is_monthly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_monthly
                label.set_text(label_id, "DO / WO / MO")

    if daily_open==weekly_open and weekly_open==quarterly_open
        if is_daily_enabled and is_weekly_enabled and is_quarterly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_quarterly
                label.set_text(label_id, "DO / WO / QO")

    if daily_open==weekly_open and weekly_open==yearly_open
        if is_daily_enabled and is_weekly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_yearly
                label.set_text(label_id, "DO / WO / YO")

    if daily_open==monthly_open and monthly_open==quarterly_open
        if is_daily_enabled and is_monthly_enabled and is_quarterly_enabled
            if check_period==check_daily or check_period==check_monthly or check_period==check_quarterly
                label.set_text(label_id, "DO / MO / QO")

    if dailyp_open==monthly_open and monthly_open==quarterly_open
        if is_previous_daily_open_enabled and is_monthly_enabled and is_quarterly_enabled
            if check_period==check_previous_daily or check_period==check_monthly or check_period==check_quarterly
                label.set_text(label_id, "PDO / MO / QO")

    if daily_open==monthly_open and monthly_open==yearly_open
        if is_daily_enabled and is_monthly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_monthly or check_period==check_yearly
                label.set_text(label_id, "DO / MO / YO")

    if daily_open==quarterly_open and quarterly_open==yearly_open
        if is_daily_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "DO / QO / YO")

    if weekly_open==monthly_open and monthly_open==quarterly_open
        if is_weekly_enabled and is_monthly_enabled and is_quarterly_enabled
            if check_period==check_weekly or check_period==check_monthly or check_period==check_quarterly
                label.set_text(label_id, "WO / MO / QO")

    if weekly_open==monthly_open and monthly_open==yearly_open
        if is_weekly_enabled and is_monthly_enabled and is_yearly_enabled
            if check_period==check_weekly or check_period==check_monthly or check_period==check_yearly
                label.set_text(label_id, "WO / MO / YO")

    if weekly_open==quarterly_open and quarterly_open==yearly_open
        if is_weekly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_weekly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "WO / QO / YO")

    if monthly_open==quarterly_open and quarterly_open==yearly_open
        if is_monthly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "MO / QO / YO")

    if daily_open==weekly_open and weekly_open==monthly_open and monthly_open==quarterly_open
        if is_daily_enabled and is_weekly_enabled and is_monthly_enabled and is_quarterly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_monthly or check_period==check_quarterly
                label.set_text(label_id, "DO / WO / MO / QO")

    if daily_open==weekly_open and weekly_open==monthly_open and monthly_open==yearly_open
        if is_daily_enabled and is_weekly_enabled and is_monthly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_monthly or check_period==check_yearly
                label.set_text(label_id, "DO / WO / MO / YO")

    if dailyp_open==monthly_open and monthly_open==quarterly_open and quarterly_open==yearly_open
        if is_previous_daily_open_enabled and is_monthly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_previous_daily or check_period==check_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "PDO / MO / QO / YO")

    if daily_open==monthly_open and monthly_open==quarterly_open and quarterly_open==yearly_open
        if is_daily_enabled and is_monthly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "DO / MO / QO / YO")

    if daily_open==weekly_open and weekly_open==quarterly_open and quarterly_open==yearly_open
        if is_daily_enabled and is_weekly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "DO / WO / QO / YO")

    if weekly_open==monthly_open and monthly_open==quarterly_open and quarterly_open==yearly_open
        if is_weekly_enabled and is_monthly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_weekly or check_period==check_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "WO / MO / QO / YO")

    if daily_open==weekly_open and weekly_open==monthly_open and monthly_open==quarterly_open and quarterly_open==yearly_open
        if is_daily_enabled and is_weekly_enabled and is_monthly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_daily or check_period==check_weekly or check_period==check_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "DO / WO / MO / QO / YO")

    //PWO combinations
    if weeklyp_open==monthly_open and monthly_open==quarterly_open and quarterly_open==yearly_open
        if is_previous_weekly_open_enabled and is_monthly_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_previous_weekly or check_period==check_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "PWO / MO / QO / YO")

    if weeklyp_open==monthly_open and monthly_open==quarterly_open
        if is_previous_weekly_open_enabled and is_monthly_enabled and is_quarterly_enabled
            if check_period==check_previous_weekly or check_period==check_monthly or check_period==check_quarterly
                label.set_text(label_id, "PWO / MO / QO")

    if weeklyp_open==monthly_open and monthly_open==quarterly_open
        if is_previous_weekly_open_enabled and is_monthly_enabled and is_yearly_enabled
            if check_period==check_previous_weekly or check_period==check_monthly or check_period==check_yearly
                label.set_text(label_id, "PWO / MO / YO")

    if weeklyp_open==quarterly_open and quarterly_open==yearly_open
        if is_previous_weekly_open_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_previous_weekly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "PWO / QO / YO")

    if weeklyp_open==monthly_open
        if is_previous_weekly_open_enabled and is_monthly_enabled 
            if check_period==check_previous_weekly or check_period==check_monthly
                label.set_text(label_id, "PWO / MO")

    if weeklyp_open==quarterly_open
        if is_previous_weekly_open_enabled and is_quarterly_enabled
            if check_period==check_previous_weekly or check_period==check_quarterly
                label.set_text(label_id, "PWO / QO")

    if weeklyp_open==yearly_open
        if is_previous_weekly_open_enabled and is_yearly_enabled
            if check_period==check_previous_weekly or check_period==check_yearly
                label.set_text(label_id, "PWO / YO")

    if monthlyp_open==quarterly_open
        if is_previous_monthly_open_enabled and is_quarterly_enabled
            if check_period==check_previous_monthly or check_period==check_quarterly
                label.set_text(label_id, "PMO / QO ")

    if monthlyp_open==yearly_open
        if is_previous_monthly_open_enabled and is_yearly_enabled
            if check_period==check_previous_monthly or check_period==check_yearly
                label.set_text(label_id, "PMO / YO")

    if monthlyp_open==quarterly_open and quarterly_open==yearly_open
        if is_previous_monthly_open_enabled and is_quarterly_enabled and is_yearly_enabled
            if check_period==check_previous_monthly or check_period==check_quarterly or check_period==check_yearly
                label.set_text(label_id, "PMO / QO / YO")

    if dailyp_open==weekly_open
        if is_previous_daily_open_enabled and is_weekly_enabled
            if check_period==check_previous_daily or check_period==check_weekly
                label.set_text(label_id, "PDO / WO")

    if dailyp_open==weekly_open and weekly_open==monthly_open
        if is_previous_daily_open_enabled and is_weekly_enabled and is_monthly_enabled
            if check_period==check_previous_daily or check_period==check_weekly or check_period==check_monthly
                label.set_text(label_id, "PDO / WO / MO")

//------------------------------ Plotting ------------------------------

var can_show_daily = is_daily_enabled and timeframe.isintraday
var can_show_weekly = is_weekly_enabled and not timeframe.isweekly and not timeframe.ismonthly
var can_show_monthly = is_monthly_enabled and not timeframe.ismonthly
var can_show_quarterly = is_quarterly_enabled and not (timeframe.period == "3M")


get_limit_right() =>
    _bar = min(time - time[1], time[1] - time[2])
    time + _bar * (DEFAULT_EXTEND_RIGHT)


// the following code doesn't need to be processed on every candle
if barstate.islast
    is_weekly_open = dayofweek == dayofweek.monday
    is_monthly_open	= dayofmonth == 1
	can_draw_daily = (is_weekly_enabled ? not is_weekly_open : true) and (is_monthly_enabled ? not is_monthly_open : true)
	can_draw_weekly = is_monthly_enabled ? not (is_monthly_open and is_weekly_open) : true
    can_draw_intra = is_intra_enabled and timeframe.isintraday
    can_draw_intrah = is_intrarange_enabled and timeframe.isintraday
    can_draw_intral = is_intrarange_enabled and timeframe.isintraday
    can_draw_intram = is_intram_enabled and timeframe.isintraday

    // 4H Open
    if  can_draw_intra
        intra_limit_right = get_limit_right()

        var intra_line = line.new(x1 = intra_time,
           x2 = intra_limit_right,
           y1 = intra_open,
           y2 = intra_open,
           color = IntraColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var intra_label = label.new(x = intra_limit_right,
           y = intra_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = IntraColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(intra_line, intra_time)
    	line.set_x2(intra_line, intra_limit_right)
    	line.set_y1(intra_line, intra_open)
    	line.set_y2(intra_line, intra_open)
    	label.set_x(intra_label, intra_limit_right)
        label.set_y(intra_label, intra_open)
        label.set_text(intra_label, "4hO")
        label.set_tooltip(intra_label, "4h Open")

        check_intersection_open(intra_label, check_4h)
        
    // Previous 4H High
    if  can_draw_intrah
    //if is_intrarange_enabled
        intrah_limit_right = get_limit_right()
        
        var intrah_line = line.new(x1 = intraph_time,
           x2 = intrah_limit_right,
           y1 = intrap_high,
           y2 = intrap_high,
           color = IntraColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var intrah_label = label.new(x = intrah_limit_right,
           y = intrap_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = IntraColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(intrah_line, intraph_time)
    	line.set_x2(intrah_line, intrah_limit_right)
    	line.set_y1(intrah_line, intrap_high)
    	line.set_y2(intrah_line, intrap_high)
    	label.set_x(intrah_label, intrah_limit_right)
        label.set_y(intrah_label, intrap_high)
        label.set_text(intrah_label, "P4hH")
        label.set_tooltip(intrah_label, "Previous 4h High")

        check_intersection_open(intrah_label, check_4h_high)

    // Previous 4H Low
    if  can_draw_intral
        intral_limit_right = get_limit_right()

        var intral_line = line.new(x1 = intrapl_time,
           x2 = intral_limit_right,
           y1 = intrap_low,
           y2 = intrap_low,
           color = IntraColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var intral_label = label.new(x = intral_limit_right,
           y = intrap_low,
           style = DEFAULT_LABEL_STYLE,
           textcolor = IntraColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(intral_line, intrapl_time)
    	line.set_x2(intral_line, intral_limit_right)
    	line.set_y1(intral_line, intrap_low)
    	line.set_y2(intral_line, intrap_low)
    	label.set_x(intral_label, intral_limit_right)
        label.set_y(intral_label, intrap_low)
        label.set_text(intral_label, "P4hL")
        label.set_tooltip(intral_label, "Previous 4h Low")
        
        check_intersection_open(intral_label, check_4h_low)
        
    // Previous 4H Mid
    if  can_draw_intram
        intram_limit_right = get_limit_right()
        intram_time = intraph_time
        intram_open = (intrap_low + intrap_high ) / 2
        
        var intram_line = line.new(x1 = intram_time,
           x2 = intram_limit_right,
           y1 = intram_open,
           y2 = intram_open,
           color = IntraColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var intram_label = label.new(x = intram_limit_right,
           y = intram_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = IntraColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)
        line.set_x1(intram_line, intram_time)
    	line.set_x2(intram_line, intram_limit_right)
    	line.set_y1(intram_line, intram_open)
    	line.set_y2(intram_line, intram_open)
    	label.set_x(intram_label, intram_limit_right)
        label.set_y(intram_label, intram_open)
        label.set_text(intram_label, "P4hM")
        label.set_tooltip(intram_label, "Previous 4h Mid")

        check_intersection_open(intram_label, check_4h_mid)

    // MONDAY
    if is_monday_enabled
        monday_limit_right = get_limit_right()
        //monday_limit_right = time + _bar * (DEFAULT_EXTEND_RIGHT)

        var monday_line = line.new(x1 = monday_time,
           x2 = monday_limit_right,
           y1 = monday_high,
           y2 = monday_high,
           color = MondayColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monday_label = label.new(x = monday_limit_right,
           y = monday_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MondayColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(monday_line, monday_time)
    	line.set_x2(monday_line, monday_limit_right)
    	line.set_y1(monday_line, monday_high)
    	line.set_y2(monday_line, monday_high)
    	label.set_x(monday_label, monday_limit_right)
        label.set_y(monday_label, monday_high)
        label.set_text(monday_label, "MondayH")
        label.set_tooltip(monday_label, "Monday High")

        check_intersection_open(monday_label, check_monday_high)
        
    if is_monday_enabled
        monday_limit_right = get_limit_right()

        var monday_low_line = line.new(x1 = monday_time,
           x2 = monday_limit_right,
           y1 = monday_low,
           y2 = monday_low,
           color = MondayColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monday_low_label = label.new(x = monday_limit_right,
           y = monday_low,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MondayColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(monday_low_line, monday_time)
    	line.set_x2(monday_low_line, monday_limit_right)
    	line.set_y1(monday_low_line, monday_low)
    	line.set_y2(monday_low_line, monday_low)
    	label.set_x(monday_low_label, monday_limit_right)
        label.set_y(monday_low_label, monday_low)   
        label.set_text(monday_low_label, "MondayL")   
        label.set_tooltip(monday_low_label, "Monday Low")

        check_intersection_open(monday_low_label, check_monday_low)

    if is_monday_mid
        mondaym_limit_right = get_limit_right()
     
        //monday_mid = (monday_high + monday_low ) / 2
        var mondaym_line = line.new(x1 = monday_time,
           x2 = mondaym_limit_right,
           y1 = monday_mid,
           y2 = monday_mid,
           color = MondayColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var mondaym_label = label.new(x = mondaym_limit_right,
           y = monday_mid,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MondayColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)
        line.set_x1(mondaym_line, monday_time)
    	line.set_x2(mondaym_line, mondaym_limit_right)
    	line.set_y1(mondaym_line, monday_mid)
    	line.set_y2(mondaym_line, monday_mid)
    	label.set_x(mondaym_label, mondaym_limit_right)
        label.set_y(mondaym_label, monday_mid)
        label.set_text(mondaym_label, "MondayM")   
        label.set_tooltip(mondaym_label, "Monday Mid")

        check_intersection_open(mondaym_label, check_monday_mid)
        
    // DAILY OPEN
    //if can_show_daily and can_draw_daily
    if is_daily_enabled
        daily_limit_right = get_limit_right()

        var daily_line = line.new(x1 = daily_time,
           x2 = daily_limit_right,
           y1 = daily_open,
           y2 = daily_open,
           color = DailyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var daily_label = label.new(x = daily_limit_right,
           y = daily_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = DailyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(daily_line, daily_time)
    	line.set_x2(daily_line, daily_limit_right)
    	line.set_y1(daily_line, daily_open)
    	line.set_y2(daily_line, daily_open)
    	label.set_x(daily_label, daily_limit_right)
        label.set_y(daily_label, daily_open)
        label.set_text(daily_label, "DO")
        label.set_tooltip(daily_label, "Daily Open")

        check_intersection_open(daily_label, check_daily)
        
    // PREVIOUS DAILY OPEN
    if is_previous_daily_open_enabled
        dailyp_limit_right = get_limit_right()

        var dailyp_line = line.new(x1 = dailypo_time,
           x2 = dailyp_limit_right,
           y1 = dailyp_open,
           y2 = dailyp_open,
           color = DailyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var dailyp_label = label.new(x = dailyp_limit_right,
           y = dailyp_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = DailyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(dailyp_line, dailypo_time)
    	line.set_x2(dailyp_line, dailyp_limit_right)
    	line.set_y1(dailyp_line, dailyp_open)
    	line.set_y2(dailyp_line, dailyp_open)
    	label.set_x(dailyp_label, dailyp_limit_right)
        label.set_y(dailyp_label, dailyp_open)
        label.set_text(dailyp_label, "PDO")
        label.set_tooltip(dailyp_label, "Previous Daily Open")

        check_intersection_open(dailyp_label, check_previous_daily)

    // PREVIOUS DAILY HIGH 
    if is_dailyrange_enabled
        dailyh_limit_right = get_limit_right()
        
        var dailyh_line = line.new(x1 = dailyph_time,
           x2 = dailyh_limit_right,
           y1 = dailyp_high,
           y2 = dailyp_high,
           color = DailyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var dailyh_label = label.new(x = dailyh_limit_right,
           y = dailyp_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = DailyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(dailyh_line, dailyph_time)
    	line.set_x2(dailyh_line, dailyh_limit_right)
    	line.set_y1(dailyh_line, dailyp_high)
    	line.set_y2(dailyh_line, dailyp_high)
    	label.set_x(dailyh_label, dailyh_limit_right)
        label.set_y(dailyh_label, dailyp_high)
        label.set_text(dailyh_label, "PDH")
        label.set_tooltip(dailyh_label, "Previous Daily High")

        check_intersection_open(dailyh_label, check_previous_daily_high)

    // PREVIOUS DAILY LOW
    if is_dailyrange_enabled
        dailyl_limit_right = get_limit_right()
        
        var dailyl_line = line.new(x1 = dailypl_time,
           x2 = dailyl_limit_right,
           y1 = dailyp_low,
           y2 = dailyp_low,
           color = DailyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var dailyl_label = label.new(x = dailyl_limit_right,
           y = dailyp_low,
           style = DEFAULT_LABEL_STYLE,
           textcolor = DailyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

    	line.set_x1(dailyl_line, dailypl_time)
    	line.set_x2(dailyl_line, dailyl_limit_right)
    	line.set_y1(dailyl_line, dailyp_low)
    	line.set_y2(dailyl_line, dailyp_low)
    	label.set_x(dailyl_label, dailyl_limit_right)
        label.set_y(dailyl_label, dailyp_low)
        label.set_text(dailyl_label, "PDL")
        label.set_tooltip(dailyl_label, "Previous Daily Low")

        check_intersection_open(dailyl_label, check_previous_daily_low)

    // DAILY MID
       
    if  is_dailym_enabled  
        dailym_limit_right = get_limit_right()
        dailym_time = dailyph_time
        
        var dailym_line = line.new(x1 = dailym_time,
           x2 = dailym_limit_right,
           y1 = dailyp_mid,
           y2 = dailyp_mid,
           color = DailyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var dailym_label = label.new(x = dailym_limit_right,
           y = dailyp_mid,
           style = DEFAULT_LABEL_STYLE,
           textcolor = DailyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)
        line.set_x1(dailym_line, dailym_time)
    	line.set_x2(dailym_line, dailym_limit_right)
    	line.set_y1(dailym_line, dailyp_mid)
    	line.set_y2(dailym_line, dailyp_mid)
    	label.set_x(dailym_label, dailym_limit_right)
        label.set_y(dailym_label, dailyp_mid)
        label.set_text(dailym_label, "PDM")
        label.set_tooltip(dailym_label, "Previous Day Mid")

        check_intersection_open(dailym_label, check_previous_daily_mid)

    // WEEKLY OPEN


    //if can_show_weekly and can_draw_weekly
    if is_weekly_enabled
        weekly_limit_right = get_limit_right()

        var weekly_line = line.new(x1 = weekly_time,
           x2 = weekly_limit_right,
           y1 = weekly_open,
           y2 = weekly_open,
           color = WeeklyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var weekly_label = label.new(x = weekly_limit_right,
           y = weekly_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = WeeklyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(weekly_line, weekly_time)
    	line.set_x2(weekly_line, weekly_limit_right)
    	line.set_y1(weekly_line, weekly_open)
    	line.set_y2(weekly_line, weekly_open)
    	label.set_x(weekly_label, weekly_limit_right)
    	label.set_y(weekly_label, weekly_open)
    	label.set_text(weekly_label, "WO")
    	label.set_tooltip(weekly_label, "Weekly Open")

    // 	// the weekly open can be the daily open too (monday)
    //     // only the weekly will be draw, in these case we update its label
	   // if is_weekly_open and can_show_daily
    //         label.set_text(weekly_label, "DO / WO            ")

        check_intersection_open(weekly_label, check_weekly)

    // PREVIOUS WEEKLY OPEN
    if is_previous_weekly_open_enabled
        weeklyo_limit_right = get_limit_right()

        var weeklyo_line = line.new(x1 = weeklypo_time,
           x2 = weeklyo_limit_right,
           y1 = weeklyp_open,
           y2 = weeklyp_open,
           color = WeeklyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var weeklyo_label = label.new(x = weeklyo_limit_right,
           y = weeklyp_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = WeeklyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(weeklyo_line, weeklypo_time)
    	line.set_x2(weeklyo_line, weeklyo_limit_right)
    	line.set_y1(weeklyo_line, weeklyp_open)
    	line.set_y2(weeklyo_line, weeklyp_open)
    	label.set_x(weeklyo_label, weeklyo_limit_right)
    	label.set_y(weeklyo_label, weeklyp_open)
    	label.set_text(weeklyo_label, "PWO")
    	label.set_tooltip(weeklyo_label, "Previous Weekly Open")

        check_intersection_open(weeklyo_label, check_previous_weekly)
   
    // WEEKLY HIGH

    if is_weeklyrange_enabled
        weeklyh_limit_right = get_limit_right()

        var weeklyh_line = line.new(x1 = weeklyph_time,
           x2 = weeklyh_limit_right,
           y1 = weeklyp_high,
           y2 = weeklyp_high,
           color = WeeklyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var weeklyh_label = label.new(x = weeklyh_limit_right,
           y = weeklyp_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = WeeklyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(weeklyh_line, weeklyph_time)
    	line.set_x2(weeklyh_line, weeklyh_limit_right)
    	line.set_y1(weeklyh_line, weeklyp_high)
    	line.set_y2(weeklyh_line, weeklyp_high)
    	label.set_x(weeklyh_label, weeklyh_limit_right)
    	label.set_y(weeklyh_label, weeklyp_high)
    	label.set_text(weeklyh_label, "PWH")
    	label.set_tooltip(weeklyh_label, "Previous Weekly High")

        check_intersection_open(weeklyh_label, check_weekly_high)

    // WEEKLY LOW

    if is_weeklyrange_enabled
        weeklyl_limit_right = get_limit_right()

        var weeklyl_line = line.new(x1 = weekly_time,
           x2 = weeklyl_limit_right,
           y1 = weekly_open,
           y2 = weekly_open,
           color = WeeklyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var weeklyl_label = label.new(x = weeklyl_limit_right,
           y = weeklyp_low,
           text = "PWL",
           style = DEFAULT_LABEL_STYLE,
           textcolor = WeeklyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(weeklyl_line, weeklypl_time)
    	line.set_x2(weeklyl_line, weeklyl_limit_right)
    	line.set_y1(weeklyl_line, weeklyp_low)
    	line.set_y2(weeklyl_line, weeklyp_low)
    	label.set_x(weeklyl_label, weeklyl_limit_right)
    	label.set_y(weeklyl_label, weeklyp_low)
    	label.set_text(weeklyl_label, "PWL")
    	label.set_tooltip(weeklyl_label, "Previous Weekly Low")

        check_intersection_open(weeklyl_label, check_weekly_low)
    
    // WEEKLY MID

    if  is_previous_weekly_mid_enabled
        weeklym_limit_right = get_limit_right()

        var weeklym_line = line.new(x1 = weekly_time,
           x2 = weeklym_limit_right,
           y1 = weekly_mid_open,
           y2 = weekly_mid_open,
           color = WeeklyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var weeklym_label = label.new(x = weeklym_limit_right,
           y = weekly_mid_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = WeeklyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(weeklym_line, weeklypl_time)
    	line.set_x2(weeklym_line, weeklym_limit_right)
    	line.set_y1(weeklym_line, weekly_mid_open)
    	line.set_y2(weeklym_line, weekly_mid_open)
    	label.set_x(weeklym_label, weeklym_limit_right)
    	label.set_y(weeklym_label, weekly_mid_open)
    	label.set_text(weeklym_label, "PWM")
    	label.set_tooltip(weeklym_label, "Previous Weekly Mid")
        
        
    // MONTHLY OPEN

    //if can_show_monthly
    if is_monthly_enabled
        monthly_limit_right = get_limit_right()

        var monthlyLine = line.new(x1 = monthly_time,
           x2 = monthly_limit_right,
           y1 = monthly_open,
           y2 = monthly_open,
           color = MonthlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monthlyLabel = label.new(x = monthly_limit_right,
           y = monthly_open, 
           style = DEFAULT_LABEL_STYLE,
           textcolor = MonthlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(monthlyLine, monthly_time)
    	line.set_x2(monthlyLine, monthly_limit_right)
    	line.set_y1(monthlyLine, monthly_open)
    	line.set_y2(monthlyLine, monthly_open)
    	label.set_x(monthlyLabel, monthly_limit_right)
        label.set_y(monthlyLabel, monthly_open)
        label.set_text(monthlyLabel, "MO")
        label.set_tooltip(monthlyLabel, "Monthly Open")

        check_intersection_open(monthlyLabel, check_monthly)


    /////////////////////////////////////////////////////////////////////////////

        // the monthly open can be the weekly open (monday 1st) and/or daily open too
        // only the monthly will be draw, in these case we update its label
        // if is_monthly_open
        //     if can_show_daily
        //         label.set_text(monthlyLabel, "DO / MO            ")
            
            
        //     if is_weekly_open
        //         if can_show_weekly
        //             label.set_text(monthlyLabel, "WO / MO            ")
        //         if can_show_daily and can_show_weekly
        //             label.set_text(monthlyLabel, "DO / WO / MO                ")

        // the start of the line is drew from the first week of the month
        // if the first day of the weekly candle (monday) is the 2nd of the month
        // we fix the start of the line position on the previous weekly candle
        if timeframe.isweekly and dayofweek(monthly_time) != dayofweek.monday
            line.set_x1(monthlyLine, monthly_time - (weekly_time - weekly_time[1]))

    //  PREVIOUS MONTHLY OPEN

    if is_previous_monthly_open_enabled
        monthlyo_limit_right = get_limit_right()

        var monthlyo_line = line.new(x1 = monthly_time,
           x2 = monthlyo_limit_right,
           y1 = monthlyp_open,
           y2 = monthlyp_open,
           color = MonthlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monthlyo_label = label.new(x = monthlyo_limit_right,
           y = monthlyp_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MonthlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(monthlyo_line, monthlypo_time)
    	line.set_x2(monthlyo_line, monthlyo_limit_right)
    	line.set_y1(monthlyo_line, monthlyp_open)
    	line.set_y2(monthlyo_line, monthlyp_open)
    	label.set_x(monthlyo_label, monthlyo_limit_right)
    	label.set_y(monthlyo_label, monthlyp_open)
        label.set_text(monthlyo_label, "PMO")
        label.set_tooltip(monthlyo_label, "Previous Monthly Open")

        check_intersection_open(monthlyo_label, check_previous_monthly)

    // PREVIOUS MONTHLY LOW

    if is_monthlyrange_enabled
        monthlyl_limit_right = get_limit_right()

        var monthlyl_line = line.new(x1 = monthly_time,
           x2 = monthlyl_limit_right,
           y1 = monthlyp_low,
           y2 = monthlyp_low,
           color = MonthlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monthlyl_label = label.new(x = monthlyl_limit_right,
           y = monthlyp_low,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MonthlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(monthlyl_line, monthlypl_time)
    	line.set_x2(monthlyl_line, monthlyl_limit_right)
    	line.set_y1(monthlyl_line, monthlyp_low)
    	line.set_y2(monthlyl_line, monthlyp_low)
    	label.set_x(monthlyl_label, monthlyl_limit_right)
    	label.set_y(monthlyl_label, monthlyp_low)
    	label.set_text(monthlyl_label, "PML")
    	label.set_tooltip(monthlyl_label, "Previous Monthly Low")

        check_intersection_open(monthlyl_label, check_monthly_low)
    
    // PREVIOUS MONTHLY HIGH

    if is_monthlyrange_enabled
        monthlyh_limit_right = get_limit_right()

        var monthlyh_line = line.new(x1 = monthly_time,
           x2 = monthlyh_limit_right,
           y1 = monthlyp_high,
           y2 = monthlyp_high,
           color = MonthlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monthlyh_label = label.new(x = monthlyh_limit_right,
           y = monthlyp_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MonthlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(monthlyh_line, monthlypl_time)
    	line.set_x2(monthlyh_line, monthlyh_limit_right)
    	line.set_y1(monthlyh_line, monthlyp_high)
    	line.set_y2(monthlyh_line, monthlyp_high)
    	label.set_x(monthlyh_label, monthlyh_limit_right)
    	label.set_y(monthlyh_label, monthlyp_high)
    	label.set_text(monthlyh_label, "PMH")
    	label.set_tooltip(monthlyh_label, "Previous Monthly High")

        check_intersection_open(monthlyh_label, check_monthly_high)

    // MONTHLY MID

    if  is_previous_monthly_mid_enabled
        monthlym_limit_right = get_limit_right()

        var monthlym_line = line.new(x1 = monthly_time,
           x2 = monthlym_limit_right,
           y1 = monthly_mid_open,
           y2 = monthly_mid_open,
           color = MonthlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var monthlym_label = label.new(x = monthlym_limit_right,
           y = monthly_mid_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = MonthlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(monthlym_line, monthlypl_time)
    	line.set_x2(monthlym_line, monthlym_limit_right)
    	line.set_y1(monthlym_line, monthly_mid_open)
    	line.set_y2(monthlym_line, monthly_mid_open)
    	label.set_x(monthlym_label, monthlym_limit_right)
    	label.set_y(monthlym_label, monthly_mid_open)
    	label.set_text(monthlym_label, "PMM")
    	label.set_tooltip(monthlym_label, "Previous Monthly Mid")

        check_intersection_open(monthlym_label, check_monthly_mid)

    // QUARTERLY OPEN
    //var Quarterly_label
    if is_quarterly_enabled
        quarterly_limit_right = get_limit_right()

        var quarterly_line = line.new(x1 = quarterly_time,
           x2 = quarterly_limit_right,
           y1 = quarterly_open,
           y2 = quarterly_open,
           color = QuarterlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var Quarterly_label = label.new(x = quarterly_limit_right,
           y = quarterly_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = QuarterlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(quarterly_line, quarterly_time)
    	line.set_x2(quarterly_line, quarterly_limit_right)
    	line.set_y1(quarterly_line, quarterly_open)
    	line.set_y2(quarterly_line, quarterly_open)
    	label.set_x(Quarterly_label, quarterly_limit_right)
    	label.set_y(Quarterly_label, quarterly_open)
    	label.set_text(Quarterly_label, "QO")
    	label.set_tooltip(Quarterly_label, "Quarterly Open")
        
        check_intersection_open(Quarterly_label, check_quarterly)

        // if ((    monthly_open == quarterly_open) and (quarterly_open == yearly_open))
        //     //label.set_text(monthlyLabel, "MO / QO / YO               ")
        //     label.set_text(Quarterly_label, "MO / QO / YO               ")


    // PREVIOUS QUARTERLY OPEN
    
    if is_previous_quarterly_open_enabled
        previous_quarterly_openlimit_right = get_limit_right()

        var previous_quarterly_open_line = line.new(x1 = quarterlypo_time,
           x2 = previous_quarterly_openlimit_right,
           y1 = quarterlyp_open,
           y2 = quarterlyp_open,
           color = QuarterlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var previous_quarterly_open_label = label.new(x = previous_quarterly_openlimit_right,
           y = quarterlyp_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = QuarterlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(previous_quarterly_open_line, quarterlypo_time)
    	line.set_x2(previous_quarterly_open_line, previous_quarterly_openlimit_right)
    	line.set_y1(previous_quarterly_open_line, quarterlyp_open)
    	line.set_y2(previous_quarterly_open_line, quarterlyp_open)
    	label.set_x(previous_quarterly_open_label, previous_quarterly_openlimit_right)
    	label.set_y(previous_quarterly_open_label, quarterlyp_open)
    	label.set_text(previous_quarterly_open_label, "PQO")
    	label.set_tooltip(previous_quarterly_open_label, "Previous Quarterly Open")

        check_intersection_open(previous_quarterly_open_label, check_previous_quarterly)

    // QUARTERLY HIGH

    if is_quarterlyrange_enabled
        Quarterlyh_limit_right = get_limit_right()

        var Quarterlyh_line = line.new(x1 = quarterlyph_time,
           x2 = Quarterlyh_limit_right,
           y1 = quarterlyp_high,
           y2 = quarterlyp_high,
           color = QuarterlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var Quarterlyh_label = label.new(x = Quarterlyh_limit_right,
           y = quarterlyp_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = QuarterlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(Quarterlyh_line, quarterlyph_time)
    	line.set_x2(Quarterlyh_line, Quarterlyh_limit_right)
    	line.set_y1(Quarterlyh_line, quarterlyp_high)
    	line.set_y2(Quarterlyh_line, quarterlyp_high)
    	label.set_x(Quarterlyh_label, Quarterlyh_limit_right)
    	label.set_y(Quarterlyh_label, quarterlyp_high)
    	label.set_text(Quarterlyh_label, "PQH")
    	label.set_tooltip(Quarterlyh_label, "Previous Quarterly High")

        check_intersection_open(Quarterlyh_label, check_quarterly_high)

    // QUARTERLY LOW

    if is_quarterlyrange_enabled
        Quarterlyl_limit_right = get_limit_right()

        var Quarterlyl_line = line.new(x1 = quarterlypl_time,
           x2 = Quarterlyl_limit_right,
           y1 = quarterlyp_low,
           y2 = quarterlyp_low,
           color = QuarterlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var Quarterlyl_label = label.new(x = Quarterlyl_limit_right,
           y = quarterlyp_low,
           style = DEFAULT_LABEL_STYLE,
           textcolor = QuarterlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(Quarterlyl_line, quarterlypl_time)
    	line.set_x2(Quarterlyl_line, Quarterlyl_limit_right)
    	line.set_y1(Quarterlyl_line, quarterlyp_low)
    	line.set_y2(Quarterlyl_line, quarterlyp_low)
    	label.set_x(Quarterlyl_label, Quarterlyl_limit_right)
    	label.set_y(Quarterlyl_label, quarterlyp_low)
    	label.set_text(Quarterlyl_label, "PQL")
    	label.set_tooltip(Quarterlyl_label, "Previous Quarterly Low")

        check_intersection_open(Quarterlyl_label, check_quarterly_low)

    // QUARTERLY MID

    if  is_previous_quarterly_mid_enabled
        quarterlym_limit_right = get_limit_right()

        //quarterly_mid = (quarterlyp_high + quarterlyp_low ) / 2
        
        var quarterlym_line = line.new(x1 = quarterlypl_time,
           x2 = quarterlym_limit_right,
           y1 = quarterly_mid,
           y2 = quarterly_mid,
           color = QuarterlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var quarterlym_label = label.new(x = quarterlym_limit_right,
           y = quarterly_mid,
           style = DEFAULT_LABEL_STYLE,
           textcolor = QuarterlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(quarterlym_line, quarterlypl_time)
    	line.set_x2(quarterlym_line, quarterlym_limit_right)
    	line.set_y1(quarterlym_line, quarterly_mid)
    	line.set_y2(quarterlym_line, quarterly_mid)
    	label.set_x(quarterlym_label, quarterlym_limit_right)
    	label.set_y(quarterlym_label, quarterly_mid)
    	label.set_text(quarterlym_label, "PQM")
    	label.set_tooltip(quarterlym_label, "Previous Quarterly Mid")

        check_intersection_open(quarterlym_label, check_quarterly_mid)

    // YEARLY OPEN

    if is_yearly_enabled
        yearly_limit_right = get_limit_right()

        var yearly_line = line.new(x1 = yearly_time,
           x2 = yearly_limit_right,
           y1 = yearly_open,
           y2 = yearly_open,
           color = YearlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var yearly_label = label.new(x = yearly_limit_right,
           y = yearly_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = YearlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(yearly_line, yearly_time)
    	line.set_x2(yearly_line, yearly_limit_right)
    	line.set_y1(yearly_line, yearly_open)
    	line.set_y2(yearly_line, yearly_open)
    	label.set_x(yearly_label, yearly_limit_right)
    	label.set_y(yearly_label, yearly_open)
    	label.set_text(yearly_label, "YO")
    	label.set_tooltip(yearly_label, "Yearly Open")

        check_intersection_open(yearly_label, check_yearly)
        // if ((monthly_open == quarterly_open) and (quarterly_open == yearly_open))
        //     //label.set_text(monthlyLabel, "MO / QO / YO               ")
        //     label.set_text(yearly_label, "MO / QO / YO               ")


    // PREVIOUS YEARLY OPEN

    if is_previous_yearly_enabled
        yearlypo_limit_right = get_limit_right()

        var yearlypo_line = line.new(x1 = yearlypo_time,
           x2 = yearlypo_limit_right,
           y1 = yearlyp_open,
           y2 = yearlyp_open,
           color = YearlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var yearlypo_label = label.new(x = yearlypo_limit_right,
           y = yearlyp_open,
           style = DEFAULT_LABEL_STYLE,
           textcolor = YearlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(yearlypo_line, yearlypo_time)
    	line.set_x2(yearlypo_line, yearlypo_limit_right)
    	line.set_y1(yearlypo_line, yearlyp_open)
    	line.set_y2(yearlypo_line, yearlyp_open)
    	label.set_x(yearlypo_label, yearlypo_limit_right)
    	label.set_y(yearlypo_label, yearlyp_open)
    	label.set_text(yearlypo_label, "PYO")
    	label.set_tooltip(yearlypo_label, "Previous Yearly Open")

        check_intersection_open(yearlypo_label, check_previous_yearly)

    // YEARLY LOW

    if is_yearlyrange_enabled
        yearlyl_limit_right = get_limit_right()

        var yearlyl_line = line.new(x1 = yearlypl_time,
           x2 = yearlyl_limit_right,
           y1 = yearlyp_low,
           y2 = yearlyp_low,
           color = YearlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var yearlyl_label = label.new(x = yearlyl_limit_right,
           y = yearlyp_low,
           style = DEFAULT_LABEL_STYLE,
           textcolor = YearlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(yearlyl_line, yearlypl_time)
    	line.set_x2(yearlyl_line, yearlyl_limit_right)
    	line.set_y1(yearlyl_line, yearlyp_low)
    	line.set_y2(yearlyl_line, yearlyp_low)
    	label.set_x(yearlyl_label, yearlyl_limit_right)
    	label.set_y(yearlyl_label, yearlyp_low)
    	label.set_text(yearlyl_label, "YL")
    	label.set_tooltip(yearlyl_label, "Yearly Low")

        check_intersection_open(yearlyl_label, check_yearly_low)
  
    // YEARLY HIGH


    if is_yearlyrange_enabled
        yearlyh_limit_right = get_limit_right()
        
        var yearlyh_line = line.new(x1 = yearlyph_time,
           x2 = yearlyh_limit_right,
           y1 = yearlyp_high,
           y2 = yearlyp_high,
           color = YearlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var yearlyh_label = label.new(x = yearlyh_limit_right,
           y = yearlyp_high,
           style = DEFAULT_LABEL_STYLE,
           textcolor = YearlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(yearlyh_line, yearlyph_time)
    	line.set_x2(yearlyh_line, yearlyh_limit_right)
    	line.set_y1(yearlyh_line, yearlyp_high)
    	line.set_y2(yearlyh_line, yearlyp_high)
    	label.set_x(yearlyh_label, yearlyh_limit_right)
    	label.set_y(yearlyh_label, yearlyp_high)
    	label.set_text(yearlyh_label, "YH")
    	label.set_tooltip(yearlyh_label, "Yearly High")

        check_intersection_open(yearlyh_label, check_yearly_high)

    // YEARLY MID

    if  is_yearly_mid_enabled
        yearlym_limit_right = get_limit_right()

        //yearly_mid = (yearlyp_high + yearlyp_low ) / 2
        
        var yearlym_line = line.new(x1 = yearlypl_time,
           x2 = yearlym_limit_right,
           y1 = yearly_mid,
           y2 = yearly_mid,
           color = YearlyColor,
           width = DEFAULT_LINE_WIDTH,
           xloc = xloc.bar_time)
        var yearlym_label = label.new(x = yearlym_limit_right,
           y = yearly_mid,
           style = DEFAULT_LABEL_STYLE,
           textcolor = YearlyColor,
           size = DEFAULT_LABEL_SIZE,
           xloc = xloc.bar_time)

        line.set_x1(yearlym_line, yearlypl_time)
    	line.set_x2(yearlym_line, yearlym_limit_right)
    	line.set_y1(yearlym_line, yearly_mid)
    	line.set_y2(yearlym_line, yearly_mid)
    	label.set_x(yearlym_label, yearlym_limit_right)
    	label.set_y(yearlym_label, yearly_mid)
    	label.set_text(yearlym_label, "PYM")
    	label.set_tooltip(yearlym_label, "Yearly Mid")

        check_intersection_open(yearlym_label, check_yearly_mid)

// ALERTS
// Create alert conditions
isMondayHigh() => cross(monday_high, close)
alertcondition(isMondayHigh(), title="Monday High", message="Monday High, {{ticker}}, price = {{close}}, volume = {{volume}}")

isMondayLow() => cross(monday_low, close)
alertcondition(isMondayLow(), title="Monday Low", message="Monday Low, {{ticker}}, price = {{close}}, volume = {{volume}}")

isMondayMid() => cross(monday_mid, close)
alertcondition(isMondayMid(), title="Monday Mid", message="Monday Mid, {{ticker}}, price = {{close}}, volume = {{volume}}")

isWeeklyOpen() => cross(weekly_open, close)
alertcondition(isWeeklyOpen(), title="Weekly Open", message="Weekly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousWeeklyOpen() => cross(weeklyp_open, close)
alertcondition(isPreviousWeeklyOpen(), title="Previous Weekly Open", message="Previous Weekly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousWeeklyHigh() => cross(weeklyp_high, close)
alertcondition(isPreviousWeeklyHigh(), title="Previous Weekly High", message="Previous Weekly High, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousWeeklyLow() => cross(weeklyp_low, close)
alertcondition(isPreviousWeeklyLow(), title="Previous Weekly Low", message="Previous Weekly Low, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousWeeklyMid() => cross(weekly_mid_open, close)
alertcondition(isPreviousWeeklyMid(), title="Previous Weekly Mid", message="Previous Weekly Mid, {{ticker}}, price = {{close}}, volume = {{volume}}")

isMonthlyOpen() => cross(monthly_open, close)
alertcondition(isMonthlyOpen(), title="Monthly Open", message="Monthly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousMonthlyOpen() => cross(monthlyp_open, close)
alertcondition(isPreviousMonthlyOpen(), title="Previous Monthly Open", message="Previous Monthly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousMonthlyHigh() => cross(monthlyp_high, close)
alertcondition(isPreviousMonthlyHigh(), title="Previous Monthly High", message="Previous Monthly High, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousMonthlyLow() => cross(monthlyp_low, close)
alertcondition(isPreviousMonthlyLow(), title="Previous Monthly Low", message="Previous Monthly Low, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousMonthlyMid() => cross(monthly_mid_open, close)
alertcondition(isPreviousMonthlyMid(), title="Previous Monthly Mid", message="Previous Monthly Mid, {{ticker}}, price = {{close}}, volume = {{volume}}")

isQuarterlyOpen() => cross(quarterly_open, close)
alertcondition(isQuarterlyOpen(), title="Quarterly Open", message="Quarterly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousQuarterlyOpen() => cross(quarterlyp_open, close)
alertcondition(isPreviousQuarterlyOpen(), title="Previous Quarterly Open", message="Previous Quarterly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousQuarterlyHigh() => cross(quarterlyp_high, close)
alertcondition(isPreviousQuarterlyHigh(), title="Previous Quarterly High", message="Previous Quarterly High, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousQuarterlyLow() => cross(quarterlyp_low, close)
alertcondition(isPreviousQuarterlyLow(), title="Previous Quarterly Low", message="Previous Quarterly Low, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousQuarterlyMid() => cross(quarterly_mid, close)
alertcondition(isPreviousQuarterlyMid(), title="Previous Quarterly Mid", message="Previous Quarterly Mid, {{ticker}}, price = {{close}}, volume = {{volume}}")

isYearlyOpen() => cross(yearly_open, close)
alertcondition(isYearlyOpen(), title="Yearly Open", message="Yearly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isPreviousYearlyOpen() => cross(yearlyp_open, close)
alertcondition(isPreviousYearlyOpen(), title="Previous Yearly Open", message="Previous Yearly Open, {{ticker}}, price = {{close}}, volume = {{volume}}")

isYearlyMid() => cross(yearly_mid, close)
alertcondition(isYearlyMid(), title="Yearly Mid", message="Yearly Mid, {{ticker}}, price = {{close}}, volume = {{volume}}")
