SESSION PIN
SESSION PIN
0 at
https://mozilla.org/MPL/2.0/
// © tradeforopp
//@version=5
indicator("ICT Killzones & Pivots [TFO]", "ICT Killzones & Pivots [TFO]", true, max_labels_count = 500,
max_lines_count = 500, max_boxes_count = 500)
get_line_type(_style) =>
result
get_size(x) =>
result = switch x
get_table_pos(pos) =>
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)
txt_color = input.color(color.black, "Text Color", tooltip = "The color of all label and table text",
group = g_SETTINGS)
use_cutoff = input.bool(false, "Drawing Cutoff Time", inline = "CO", tooltip = "When enabled, all
pivots and open price lines will stop extending at this time", group = g_SETTINGS)
use_alerts = input.bool(false, "Alert Broken Pivots", inline = "PV", tooltip = "The desired killzones
must be enabled at the time that an alert is created, along with the show pivots option, in order for
alerts to work", group = g_LABELS)
show_range_avg = input.bool(true, "Show Average", tooltip = "Show the average range of each
selected killzone", group = g_RNG)
range_avg = input.int(5, "Average Length", 0, tooltip = "This many previous sessions will be used
to calculate the average. If there isn't enough data on the current chart, it will use as many sessions
as possible", group = g_RNG)
alert_HL = input.bool(false, "Alert High/Low Break", tooltip = "Alert when any selected highs
and lows are traded through. The desired timeframe's high/low option must be enabled at the time
that an alert is created", group = g_DWM)
ds = input.bool(false, "Separators", inline = "DO", tooltip = "Mark where a new day begins",
group = g_DWM)
type kz
string _title
box[] _box
line[] _hi_line
line[] _md_line
line[] _lo_line
label[] _hi_label
label[] _lo_label
bool[] _hi_valid
bool[] _md_valid
bool[] _lo_valid
float[] _range_store
float _range_current
type hz
line[] LN
label[] LB
bool[] CO
type dwm_hl
line[] hi_line
line[] lo_line
label[] hi_label
label[] lo_label
type dwm_info
string tf
float o = na
float h = na
float l = na
float ph = na
float pl = na
var as_kz = kz.new(as_txt, array.new_box(), array.new_line(), array.new_line(), array.new_line(),
array.new_label(), array.new_label(), array.new_bool(), array.new_bool(), array.new_bool(),
array.new_float())
update_dwm_info(dwm_info n) =>
if timeframe.change(n.tf)
n.ph := n.h
n.pl := n.l
n.o := open
n.h := high
n.l := low
else
if dhl or show_d_open
update_dwm_info(d_info)
if whl or show_w_open
update_dwm_info(w_info)
if mhl or show_m_open
update_dwm_info(m_info)
get_box_color(color c) =>
result = color.new(c, box_transparency)
get_text_color(color c) =>
if use
if timeframe.change(tf)
arr.pop().delete()
dwm_open(string tf, bool use, line[] lns, label[] lbls, dwm_info n, color col) =>
if use
if lns.size() > 0
lns.get(0).set_x2(time)
lbls.get(0).set_x(time)
if timeframe.change(tf)
lns.pop().delete()
lbls.pop().delete()
dwm_hl(string tf, bool use, dwm_hl hl, dwm_info n, color col) =>
if use
if hl.hi_line.size() > 0
hl.hi_line.get(0).set_x2(time)
hl.lo_line.get(0).set_x2(time)
hl.hi_label.get(0).set_x(time)
hl.lo_label.get(0).set_x(time)
if timeframe.change(tf)
hl.hit_high := false
hl.hit_low := false
hl.hi_line.pop().delete()
hl.lo_line.pop().delete()
hl.hi_label.pop().delete()
hl.lo_label.pop().delete()
hl.hit_high := true
hl.hit_low := true
dwm() =>
// DWM - Separators
dwm_sep("D", ds, d_sep_line, d_color)
if use
if not v_unlimited
arr.pop().delete()
vlines() =>
if use
array.unshift(hz.CO, false)
hz.LN.pop().delete()
hz.LB.pop().delete()
hz.CO.pop()
if not hz.CO.get(0)
hz.LN.get(0).set_x2(bar_index)
hz.LB.get(0).set_x(bar_index)
hz.CO.set(0, true)
hz_lines() =>
del_kz(kz k) =>
k._hi_line.pop().delete()
k._lo_line.pop().delete()
k._hi_valid.pop()
k._lo_valid.pop()
if show_midpoints
k._md_line.pop().delete()
k._md_valid.pop()
k._hi_label.pop().delete()
k._lo_label.pop().delete()
S = L.get_text()
str.trim(pre)
if t
kz._box.get(0).set_right(time)
kz._box.get(0).set_top(math.max(kz._box.get(0).get_top(), high))
kz._box.get(0).set_bottom(math.min(kz._box.get(0).get_bottom(), low))
kz._hi_line.get(0).set_xy1(time, high)
kz._hi_line.get(0).set_xy2(time, high)
if low < kz._lo_line.get(0).get_y1()
kz._lo_line.get(0).set_xy1(time, low)
kz._lo_line.get(0).set_xy2(time, low)
if show_midpoints
kz._md_line.get(0).set_xy1(time, math.avg(kz._hi_line.get(0).get_y2(),
kz._lo_line.get(0).get_y2()))
kz._md_line.get(0).set_xy2(time, math.avg(kz._hi_line.get(0).get_y2(),
kz._lo_line.get(0).get_y2()))
if label_right
kz._hi_label.get(0).set_x(time)
kz._lo_label.get(0).set_x(time)
kz._hi_label.get(0).set_xy(time, high)
if label_price
update_price_string(kz._hi_label.get(0), high)
kz._lo_label.get(0).set_xy(time, low)
if label_price
update_price_string(kz._lo_label.get(0), low)
if t[1]
array.unshift(kz._range_store, kz._range_current)
kz._range_store.pop()
if kz._box.size() > 0 and show_pivots
for i = 0 to kz._box.size() - 1
kz._hi_line.get(i).set_x2(time)
kz._hi_label.get(i).set_x(time)
if use_alerts and i == 0
kz._hi_valid.set(i, false)
kz._hi_label.get(0).set_style(label.style_label_down)
kz._hi_valid.set(i, false)
kz._lo_line.get(i).set_x2(time)
kz._lo_label.get(i).set_x(time)
if use_alerts and i == 0
kz._lo_valid.set(i, false)
kz._lo_label.get(0).set_style(label.style_label_up)
kz._lo_valid.set(i, false)
if show_midpoints
kz._md_line.get(i).set_x2(time)
else
break
manage_kz(kz kz, bool use, bool t, color c, string box_txt, string hi_txt, string lo_txt) =>
_c = get_box_color(c)
_t = get_text_color(c)
if show_pivots
if show_midpoints
array.unshift(kz._md_valid, true)
array.unshift(kz._hi_valid, true)
array.unshift(kz._lo_valid, true)
if show_labels
if label_right
else
kz._hi_label.unshift(label.new(time, high, _hi_txt, xloc = xloc.bar_time, color =
transparent, textcolor = txt_color, style = label.style_label_down, size = lbl_size))
del_kz(kz)
adjust_in_kz(kz, t)
adjust_out_kz(kz, t)
dwm()
vlines()
hz_lines()
get_min_days_stored() =>
store = array.new_int()
if as_kz._range_store.size() > 0
store.push(as_kz._range_store.size())
if lo_kz._range_store.size() > 0
store.push(lo_kz._range_store.size())
if na_kz._range_store.size() > 0
store.push(na_kz._range_store.size())
if nl_kz._range_store.size() > 0
store.push(nl_kz._range_store.size())
if np_kz._range_store.size() > 0
store.push(np_kz._range_store.size())
result = store.min()
set_table(table tbl, kz kz, int row, string txt, bool use, bool t, color col) =>
if use
if show_range_avg
if show_range_avg