My:HTF O/H/L/C
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Thlem

//@version=4
study("My:HTF O/H/L/C", overlay=true)

showCurrentDailyOpen = input(true, title="Show Current Daily Open - CDO", group="-- Current Daily --")
showCurrentDailyHigh = input(true, title="Show Current Daily High - CDH", group="-- Current Daily --")
showCurrentDailyLow = input(true, title="Show Current Daily Low - CDL", group="-- Current Daily --")

showCurrentWeeklyOpen = input(true, title="Show Current Weekly Open - CWO", group="-- Current Weekly --")
showCurrentWeeklyHigh = input(true, title="Show Current Weekly High - CWH", group="-- Current Weekly --")
showCurrentWeeklyLow = input(true, title="Show Current Weekly Low - CWL", group="-- Current Weekly --")

showCurrentMonthlyOpen = input(true, title="Show Current Monthly Open - CMO", group="-- Current Monthly --")
showCurrentMonthlyHigh = input(true, title="Show Current Monthly High - CMH", group="-- Current Monthly --")
showCurrentMonthlyLow = input(true, title="Show Current Monthly Low - CML", group="-- Current Monthly --")


showPreviousDailyOpen = input(true, title="Show Previous Daily Open - PDO", group="-- Previous Daily --")
showPreviousDailyHigh = input(true, title="Show Previous Daily High - PDH", group="-- Previous Daily --")
showPreviousDailyLow = input(true, title="Show Previous Daily Low - PDL", group="-- Previous Daily --")
showPreviousDailyClose = input(true, title="Show Previous Daily Close - PDC", group="-- Previous Daily --")

showPreviousWeeklyOpen = input(true, title="Show Previous Weekly Open - PWO", group="-- Previous Weekly --")
showPreviousWeeklyHigh = input(true, title="Show Previous Weekly High - PWH", group="-- Previous Weekly --")
showPreviousWeeklyLow = input(true, title="Show Previous Weekly Low - PWL", group="-- Previous Weekly --")
showPreviousWeeklyClose = input(true, title="Show Previous Weekly Close - PWC", group="-- Previous Weekly --")

showPreviousMonthlyOpen = input(true, title="Show Previous Monthly Open - PMO", group="-- Previous Monthly --")
showPreviousMonthlyHigh = input(true, title="Show Previous Monthly High - PMH", group="-- Previous Monthly --")
showPreviousMonthlyLow = input(true, title="Show Previous Monthly Low - PML", group="-- Previous Monthly --")
showPreviousMonthlyClose = input(true, title="Show Previous Monthly Close - PMC", group="-- Previous Monthly --")


[m_open, m_close, m_high, m_low] = security(syminfo.tickerid, '1M', [open[1], close[1], high[1], low[1]])
[w_open, w_close, w_high, w_low] = security(syminfo.tickerid, '1W', [open[1], close[1], high[1], low[1]])
[d_open, d_close, d_high, d_low] = security(syminfo.tickerid, '1D', [open[1], close[1], high[1], low[1]])
[cm_open, cm_high, cm_low] = security(syminfo.tickerid, '1M', [open, high, low])
[cw_open, cw_high, cw_low] = security(syminfo.tickerid, '1W', [open, high, low])
[cd_open, cd_high, cd_low] = security(syminfo.tickerid, '1D', [open, high, low])


labelXLoc(offset) => time_close + (( time_close - time_close[1] ) * offset )
barIndex = if (timeframe.ismonthly or timeframe.isweekly or timeframe.isdaily)
    1
else if (timeframe.period == '240')
    7
else if (timeframe.period == '120')
    12
else if (timeframe.period == '180')
    8
else if (timeframe.period == '60')
    24
else if (timeframe.period == '15')
    24*4
else if (timeframe.period == '1')
    24*4
else
    10

showDaily = timeframe.ismonthly == false and timeframe.isweekly == false
showWeekly = timeframe.ismonthly == false

