FVG BY JOYDIP - KillZones Added
FVG BY JOYDIP - KillZones Added
FVG BY JOYDIP - KillZones Added
// Input options
numDays = input.int(7, "number of days lookback")
showUP = input.bool(true, "'UP' FVGs:", inline ='1')
colUp = input.color(color.new(color.blue, 86), "", inline ='1')
showDN = input.bool(true, "'DOWN' FVGs:", inline ='2')
colDn = input.color(color.new(color.orange, 86), "", inline ='2')
showCE = input.bool(true, "show CE", inline ='3')
ceCol = input.color(color.new(color.black, 1), "| color:", inline ='3')
ceStyle = input.string(line.style_dotted, "| style:",
options=[line.style_dotted,line.style_solid, line.style_dashed], inline ='3')
deleteFilledBoxes = input.bool(false, "delete filled boxes & lines")
CEcond = input.bool (true, "Use CE (as opposed to Full Fill)", group =
'conditions/alerts', tooltip = "If toggled OFF, FVGs and CEs will paint until FVG
has been completely filled.\n\nThis threshold is used for Above/Below threshold
Alert conditions too (but does not effect the IOFED alerts):\ni.e. this will
determine if your 'ABOVE threshold' alert fires when price hits latest active FVG
CE ABOVE or latest active FVG Full Fill ABOVE\n\nAlerts are set by clicking the
three dots on the indicator display line.")
colorNone = color.new(color.white, 100)
// EMA inputs
ema9Length = input.int(9, "EMA 9 Length")
ema20Length = input.int(20, "EMA 20 Length")
ema50Length = input.int(50, "EMA 50 Length")
// Variables
_day = 24*3600*1000
var box bxUp = na, var box bxDn = na, var line lnUp = na, var line lnDn = na
var array<box> bxUpArr = array.new<box>(0), var array<line> lnUpArr =
array.new<line>(0)
var array<box> bxDnArr = array.new<box>(0), var array<line> lnDnArr =
array.new<line>(0)
dnCE = high[1] + (low[3]-high[1])/2
upCE = low[1] - (low[1]-high[3])/2
if low[3] > high[1] and time> timenow- numDays*_day and showDN
bxDnArr.push(box.new(bar_index-3, low[3], bar_index, high[1], bgcolor = colDn,
border_color = colorNone))
lnDnArr.push(line.new(bar_index-3, dnCE, bar_index, dnCE, color = showCE?
ceCol:colorNone, style =ceStyle))
if high[3] < low[1] and time> timenow- numDays*_day and showUP
bxUpArr.push(box.new(bar_index-3, low[1], bar_index, high[3], bgcolor = colUp,
border_color = colorNone))
lnUpArr.push(line.new(bar_index-3, upCE, bar_index, upCE, color = showCE?
ceCol:colorNone, style =ceStyle))
upThresholdLst = array.sum(_countArr)>array.sum(_countArr)[1]
dnThresholdLst = array.sum(_countArr)<array.sum(_countArr)[1]
upIOFEDlast= array.sum(_countArrIOFED)>array.sum(_countArrIOFED)[1]
dnIOFEDlast= array.sum(_countArrIOFED)<array.sum(_countArrIOFED)[1]
alertcondition(low[3] > high[1], "Simple alert: Down FVG (confirmed)", "Down FVG
has formed (confirmed)")
alertcondition(high[3] < low[1], "Simple alert: Up FVG (confirmed)", "Up FVG has
formed (confirmed)")
alertcondition(low[2] > high, "Simple alert: Down FVG (UN-confirmed)", "Down FVG
has formed (un-confirmed)")
alertcondition(high[2] < low, "Simple alert: Up FVG (UN-confirmed)", "Up FVG has
formed (un-confirmed)")
get_size(x) =>
result = switch x
'Auto' => size.auto
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
get_table_pos(pos) =>
result = switch pos
"Bottom Center" => position.bottom_center
"Bottom Left" => position.bottom_left
"Bottom Right" => position.bottom_right
"Middle Center" => position.middle_center
"Middle Left" => position.middle_left
"Middle Right" => position.middle_right
"Top Center" => position.top_center
"Top Left" => position.top_left
"Top Right" => position.top_right
// ---------------------------------------- Constant Functions
--------------------------------------------------
// ---------------------------------------- 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('America/New_York', "Timezone", options =
['America/New_York','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)
lbl_size = get_size(input.string('Normal', "Label Size", options =
['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], tooltip = "The size of all
labels", 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(true, "Drawing Cutoff Time", inline = "CO",
tooltip = "When enabled, all pivots and open price lines will stop extending at
this time", group = g_SETTINGS)
cutoff = input.session("1200-1201", "", inline = "CO", group =
g_SETTINGS)
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
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
n.h := math.max(high, n.h)
n.l := math.min(low, n.l)
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)
// ---------------------------------------- Variables & Constants
--------------------------------------------------
// ---------------------------------------- Functions
--------------------------------------------------
get_box_color(color c) =>
result = color.new(c, box_transparency)
get_text_color(color c) =>
result = color.new(c, text_transparency)
// ---------------------------------------- Functions
--------------------------------------------------
dwm_open(string tf, bool use, line[] lns, label[] lbls, dwm_info n, color col) =>
if use
if timeframe.change(tf)
lns.unshift(line.new(time, n.o, time, n.o, xloc = xloc.bar_time, style
= htf_style, width = htf_width, color = col))
lbls.unshift(label.new(time, n.o, tf + " OPEN", xloc = xloc.bar_time,
style = label.style_label_left, color = transparent, textcolor = txt_color, size =
lbl_size))
if not sep_unlimited and lns.size() > max_days
lns.pop().delete()
lbls.pop().delete()
else if lns.size() > 0
lns.get(0).set_x2(time)
lbls.get(0).set_x(time)
dwm_hl(string tf, bool use, dwm_hl hl, dwm_info n, color col) =>
if use
if timeframe.change(tf)
hl.hi_line.unshift(line.new(time, n.ph, time, n.ph, xloc =
xloc.bar_time, style = htf_style, width = htf_width, color = col))
hl.lo_line.unshift(line.new(time, n.pl, time, n.pl, xloc =
xloc.bar_time, style = htf_style, width = htf_width, color = col))
hl.hi_label.unshift(label.new(time, n.ph, "P"+tf+"H", xloc =
xloc.bar_time, style = label.style_label_left, color = transparent, textcolor =
txt_color, size = lbl_size))
hl.lo_label.unshift(label.new(time, n.pl, "P"+tf+"L", xloc =
xloc.bar_time, style = label.style_label_left, color = transparent, textcolor =
txt_color, size = lbl_size))
if not sep_unlimited and hl.hi_line.size() > max_days
hl.hi_line.pop().delete()
hl.lo_line.pop().delete()
hl.hi_label.pop().delete()
hl.lo_label.pop().delete()
else 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)
dwm() =>
if timeframe.in_seconds("") <= timeframe.in_seconds(tf_limit)
// DWM - Separators
dwm_sep("D", ds, d_sep_line, d_color)
dwm_sep("W", ws, w_sep_line, w_color)
dwm_sep("M", ms, m_sep_line, m_color)
hz_lines() =>
if timeframe.in_seconds("") <= timeframe.in_seconds(tf_limit)
hz_line(use_h1, t_h1, hz_1, h1_text, h1_color)
hz_line(use_h2, t_h2, hz_2, h2_text, h2_color)
hz_line(use_h3, t_h3, hz_3, h3_text, h3_color)
hz_line(use_h4, t_h4, hz_4, h4_text, h4_color)
del_kz(kz k) =>
if k._box.size() > max_days
k._box.pop().delete()
if k._hi_line.size() > max_days
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()
if k._hi_label.size() > max_days
k._hi_label.pop().delete()
k._lo_label.pop().delete()
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 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) =>
if timeframe.in_seconds("") <= timeframe.in_seconds(tf_limit) and use
if t and not t[1]
_c = get_box_color(c)
_t = get_text_color(c)
kz._box.unshift(box.new(time, high, time, low, xloc = xloc.bar_time,
border_color = show_kz ? _c : na, bgcolor = show_kz ? _c : na, text = (show_kz and
show_kz_text) ? box_txt : na, text_color = _t))
if show_pivots
kz._hi_line.unshift(line.new(time, high, time, high, xloc =
xloc.bar_time, style = kzp_style, color = c, width = kzp_width))
kz._lo_line.unshift(line.new(time, low, time, low, xloc =
xloc.bar_time, style = kzp_style, color = c, width = kzp_width))
if show_midpoints
kz._md_line.unshift(line.new(time, math.avg(high, low), time,
math.avg(high, low), xloc = xloc.bar_time, style = kzm_style, color = c, width =
kzm_width))
array.unshift(kz._md_valid, true)
array.unshift(kz._hi_valid, true)
array.unshift(kz._lo_valid, true)
if show_labels
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))
kz._lo_label.unshift(label.new(time, low, lo_txt, xloc =
xloc.bar_time, color = transparent, textcolor = txt_color, style =
label.style_label_up, 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
table.cell(tbl, 0, row, txt, text_size = range_size, bgcolor =
get_box_color(col), text_color = txt_color)
table.cell(tbl, 1, row, str.tostring(kz._range_current), text_size =
range_size, bgcolor = t ? get_box_color(col) : na, text_color = txt_color)
if show_range_avg
table.cell(tbl, 2, row, str.tostring(kz._range_store.avg()), text_size
= range_size, text_color = txt_color)