Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title='Daily levels', shorttitle='Daily Levels', precision=2, overlay=true)
- // 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) =>
- 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 == "close"
- if _start_condition
- _price := close
- _start_time := time
- else if _active_condition
- _price := close
- 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)
- // Global arrays used to detect duplicate levels.
- 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(10, 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
- // -----------------------------------------------------------------------------
- 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_yearly_col = input.color(color.red, title = "color", group = "Yearly Levels", inline = "2")
- inp_yearly_line_width = input.int(2, 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("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)
- // Quarterly
- // -----------------------------------------------------------------------------
- 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_quarterly_col = input.color(color.orange, title = "color", group = "Quarterly Levels", inline = "2")
- inp_quarterly_line_width = input.int(2, title = "Line width", minval = 1, group = "Quarterly Levels", inline = "2")
- quarterly_ok = timeframe.isintraday or timeframe.isdaily or timeframe.isweekly
- 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)
- // Monthly
- // -----------------------------------------------------------------------------
- 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_monthly_col = input.color(color.lime, title = "color", group = "Monthly Levels", inline = "2")
- inp_monthly_line_width = input.int(2, title = "Line width", minval = 1, group = "Monthly Levels", inline = "2")
- monthly_ok = timeframe.isintraday or timeframe.isdaily
- 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)
- // Weekly
- // -----------------------------------------------------------------------------
- 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_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("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)
- // 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_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("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)
- 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_close = input.bool(true, title = "CLOSE", 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("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("close", 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 CLOSE", 1, inp_show_prev_daily_close and daily_ok)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement