// ---------------------------------------- Inputs -------------------------------------------------- var g_SETTINGS = "Settings" max_days = input.int(3, "Session Drawing Limit", 1, tooltip = "Only this many drawings will be kept on the chart, for each selected drawing type (killzone boxes, pivot lines, open lines, etc.)", group = g_SETTINGS) tf_limit = input.timeframe("30", "Timeframe Limit", tooltip = "Drawings will not appear on timeframes greater than or equal to this", group = g_SETTINGS) gmt_tz = input.string('GMT-4', "Timezone", options = ['GMT-12','GMT-11','GMT-10','GMT-9','GMT-8','GMT-7','GMT-6','GMT-5','GMT-4','GMT-3','GMT-2','GMT-1','GMT+0','GMT+1','GMT+2','GMT+3','GMT+4','GMT+5','GMT+6','GMT+7','GMT+8','GMT+9','GMT+10','GMT+11','GMT+12','GMT+13','GMT+14'], tooltip = "Note GMT is not adjusted to reflect Daylight Saving Time changes", group = g_SETTINGS) lb_size = input.string('Normal', "Label Size", options = ['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = g_SETTINGS) lb_color = input.color(color.black, "Label Text Color", group = g_SETTINGS) use_cutoff = input.bool(true, "Drawing Cutoff Time", inline = "CO", tooltip = "When enabled, all highs and lows will stop extending after this time", group = g_SETTINGS) cutoff = input.session("1200-1201", "", inline = "CO", group = g_SETTINGS)
var g_KZ = "Killzones" show_kz = input.bool(true, "Show Killzone Boxes", inline = "KZ", group = g_KZ) show_kz_text = input.bool(true, "Display Text", inline = "KZ", group = g_KZ) box_transparency = input.int(70, "Box Transparency", 0, 100, group = g_KZ) text_transparency = input.int(50, "Text Transparency", 0, 100, group = g_KZ)
use_asia = input.bool(true, "", inline = "ASIA", group = g_KZ) asia_text = input.string("Asia", "", inline = "ASIA", group = g_KZ) asia = input.session("2000-0000", "", inline = "ASIA", group = g_KZ) as_color = input.color(color.blue, "", inline = "ASIA", group = g_KZ)
use_london = input.bool(true, "", inline = "LONDON", group = g_KZ) london_text = input.string("London", "", inline = "LONDON", group = g_KZ) london = input.session("0200-0500", "", inline = "LONDON", group = g_KZ) lo_color = input.color(color.red, "", inline = "LONDON", group = g_KZ)
// ---------------------------------------- Variables & Constants -------------------------------------------------- t_as = not na(time("", asia, gmt_tz)) t_lo = not na(time("", london, gmt_tz)) t_na = not na(time("", nyam, gmt_tz)) t_nl = not na(time("", nylu, gmt_tz)) t_np = not na(time("", nypm, gmt_tz)) t_co = not na(time("", cutoff, gmt_tz))
t_h1 = not na(time("", h1, gmt_tz)) t_h2 = not na(time("", h2, gmt_tz)) t_h3 = not na(time("", h3, gmt_tz)) t_h4 = not na(time("", h4, gmt_tz))
t_v1 = not na(time("", v1, gmt_tz)) t_v2 = not na(time("", v2, gmt_tz)) t_v3 = not na(time("", v3, gmt_tz)) t_v4 = not na(time("", v4, gmt_tz)) t_v5 = not na(time("", v5, gmt_tz)) t_v6 = not na(time("", v6, gmt_tz))
var as_hi_line = array.new_line() var as_lo_line = array.new_line() var lo_hi_line = array.new_line() var lo_lo_line = array.new_line() var na_hi_line = array.new_line() var na_lo_line = array.new_line() var nl_hi_line = array.new_line() var nl_lo_line = array.new_line() var np_hi_line = array.new_line() var np_lo_line = array.new_line()
var d_sep_line = array.new_line() var w_sep_line = array.new_line() var m_sep_line = array.new_line()
var d_line = array.new_line() var w_line = array.new_line() var m_line = array.new_line()
var h1_line = array.new_line() var h2_line = array.new_line() var h3_line = array.new_line() var h4_line = array.new_line()
var v1_line = array.new_line() var v2_line = array.new_line() var v3_line = array.new_line() var v4_line = array.new_line() var v5_line = array.new_line() var v6_line = array.new_line()
var d_label = array.new_label() var w_label = array.new_label() var m_label = array.new_label()
var h1_label = array.new_label() var h2_label = array.new_label() var h3_label = array.new_label() var h4_label = array.new_label()
var as_hi_label = array.new_label() var as_lo_label = array.new_label() var lo_hi_label = array.new_label() var lo_lo_label = array.new_label() var na_hi_label = array.new_label() var na_lo_label = array.new_label() var nl_hi_label = array.new_label() var nl_lo_label = array.new_label() var np_hi_label = array.new_label() var np_lo_label = array.new_label()
var as_box = array.new_box() var lo_box = array.new_box() var na_box = array.new_box() var nl_box = array.new_box() var np_box = array.new_box()
var color as_box_color = get_box_color(as_color, box_transparency) var color lo_box_color = get_box_color(lo_color, box_transparency) var color na_box_color = get_box_color(na_color, box_transparency) var color nl_box_color = get_box_color(nl_color, box_transparency) var color np_box_color = get_box_color(np_color, box_transparency)
var color as_text_color = get_box_color(as_color, text_transparency) var color lo_text_color = get_box_color(lo_color, text_transparency) var color na_text_color = get_box_color(na_color, text_transparency) var color nl_text_color = get_box_color(nl_color, text_transparency) var color np_text_color = get_box_color(np_color, text_transparency)
var h1_co = false var h2_co = false var h3_co = false var h4_co = false
var as_stop_hi = false var as_stop_lo = false
var lo_stop_hi = false var lo_stop_lo = false
var na_stop_hi = false var na_stop_lo = false
var nl_stop_hi = false var nl_stop_lo = false
var np_stop_hi = false var np_stop_lo = false
as_broke_hi = false as_broke_lo = false
lo_broke_hi = false lo_broke_lo = false
na_broke_hi = false na_broke_lo = false
nl_broke_hi = false nl_broke_lo = false
np_broke_hi = false np_broke_lo = false
// day_str = switch dayofweek
// if dayofweek != dayofweek[1] // label.new(time, high, str.tostring(dayofweek))
if timeframe.in_seconds("") <= timeframe.in_seconds(tf_limit) // Asia if use_asia if t_as and not t_as[1] as_stop_hi := false as_stop_lo := false
if show_pivots np_hi_line.unshift(line.new(bar_index, high, bar_index, high, style = s_style, color = np_color, width = s_width)) np_lo_line.unshift(line.new(bar_index, low, bar_index, low, style = s_style, color = np_color, width = s_width))
if show_labels np_hi_label.unshift(label.new(bar_index, high, nph_str, color = transparent, textcolor = lb_color, style = label.style_label_down, size = lb_size)) np_lo_label.unshift(label.new(bar_index, low, npl_str, color = transparent, textcolor = lb_color, style = label.style_label_up, size = lb_size)) else if t_np adjust(show_pivots ? np_hi_line.get(0) : na, show_pivots ? np_lo_line.get(0) : na, show_labels ? np_hi_label.get(0) : na, show_labels ? np_lo_label.get(0) : na, show_labels, show_kz ? np_box.get(0) : na) else if not t_np and np_hi_line.size() > 0 if not np_stop_hi [_r, _b] = check_high(np_hi_line.get(0)) if _r np_stop_hi := true if _b np_broke_hi := true if np_alert alert("Broke " + str.tostring(nph_str), alert.freq_once_per_bar) if not np_stop_lo [_r, _b] = check_low(np_lo_line.get(0)) if _r np_stop_lo := true if _b np_broke_lo := true if np_alert alert("Broke " + str.tostring(npl_str), alert.freq_once_per_bar)
// Vertical Lines if use_v1 if t_v1 and not t_v1[1] v1_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v1_color)) if use_v2 if t_v2 and not t_v2[1] v2_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v2_color)) if use_v3 if t_v3 and not t_v3[1] v3_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v3_color)) if use_v4 if t_v4 and not t_v4[1] v4_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v4_color)) if use_v5 if t_v5 and not t_v5[1] v5_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v5_color)) if use_v6 if t_v6 and not t_v6[1] v6_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v6_color))
// Horizontal Lines if use_h1 if t_h1 and not t_h1[1] h1_co := false
h1_line.unshift(line.new(bar_index, open, bar_index, open, style = h_style, width = h_width, color = h1_color)) h1_label.unshift(label.new(bar_index, open, h1_text, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if not t_h1 and h1_line.size() > 0 if not h1_co if not check_open(h1_line.get(0), h1_label.get(0)) h1_label.get(0).set_x(bar_index) else h1_co := true
if use_h2 if t_h2 and not t_h2[1] h2_co := false
h2_line.unshift(line.new(bar_index, open, bar_index, open, style = h_style, width = h_width, color = h2_color)) h2_label.unshift(label.new(bar_index, open, h2_text, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if not t_h2 and h2_line.size() > 0 if not h2_co if not check_open(h2_line.get(0), h2_label.get(0)) h2_label.get(0).set_x(bar_index) else h2_co := true
if use_h3 if t_h3 and not t_h3[1] h3_co := false
h3_line.unshift(line.new(bar_index, open, bar_index, open, style = h_style, width = h_width, color = h3_color)) h3_label.unshift(label.new(bar_index, open, h3_text, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if not t_h3 and h3_line.size() > 0 if not h3_co if not check_open(h3_line.get(0), h3_label.get(0)) h3_label.get(0).set_x(bar_index) else h3_co := true
if use_h4 if t_h4 and not t_h4[1] h4_co := false
h4_line.unshift(line.new(bar_index, open, bar_index, open, style = h_style, width = h_width, color = h4_color)) h4_label.unshift(label.new(bar_index, open, h4_text, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if not t_h4 and h4_line.size() > 0 if not h4_co if not check_open(h4_line.get(0), h4_label.get(0)) h4_label.get(0).set_x(bar_index) else h4_co := true
// DWM - Separators if ds if d_o != d_o[1] d_sep_line.unshift(line.new(bar_index, high, bar_index, low, style = dwm_style, width = dwm_width, extend = extend.both, color = d_color)) if ws if w_o != w_o[1] w_sep_line.unshift(line.new(bar_index, high, bar_index, low, style = dwm_style, width = dwm_width, extend = extend.both, color = w_color)) if ms if m_o != m_o[1] m_sep_line.unshift(line.new(bar_index, high, bar_index, low, style = dwm_style, width = dwm_width, extend = extend.both, color = m_color))
// DWM - Open Lines if show_d_open if d_o != d_o[1] d_line.unshift(line.new(bar_index, d_o, bar_index, d_o, style = dwm_style, width = dwm_width, color = d_color)) d_label.unshift(label.new(bar_index, d_o, d_open_str, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if d_line.size() > 0 if not check_open(d_line.get(0), d_label.get(0)) d_label.get(0).set_x(bar_index)
if show_w_open if w_o != w_o[1] w_line.unshift(line.new(bar_index, w_o, bar_index, w_o, style = dwm_style, width = dwm_width, color = w_color)) w_label.unshift(label.new(bar_index, w_o, w_open_str, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if w_line.size() > 0 if not check_open(w_line.get(0), w_label.get(0)) w_label.get(0).set_x(bar_index)
if show_m_open if m_o != m_o[1] m_line.unshift(line.new(bar_index, m_o, bar_index, m_o, style = dwm_style, width = dwm_width, color = m_color)) m_label.unshift(label.new(bar_index, m_o, m_open_str, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size)) else if m_line.size() > 0 if not check_open(m_line.get(0), m_label.get(0)) m_label.get(0).set_x(bar_index)
if not ds_unlimited check_array(d_sep_line) check_array(d_line) check_array(d_label) if not ws_unlimited check_array(w_sep_line) check_array(w_line) check_array(w_label) if not ms_unlimited check_array(m_sep_line) check_array(m_line) check_array(m_label) // ---------------------------------------- Core Logic --------------------------------------------------