No Duplicates Interval Range & EQ
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rumpypumpydumpy

//@version=5
indicator("No duplicates interval rangee  & eq", overlay = true, max_lines_count = 56, max_labels_count = 56)


// Create Level Function {
// -----------------------------------------------------------------------------

f_create_level(_type, _start_condition, _active_condition, _global_level_array, _color, _line_width, _line_ext, _line_style, _label_size, _title, _iter, _is_enabled) =>
    // _type [ string ] : Determines level type to manage. Available options : "open", "high", "low", "eq"
    // _start_condition [ bool ] : Determines when to obtain initial value
    // _active_condition [ bool ] : Determines when to continue updated value if applicable
    // _global_level_array [ float[] ] : global array where other of same type of levels are stored to find duplicates
    // _color [ color ] : color of line/text
    // _line_ext [ int ] : Distance to extend line to the right
    // _line_style [ const string ] : line style type
    // _label_size [ const string ] : label size used to set text size
    // _title [ string ] : Prefix for level's text
    // _iter [ int ] : How many previous iterations to retrieve level from
    // _is_enabled : Override for disabling level
    var float _price = na
    var int _start_time = na
    var float _hh = na
    var float _ll = na
    var line _price_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, xloc = xloc.bar_time, color = _color, width = _line_width, style = _line_style)
    var label _price_label = label.new(x = na, y = na, xloc = xloc.bar_time, style = label.style_label_left, color = #00000000, size = _label_size, textcolor = _color)
    
    _end_time = int(time + _line_ext * ta.change(time))
    
    if _type == "open"
        if _start_condition
            _price := open
            _start_time := time
    else if _type == "high"
        if _start_condition
            _price := high
            _start_time := time
        else if _active_condition
            _price := math.max(_price, high)
    else if _type == "low"
        if _start_condition
            _price := low
            _start_time := time
        else if _active_condition
            _price := math.min(_price, low)
    else if _type == "eq"
        if _start_condition
            _hh := high
            _ll := low
            _price := math.avg(_hh, _ll)
            _start_time := time
        else if _active_condition
            _hh := math.max(_hh, high)
            _ll := math.min(_ll, low)
            _price := math.avg(_hh, _ll)
            
    float _price_val = _iter == 0 ? _price : ta.valuewhen(_start_condition, _price[1], _iter - 1)
    int _start_time_val = _iter == 0 ? _start_time : ta.valuewhen(_start_condition, _start_time[1], _iter - 1)
    
    _found_existing = array.indexof(_global_level_array, _price_val) > -1
    
    if _is_enabled
        if _found_existing
            line.set_xy1(_price_line, x = na, y = na)
            line.set_xy2(_price_line, x = na, y = na)
            label.set_xy(_price_label, x = na, y = na)
        else
            array.push(_global_level_array, _price_val)
            line.set_xy1(_price_line, x = _start_time_val, y = _price_val)
            line.set_xy2(_price_line, x = _end_time, y = _price_val)
            label.set_text(_price_label, text = _title + " : " + str.tostring(_price_val))
            label.set_xy(_price_label, x = _end_time, y = _price_val)
            
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// }



// Necessary Variables {
// -----------------------------------------------------------------------------

// Global arrays used to detect duplicate levels.
// Duplication is detected implicitly by execution order and whether the level has already been placed in the global array.
float[] global_open_array = array.new_float()
float[] global_high_array = array.new_float()
float[] global_low_array = array.new_float()
float[] global_eq_array = array.new_float()

new_H4 = ta.change(time("240")) != 0
new_day = ta.change(time("D")) != 0
new_week = ta.change(time("W")) != 0
new_month = ta.change(time("M")) != 0
new_quarter = ta.change(time("3M")) != 0
new_year = ta.change(time("12M")) != 0
is_monday = dayofweek == dayofweek.monday

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// }



// Global settings {
// -----------------------------------------------------------------------------

inp_open_line_style =   input.string("Dotted",  options = ["Solid", "Dotted", "Dashed"], title = "Open Line Style", group = "Global Settings")
inp_high_line_style =   input.string("Solid",   options = ["Solid", "Dotted", "Dashed"], title = "High Line Style", group = "Global Settings")
inp_low_line_style =    input.string("Solid",   options = ["Solid", "Dotted", "Dashed"], title = "Low Line Style",  group = "Global Settings")
inp_eq_line_style =     input.string("Dashed",  options = ["Solid", "Dotted", "Dashed"], title = "EQ Line Style",   group = "Global Settings")

inp_text_size =         input.string("Small", options = ["Small", "Normal", "Large"], title = "Text Size", group = "Global Settings")
inp_ext =               input.int(30, title = "Line Extension", group = "Global Settings")

text_size = inp_text_size == "Small" ? size.small : inp_text_size == "Normal" ? size.normal : size.large
open_line_style = inp_open_line_style == "Solid" ? line.style_solid : inp_open_line_style == "Dotted" ? line.style_dotted : line.style_dashed
high_line_style = inp_high_line_style == "Solid" ? line.style_solid : inp_high_line_style == "Dotted" ? line.style_dotted : line.style_dashed
low_line_style = inp_low_line_style == "Solid" ? line.style_solid : inp_low_line_style == "Dotted" ? line.style_dotted : line.style_dashed
eq_line_style = inp_eq_line_style == "Solid" ? line.style_solid : inp_eq_line_style == "Dotted" ? line.style_dotted : line.style_dashed

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// }



// Yearly & Prev Yearly
// -----------------------------------------------------------------------------
inp_show_yearly_open =  input.bool(true, title = "OPEN", group = "Yearly Levels", inline = "1")
inp_show_yearly_high =  input.bool(true, title = "HIGH", group = "Yearly Levels", inline = "1")
inp_show_yearly_low =   input.bool(true, title = "LOW", group = "Yearly Levels", inline = "1")
inp_show_yearly_eq =    input.bool(true, title = "EQ",  group = "Yearly Levels", inline = "1")
inp_yearly_col =        input.color(color.red, title = "color", group = "Yearly Levels", inline = "2")
inp_yearly_line_width = input.int(5, title = "Line width", minval = 1, group = "Yearly Levels", inline = "2")

yearly_ok = timeframe.isintraday or timeframe.isdaily or timeframe.isweekly or (timeframe.ismonthly and timeframe.multiplier < 12)

f_create_level("open", new_year, not new_year, global_open_array, inp_yearly_col, inp_yearly_line_width, inp_ext, open_line_style, text_size, "Yearly OPEN", 0, inp_show_yearly_open and yearly_ok)
f_create_level("high", new_year, not new_year, global_high_array, inp_yearly_col, inp_yearly_line_width, inp_ext, high_line_style, text_size, "Yearly HIGH", 0, inp_show_yearly_high and yearly_ok)
f_create_level("low", new_year, not new_year, global_low_array, inp_yearly_col, inp_yearly_line_width, inp_ext, low_line_style, text_size, "Yearly LOW", 0, inp_show_yearly_low and yearly_ok)
f_create_level("eq", new_year, not new_year, global_eq_array, inp_yearly_col, inp_yearly_line_width, inp_ext, eq_line_style, text_size, "Yearly EQ", 0, inp_show_yearly_eq and yearly_ok)


inp_show_prev_yearly_open =  input.bool(true, title = "OPEN", group = "Prev Yearly Levels", inline = "1")
inp_show_prev_yearly_high =  input.bool(true, title = "HIGH", group = "Prev Yearly Levels", inline = "1")
inp_show_prev_yearly_low =   input.bool(true, title = "LOW", group = "Prev Yearly Levels", inline = "1")
inp_show_prev_yearly_eq =    input.bool(true, title = "EQ",  group = "Prev Yearly Levels", inline = "1")
inp_prev_yearly_col =        input.color(color.maroon, title = "color", group = "Prev Yearly Levels", inline = "2")
inp_prev_yearly_line_width = input.int(5, title = "Line width", minval = 1, group = "Prev Yearly Levels", inline = "2")

f_create_level("open", new_year, not new_year, global_open_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, open_line_style, text_size, "Prev Yearly OPEN", 1, inp_show_prev_yearly_open and yearly_ok)
f_create_level("high", new_year, not new_year, global_high_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, high_line_style, text_size, "Prev Yearly HIGH", 1, inp_show_prev_yearly_high and yearly_ok)
f_create_level("low", new_year, not new_year, global_low_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, low_line_style, text_size, "Prev Yearly LOW", 1, inp_show_prev_yearly_low and yearly_ok)
f_create_level("eq", new_year, not new_year, global_eq_array, inp_prev_yearly_col, inp_prev_yearly_line_width, inp_ext, eq_line_style, text_size, "Prev Yearly EQ", 1, inp_show_prev_yearly_eq and yearly_ok)
// -----------------------------------------------------------------------------



// Quarterly and Prev Quarterly
// -----------------------------------------------------------------------------
inp_show_quarterly_open =  input.bool(true, title = "OPEN", group = "Quarterly Levels", inline = "1")
inp_show_quarterly_high =  input.bool(true, title = "HIGH", group = "Quarterly Levels", inline = "1")
inp_show_quarterly_low =   input.bool(true, title = "LOW", group = "Quarterly Levels", inline = "1")
inp_show_quarterly_eq =    input.bool(true, title = "EQ",  group = "Quarterly Levels", inline = "1")
inp_quarterly_col =        input.color(color.orange, title = "color", group = "Quarterly Levels", inline = "2")
inp_quarterly_line_width = input.int(4, title = "Line width", minval = 1, group = "Quarterly Levels", inline = "2")

quarterly_ok = timeframe.isintraday or timeframe.isdaily or timeframe.isweekly

f_create_level("open", new_quarter, not new_quarter, global_open_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, open_line_style, text_size, "Quarterly OPEN", 0, inp_show_quarterly_open and quarterly_ok)
f_create_level("high", new_quarter, not new_quarter, global_high_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, high_line_style, text_size, "Quarterly HIGH", 0, inp_show_quarterly_high and quarterly_ok)
f_create_level("low", new_quarter, not new_quarter, global_low_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, low_line_style, text_size, "Quarterly LOW", 0, inp_show_quarterly_low and quarterly_ok)
f_create_level("eq", new_quarter, not new_quarter, global_eq_array, inp_quarterly_col, inp_quarterly_line_width, inp_ext, eq_line_style, text_size, "Quarterly EQ", 0, inp_show_quarterly_eq and quarterly_ok)


inp_show_prev_quarterly_open =  input.bool(true, title = "OPEN", group = "Prev Quarterly Levels", inline = "1")
inp_show_prev_quarterly_high =  input.bool(true, title = "HIGH", group = "Prev Quarterly Levels", inline = "1")
inp_show_prev_quarterly_low =   input.bool(true, title = "LOW", group = "Prev Quarterly Levels", inline = "1")
inp_show_prev_quarterly_eq =    input.bool(true, title = "EQ",  group = "Prev Quarterly Levels", inline = "1")
inp_prev_quarterly_col =        input.color(color.yellow, title = "color", group = "Prev Quarterly Levels", inline = "2")
inp_prev_quarterly_line_width = input.int(4, title = "Line width", minval = 1, group = "Prev Quarterly Levels", inline = "2")

f_create_level("open", new_quarter, not new_quarter, global_open_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, open_line_style, text_size, "Prev Quarterly OPEN", 1, inp_show_prev_quarterly_open and quarterly_ok)
f_create_level("high", new_quarter, not new_quarter, global_high_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, high_line_style, text_size, "Prev Quarterly HIGH", 1, inp_show_prev_quarterly_high and quarterly_ok)
f_create_level("low", new_quarter, not new_quarter, global_low_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, low_line_style, text_size, "Prev Quarterly LOW", 1, inp_show_prev_quarterly_low and quarterly_ok)
f_create_level("eq", new_quarter, not new_quarter, global_eq_array, inp_prev_quarterly_col, inp_prev_quarterly_line_width, inp_ext, eq_line_style, text_size, "Prev Quarterly EQ", 1, inp_show_prev_quarterly_eq and quarterly_ok)
// -----------------------------------------------------------------------------




// Monthly and Prev Monthly
// -----------------------------------------------------------------------------
inp_show_monthly_open =  input.bool(true, title = "OPEN", group = "Monthly Levels", inline = "1")
inp_show_monthly_high =  input.bool(true, title = "HIGH", group = "Monthly Levels", inline = "1")
inp_show_monthly_low =   input.bool(true, title = "LOW", group = "Monthly Levels", inline = "1")
inp_show_monthly_eq =    input.bool(true, title = "EQ",  group = "Monthly Levels", inline = "1")
inp_monthly_col =        input.color(color.lime, title = "color", group = "Monthly Levels", inline = "2")
inp_monthly_line_width = input.int(3, title = "Line width", minval = 1, group = "Monthly Levels", inline = "2")

monthly_ok = timeframe.isintraday or timeframe.isdaily

f_create_level("open", new_month, not new_month, global_open_array, inp_monthly_col, inp_monthly_line_width, inp_ext, open_line_style, text_size, "Monthly OPEN", 0, inp_show_monthly_open and monthly_ok)
f_create_level("high", new_month, not new_month, global_high_array, inp_monthly_col, inp_monthly_line_width, inp_ext, high_line_style, text_size, "Monthly HIGH", 0, inp_show_monthly_high and monthly_ok)
f_create_level("low", new_month, not new_month, global_low_array, inp_monthly_col, inp_monthly_line_width, inp_ext, low_line_style, text_size, "Monthly LOW", 0, inp_show_monthly_low and monthly_ok)
f_create_level("eq", new_month, not new_month, global_eq_array, inp_monthly_col, inp_monthly_line_width, inp_ext, eq_line_style, text_size, "Monthly EQ", 0, inp_show_monthly_eq and monthly_ok)


inp_show_prev_monthly_open =  input.bool(true, title = "OPEN", group = "Prev Monthly Levels", inline = "1")
inp_show_prev_monthly_high =  input.bool(true, title = "HIGH", group = "Prev Monthly Levels", inline = "1")
inp_show_prev_monthly_low =   input.bool(true, title = "LOW", group = "Prev Monthly Levels", inline = "1")
inp_show_prev_monthly_eq =    input.bool(true, title = "EQ",  group = "Prev Monthly Levels", inline = "1")
inp_prev_monthly_col =        input.color(color.green, title = "color", group = "Prev Monthly Levels", inline = "2")
inp_prev_monthly_line_width = input.int(3, title = "Line width", minval = 1, group = "Prev Monthly Levels", inline = "2")

f_create_level("open", new_month, not new_month, global_open_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, open_line_style, text_size, "Prev Monthly OPEN", 1, inp_show_prev_monthly_open and monthly_ok)
f_create_level("high", new_month, not new_month, global_high_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, high_line_style, text_size, "Prev Monthly HIGH", 1, inp_show_prev_monthly_high and monthly_ok)
f_create_level("low", new_month, not new_month, global_low_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, low_line_style, text_size, "Prev Monthly LOW", 1, inp_show_prev_monthly_low and monthly_ok)
f_create_level("eq", new_month, not new_month, global_eq_array, inp_prev_monthly_col, inp_prev_monthly_line_width, inp_ext, eq_line_style, text_size, "Prev Monthly EQ", 1, inp_show_prev_monthly_eq and monthly_ok)
// -----------------------------------------------------------------------------



// Weekly and Prev Weekly
// -----------------------------------------------------------------------------
inp_show_weekly_open =  input.bool(true, title = "OPEN", group = "Weekly Levels", inline = "1")
inp_show_weekly_high =  input.bool(true, title = "HIGH", group = "Weekly Levels", inline = "1")
inp_show_weekly_low =   input.bool(true, title = "LOW", group = "Weekly Levels", inline = "1")
inp_show_weekly_eq =    input.bool(true, title = "EQ",  group = "Weekly Levels", inline = "1")
inp_weekly_col =        input.color(color.aqua, title = "color", group = "Weekly Levels", inline = "2")
inp_weekly_line_width = input.int(2, title = "Line width", minval = 1, group = "Weekly Levels", inline = "2")

weekly_ok = timeframe.isintraday or timeframe.isdaily

f_create_level("open", new_week, not new_week, global_open_array, inp_weekly_col, inp_weekly_line_width, inp_ext, open_line_style, text_size, "Weekly OPEN", 0, inp_show_weekly_open and weekly_ok)
f_create_level("high", new_week, not new_week, global_high_array, inp_weekly_col, inp_weekly_line_width, inp_ext, high_line_style, text_size, "Weekly HIGH", 0, inp_show_weekly_high and weekly_ok)
f_create_level("low", new_week, not new_week, global_low_array, inp_weekly_col, inp_weekly_line_width, inp_ext, low_line_style, text_size, "Weekly LOW", 0, inp_show_weekly_low and weekly_ok)
f_create_level("eq", new_week, not new_week, global_eq_array, inp_weekly_col, inp_weekly_line_width, inp_ext, eq_line_style, text_size, "Weekly EQ", 0, inp_show_weekly_eq and weekly_ok)


inp_show_prev_weekly_open =  input.bool(true, title = "OPEN", group = "Prev Weekly Levels", inline = "1")
inp_show_prev_weekly_high =  input.bool(true, title = "HIGH", group = "Prev Weekly Levels", inline = "1")
inp_show_prev_weekly_low =   input.bool(true, title = "LOW", group = "Prev Weekly Levels", inline = "1")
inp_show_prev_weekly_eq =    input.bool(true, title = "EQ",  group = "Prev Weekly Levels", inline = "1")
inp_prev_weekly_col =        input.color(color.blue, title = "color", group = "Prev Weekly Levels", inline = "2")
inp_prev_weekly_line_width = input.int(2, title = "Line width", minval = 1, group = "Prev Weekly Levels", inline = "2")

f_create_level("open", new_week, not new_week, global_open_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, open_line_style, text_size, "Prev Weekly OPEN", 1, inp_show_prev_weekly_open and weekly_ok)
f_create_level("high", new_week, not new_week, global_high_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, high_line_style, text_size, "Prev Weekly HIGH", 1, inp_show_prev_weekly_high and weekly_ok)
f_create_level("low", new_week, not new_week, global_low_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, low_line_style, text_size, "Prev Weekly LOW", 1, inp_show_prev_weekly_low and weekly_ok)
f_create_level("eq", new_week, not new_week, global_eq_array, inp_prev_weekly_col, inp_prev_weekly_line_width, inp_ext, eq_line_style, text_size, "Prev Weekly EQ", 1, inp_show_prev_weekly_eq and weekly_ok)
// -----------------------------------------------------------------------------




// Daily and Prev Daily
// -----------------------------------------------------------------------------
inp_show_daily_open =  input.bool(true, title = "OPEN", group = "Daily Levels", inline = "1")
inp_show_daily_high =  input.bool(true, title = "HIGH", group = "Daily Levels", inline = "1")
inp_show_daily_low =   input.bool(true, title = "LOW", group = "Daily Levels", inline = "1")
inp_show_daily_eq =    input.bool(true, title = "EQ",  group = "Daily Levels", inline = "1")
inp_daily_col =        input.color(color.white, title = "color", group = "Daily Levels", inline = "2")
inp_daily_line_width = input.int(1, title = "Line width", minval = 1, group = "Daily Levels", inline = "2")

daily_ok = timeframe.isintraday

f_create_level("open", new_day, not new_day, global_open_array, inp_daily_col, inp_daily_line_width, inp_ext, open_line_style, text_size, "Daily OPEN", 0, inp_show_daily_open and daily_ok)
f_create_level("high", new_day, not new_day, global_high_array, inp_daily_col, inp_daily_line_width, inp_ext, high_line_style, text_size, "Daily HIGH", 0, inp_show_daily_high and daily_ok)
f_create_level("low", new_day, not new_day, global_low_array, inp_daily_col, inp_daily_line_width, inp_ext, low_line_style, text_size, "Daily LOW", 0, inp_show_daily_low and daily_ok)
f_create_level("eq", new_day, not new_day, global_eq_array, inp_daily_col, inp_daily_line_width, inp_ext, eq_line_style, text_size, "Daily EQ", 0, inp_show_daily_eq and daily_ok)


inp_show_prev_daily_open =  input.bool(true, title = "OPEN", group = "Prev Daily Levels", inline = "1")
inp_show_prev_daily_high =  input.bool(true, title = "HIGH", group = "Prev Daily Levels", inline = "1")
inp_show_prev_daily_low =   input.bool(true, title = "LOW", group = "Prev Daily Levels", inline = "1")
inp_show_prev_daily_eq =    input.bool(true, title = "EQ",  group = "Prev Daily Levels", inline = "1")
inp_prev_daily_col =        input.color(color.gray, title = "color", group = "Prev Daily Levels", inline = "2")
inp_prev_daily_line_width = input.int(1, title = "Line width", minval = 1, group = "Prev Daily Levels", inline = "2")

f_create_level("open", new_day, not new_day, global_open_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, open_line_style, text_size, "Prev Daily OPEN", 1, inp_show_prev_daily_open and daily_ok)
f_create_level("high", new_day, not new_day, global_high_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, high_line_style, text_size, "Prev Daily HIGH", 1, inp_show_prev_daily_high and daily_ok)
f_create_level("low", new_day, not new_day, global_low_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, low_line_style, text_size, "Prev Daily LOW", 1, inp_show_prev_daily_low and daily_ok)
f_create_level("eq", new_day, not new_day, global_eq_array, inp_prev_daily_col, inp_prev_daily_line_width, inp_ext, eq_line_style, text_size, "Prev Daily EQ", 1, inp_show_prev_daily_eq and daily_ok)
// -----------------------------------------------------------------------------



// Monday and Prev Monday
// -----------------------------------------------------------------------------
// Note : Monday range is a special case and is why the _active_condition is implemented in the function. We only want start on Monday, and ONLY update levels during monday.
inp_show_monday_open =  input.bool(true, title = "OPEN", group = "Monday Levels", inline = "1")
inp_show_monday_high =  input.bool(true, title = "HIGH", group = "Monday Levels", inline = "1")
inp_show_monday_low =   input.bool(true, title = "LOW", group = "Monday Levels", inline = "1")
inp_show_monday_eq =    input.bool(true, title = "EQ",  group = "Monday Levels", inline = "1")
inp_monday_col =        input.color(color.fuchsia, title = "color", group = "Monday Levels", inline = "2")
inp_monday_line_width = input.int(1, title = "Line width", minval = 1, group = "Monday Levels", inline = "2")

monday_ok = timeframe.isintraday

f_create_level("open", new_week, is_monday, global_open_array, inp_monday_col, inp_monday_line_width, inp_ext, open_line_style, text_size, "Monday OPEN", 0, inp_show_monday_open and monday_ok)
f_create_level("high", new_week, is_monday, global_high_array, inp_monday_col, inp_monday_line_width, inp_ext, high_line_style, text_size, "Monday HIGH", 0, inp_show_monday_high and monday_ok)
f_create_level("low", new_week, is_monday, global_low_array, inp_monday_col, inp_monday_line_width, inp_ext, low_line_style, text_size, "Monday LOW", 0, inp_show_monday_low and monday_ok)
f_create_level("eq", new_week, is_monday, global_eq_array, inp_monday_col, inp_monday_line_width, inp_ext, eq_line_style, text_size, "Monday EQ", 0, inp_show_monday_eq and monday_ok)


inp_show_prev_monday_open =  input.bool(true, title = "OPEN", group = "Prev Monday Levels", inline = "1")
inp_show_prev_monday_high =  input.bool(true, title = "HIGH", group = "Prev Monday Levels", inline = "1")
inp_show_prev_monday_low =   input.bool(true, title = "LOW", group = "Prev Monday Levels", inline = "1")
inp_show_prev_monday_eq =    input.bool(true, title = "EQ",  group = "Prev Monday Levels", inline = "1")
inp_prev_monday_col =        input.color(color.purple, title = "color", group = "Prev Monday Levels", inline = "2")
inp_prev_monday_line_width = input.int(1, title = "Line width", minval = 1, group = "Prev Monday Levels", inline = "2")

f_create_level("open", new_week, is_monday, global_open_array, inp_prev_monday_col, inp_prev_monday_line_width, inp_ext, open_line_style, text_size, "Prev Monday OPEN", 1, inp_show_prev_monday_open and monday_ok)
f_create_level("high", new_week, is_monday, global_high_array, inp_prev_monday_col, inp_prev_monday_line_width, inp_ext, high_line_style, text_size, "Prev Monday HIGH", 1, inp_show_prev_monday_high and monday_ok)
f_create_level("low", new_week, is_monday, global_low_array, inp_prev_monday_col, inp_prev_monday_line_width, inp_ext, low_line_style, text_size, "Prev Monday LOW", 1, inp_show_prev_monday_low and monday_ok)
f_create_level("eq", new_week, is_monday, global_eq_array, inp_prev_monday_col, inp_prev_monday_line_width, inp_ext, eq_line_style, text_size, "Prev Monday EQ", 1, inp_show_prev_monday_eq and monday_ok)
// -----------------------------------------------------------------------------



// H4 and Prev H4
// -----------------------------------------------------------------------------
inp_show_H4_open =  input.bool(true, title = "OPEN", group = "H4 Levels", inline = "1")
inp_show_H4_high =  input.bool(true, title = "HIGH", group = "H4 Levels", inline = "1")
inp_show_H4_low =   input.bool(true, title = "LOW", group = "H4 Levels", inline = "1")
inp_show_H4_eq =    input.bool(true, title = "EQ",  group = "H4 Levels", inline = "1")
inp_H4_col =        input.color(color.teal, title = "color", group = "H4 Levels", inline = "2")
inp_H4_line_width = input.int(1, title = "Line width", minval = 1, group = "H4 Levels", inline = "2")

H4_ok = timeframe.isintraday and timeframe.multiplier < 240

f_create_level("open", new_H4, not new_H4, global_open_array, inp_H4_col, inp_H4_line_width, inp_ext, open_line_style, text_size, "H4 OPEN", 0, inp_show_H4_open and H4_ok)
f_create_level("high", new_H4, not new_H4, global_high_array, inp_H4_col, inp_H4_line_width, inp_ext, high_line_style, text_size, "H4 HIGH", 0, inp_show_H4_high and H4_ok)
f_create_level("low", new_H4, not new_H4, global_low_array, inp_H4_col, inp_H4_line_width, inp_ext, low_line_style, text_size, "H4 LOW", 0, inp_show_H4_low and H4_ok)
f_create_level("eq", new_H4, not new_H4, global_eq_array, inp_H4_col, inp_H4_line_width, inp_ext, eq_line_style, text_size, "H4 EQ", 0, inp_show_H4_eq and H4_ok)


inp_show_prev_H4_open =  input.bool(true, title = "OPEN", group = "Prev H4 Levels", inline = "1")
inp_show_prev_H4_high =  input.bool(true, title = "HIGH", group = "Prev H4 Levels", inline = "1")
inp_show_prev_H4_low =   input.bool(true, title = "LOW", group = "Prev H4 Levels", inline = "1")
inp_show_prev_H4_eq =    input.bool(true, title = "EQ",  group = "Prev H4 Levels", inline = "1")
inp_prev_H4_col =        input.color(color.olive, title = "color", group = "Prev H4 Levels", inline = "2")
inp_prev_H4_line_width = input.int(1, title = "Line width", minval = 1, group = "Prev H4 Levels", inline = "2")

f_create_level("open", new_H4, not new_H4, global_open_array, inp_prev_H4_col, inp_prev_H4_line_width, inp_ext, open_line_style, text_size, "Prev H4 OPEN", 1, inp_show_prev_H4_open and H4_ok)
f_create_level("high", new_H4, not new_H4, global_high_array, inp_prev_H4_col, inp_prev_H4_line_width, inp_ext, high_line_style, text_size, "Prev H4 HIGH", 1, inp_show_prev_H4_high and H4_ok)
f_create_level("low", new_H4, not new_H4, global_low_array, inp_prev_H4_col, inp_prev_H4_line_width, inp_ext, low_line_style, text_size, "Prev H4 LOW", 1, inp_show_prev_H4_low and H4_ok)
f_create_level("eq", new_H4, not new_H4, global_eq_array, inp_prev_H4_col, inp_prev_H4_line_width, inp_ext, eq_line_style, text_size, "Prev H4 EQ", 1, inp_show_prev_H4_eq and H4_ok)
// -----------------------------------------------------------------------------