/////////////////////////////////////////////////
// Current Daily price of interest
/////////////////////////////////////////////////
if (showDaily and showCurrentDailyOpen)
    cd_open_line = line.new(bar_index[barIndex], cd_open, bar_index, cd_open, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    cd_open_label = label.new (labelXLoc(15), cd_open, "CDO" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(cd_open_line[1])
    label.delete(cd_open_label[1])
if (showDaily and showCurrentDailyHigh)
    cd_high_line = line.new(bar_index[barIndex], cd_high, bar_index, cd_high, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    cd_high_label = label.new (labelXLoc(15), cd_high, "CDH" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(cd_high_line[1])
    label.delete(cd_high_label[1])
if (showDaily and showCurrentDailyLow)
    cd_low_line = line.new(bar_index[barIndex], cd_low, bar_index, cd_low, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    cd_low_label = label.new (labelXLoc(15), cd_low, "CDL" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(cd_low_line[1])
    label.delete(cd_low_label[1])
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Current Weekly price of interest
/////////////////////////////////////////////////
if (showWeekly and showCurrentWeeklyOpen)
    cw_open_line = line.new(bar_index[barIndex], cw_open, bar_index, cw_open, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    cw_open_label = label.new (labelXLoc(55), cw_open, "CWO" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(cw_open_line[1])
    label.delete(cw_open_label[1])
if (showWeekly and showCurrentWeeklyHigh)
    cw_high_line = line.new(bar_index[barIndex], cw_high, bar_index, cw_high, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    cw_high_label = label.new (labelXLoc(55), cw_high, "CWH" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(cw_high_line[1])
    label.delete(cw_high_label[1])
if (showWeekly and showCurrentWeeklyLow)
    cw_low_line = line.new(bar_index[barIndex], cw_low, bar_index, cw_low, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    cw_low_label = label.new (labelXLoc(55), cw_low, "CWL" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(cw_low_line[1])
    label.delete(cw_low_label[1])
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Current Monthly price of interest
/////////////////////////////////////////////////
if (showCurrentMonthlyOpen)
    cm_open_line = line.new(bar_index[barIndex], cm_open, bar_index, cm_open, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    cm_open_label = label.new (labelXLoc(115), cm_open, "CMO" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(cm_open_line[1])
    label.delete(cm_open_label[1])
if (showCurrentMonthlyHigh)
    cm_high_line = line.new(bar_index[barIndex], cm_high, bar_index, cm_high, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    cm_high_label = label.new (labelXLoc(115), cm_high, "CMH" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(cm_high_line[1])
    label.delete(cm_high_label[1])
if (showCurrentMonthlyLow)
    cm_low_line = line.new(bar_index[barIndex], cm_low, bar_index, cm_low, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    cm_low_label = label.new (labelXLoc(115), cm_low, "CML" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(cm_low_line[1])
    label.delete(cm_low_label[1])
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Previous Daily price of interest
/////////////////////////////////////////////////
if (showDaily and showPreviousDailyOpen)
    d_open_line = line.new(bar_index[barIndex], d_open, bar_index, d_open, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    d_open_label = label.new (labelXLoc(35), d_open, "PDO" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(d_open_line[1])
    label.delete(d_open_label[1])
if (showDaily and showPreviousDailyClose)
    d_close_line = line.new(bar_index[barIndex], d_close, bar_index, d_close, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    d_close_label = label.new (labelXLoc(35), d_close, "PDC" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(d_close_line[1])
    label.delete(d_close_label[1])
if (showDaily and showPreviousDailyHigh)
    d_high_line = line.new(bar_index[barIndex], d_high, bar_index, d_high, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    d_high_label = label.new (labelXLoc(35), d_high, "PDH" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(d_high_line[1])
    label.delete(d_high_label[1])
if (showDaily and showPreviousDailyLow)
    d_low_line = line.new(bar_index[barIndex], d_low, bar_index, d_low, xloc.bar_index, extend=extend.right, color=color.white, style=line.style_solid, width=1)
    d_low_label = label.new (labelXLoc(35), d_low, "PDL" , xloc.bar_time, yloc.price, color.white, label.style_label_left, color.black, size=size.normal )
    line.delete(d_low_line[1])
    label.delete(d_low_label[1])
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Previous Weekly price of interest
/////////////////////////////////////////////////
if (showWeekly and showPreviousWeeklyOpen)
    w_open_line = line.new(bar_index[barIndex], w_open, bar_index, w_open, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    w_open_label = label.new (labelXLoc(75), w_open, "PWO" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(w_open_line[1])
    label.delete(w_open_label[1])
if (showWeekly and showPreviousWeeklyClose)
    w_close_line = line.new(bar_index[barIndex], w_close, bar_index, w_close, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    w_close_label = label.new (labelXLoc(75), w_close, "PWC" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(w_close_line[1])
    label.delete(w_close_label[1])
if (showWeekly and showPreviousWeeklyHigh)
    w_high_line = line.new(bar_index[barIndex], w_high, bar_index, w_high, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    w_high_label = label.new (labelXLoc(75), w_high, "PWH" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(w_high_line[1])
    label.delete(w_high_label[1])
if (showWeekly and showPreviousWeeklyLow)
    w_low_line = line.new(bar_index[barIndex], w_low, bar_index, w_low, xloc.bar_index, extend=extend.right, color=color.lime, style=line.style_solid, width=1)
    w_low_label = label.new (labelXLoc(75), w_low, "PWL" , xloc.bar_time, yloc.price, color.lime, label.style_label_left, color.black, size=size.normal )
    line.delete(w_low_line[1])
    label.delete(w_low_label[1])
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Previous Monthly price of interest
/////////////////////////////////////////////////
if (showPreviousMonthlyOpen)
    m_open_line = line.new(bar_index[barIndex], m_open, bar_index, m_open, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    m_open_label = label.new (labelXLoc(125), m_open, "PMO" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(m_open_line[1])
    label.delete(m_open_label[1])
if (showPreviousMonthlyClose)
    m_close_line = line.new(bar_index[barIndex], m_close, bar_index, m_close, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    m_close_label = label.new (labelXLoc(125), m_close, "PMC" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(m_close_line[1])
    label.delete(m_close_label[1])
if (showPreviousMonthlyHigh)
    m_high_line = line.new(bar_index[barIndex], m_high, bar_index, m_high, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    m_high_label = label.new (labelXLoc(125), m_high, "PMH" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(m_high_line[1])
    label.delete(m_high_label[1])
if (showPreviousMonthlyLow)
    m_low_line = line.new(bar_index[barIndex], m_low, bar_index, m_low, xloc.bar_index, extend=extend.right, color=color.aqua, style=line.style_solid, width=1)
    m_low_label = label.new (labelXLoc(125), m_low, "PML" , xloc.bar_time, yloc.price, color.aqua, label.style_label_left, color.black, size=size.normal )
    line.delete(m_low_line[1])
    label.delete(m_low_label[1])
/////////////////////////////////////////////////
