GodSlayer Price Action Toolkit v1.6.3
GodSlayer Price Action Toolkit v1.6.3
GodSlayer Price Action Toolkit v1.6.3
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// GodSlayer
//@version=5
indicator("[v1.6.3] Price Action Toolkit", "[v1.6.3] Price Action Toolkit "
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)
max_bars_back = 500
max_labels_count = 500
max_lines_count = 500
//-----------------------------------------------------------------------------{
//Boolean set
//-----------------------------------------------------------------------------{
s_BOS = 0
s_CHoCH = 1
i_BOS = 2
i_CHoCH = 3
i_pp_CHoCH = 4
green_candle = 5
red_candle = 6
s_CHoCHP = 7
i_CHoCHP = 8
boolean =
array.from(
false
, false
, false
, false
, false
, false
, false
, false
, false
)
//-----------------------------------------------------------------------------{
// User inputs
//-----------------------------------------------------------------------------{
t = color.t (ob_bull_css)
invcol = color.new (color.white
, 100)
type bar
float o = open
float c = close
float h = high
float l = low
float v = volume
int n = bar_index
int t = time
type Zphl
line top
line bottom
label top_label
label bottom_label
bool stopcross
bool sbottomcross
bool itopcross
bool ibottomcross
string txtup
string txtdn
float topy
float bottomy
float topx
float bottomx
float tup
float tdn
int tupx
int tdnx
float itopy
float itopx
float ibottomy
float ibottomx
float uV
float dV
type FVG
box [] box
line[] ln
bool bull
float top
float btm
int left
int right
type ms
float[] p
int [] n
float[] l
type msDraw
int n
float p
color css
string txt
bool bull
type obC
float[] top
float[] btm
int [] left
float[] avg
float[] dV
float[] cV
int [] wM
int [] blVP
int [] brVP
int [] dir
float[] h
float[] l
int [] n
type obD
box [] ob
box [] eOB
box [] blB
box [] brB
line[] mL
type zone
chart.point points
float p
int c
int t
type hqlzone
box pbx
box ebx
box lbx
label plb
label elb
label lbl
type ehl
float pt
int t
float pb
int b
type pattern
string found = "None"
bool isfound = false
int period = 0
bool bull = false
type alerts
bool chochswing = false
bool chochplusswing = false
bool swingbos = false
bool chochplus = false
bool choch = false
bool bos = false
bool equal = false
bool ob = false
bool swingob = false
bool zone = false
bool fvg = false
bool obtouch = false
bar b = bar.new()
var pattern p = pattern.new()
if p.isfound
p.period += 1
if p.period == 50
p.period := 0
p.found := "None"
p.isfound := false
p.bull := na
switch
if ms_mode == "Dynamic"
switch
lstyle(style) =>
hy = ta.valuewhen(h != h[1] , h , 1)
hx = ta.valuewhen(h == high , time , 1)
ly = ta.valuewhen(l != l[1] , l , 1)
lx = ta.valuewhen(l == low , time , 1)
if barstate.islast
line.set_xy1(hl , hx , hy)
line.set_xy2(hl , extension , hy)
label.set_xy(hlb, extension , hy)
line.set_xy1(ll , lx , ly)
line.set_xy2(ll , extension , ly)
label.set_xy(lbl, extension , ly)
if lvl_daily
if lvl_weekly
if lvl_monthly
mtfphl(pmh , pml, 'M' , css_m, s_m)
if lvl_yearly
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Market Structure
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
var line id = na
var label lbl = na
id := line.new(
d.n
, d.p
, b.n
, d.p
, color = d.css
, width = 1
, style = style
)
msline.push(id)
lbl := label.new(
int(math.avg(d.n, b.n))
, d.p
, d.txt
, color = invcol
, textcolor = d.css
, style = d.bull ? label.style_label_down : label.style_label_up
, size = size
)
msDraw drw = na
n = bar_index
var ms up = ms.new(
array.new<float>()
, array.new< int >()
, array.new<float>()
)
var ms dn = ms.new(
array.new<float>()
, array.new< int >()
, array.new<float>()
)
switch show_internal_ms
switch
iH =>
up.p.unshift(b.h[iLen])
up.l.unshift(b.h[iLen])
up.n.unshift(n [iLen])
iL =>
dn.p.unshift(b.l[iLen])
dn.l.unshift(b.l[iLen])
dn.n.unshift(n [iLen])
sL =>
sdn.p.unshift(b.l[sLen])
sdn.l.unshift(b.l[sLen])
sdn.n.unshift(n [sLen])
sH =>
sup.p.unshift(b.h[sLen])
sup.l.unshift(b.h[sLen])
sup.n.unshift(n [sLen])
if ta.crossover(b.c, up.p.first())
bool CHoCH = na
string txt = na
if itrend < 0
CHoCH := true
switch
txt := "BOS"
css := i_ms_up_BOS
blalert.bos := true
isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, i_ms_up_BOS
, txt
, true
)
CHoCH =>
isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, i_ms_up_BOS.darkcss(0.25, true)
, txt
, true
)
if mtf == false
switch
if ta.crossunder(b.c, dn.p.first())
bool CHoCH = na
string txt = na
if itrend > 0
CHoCH := true
switch
bralert.bos := true
txt := "BOS"
css := i_ms_dn_BOS
isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, i_ms_dn_BOS
, txt
, false
)
CHoCH =>
isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, i_ms_dn_BOS.darkcss(0.25, false)
, txt
, false
)
if mtf == false
switch
itrend := -1
dn.n.clear()
dn.p.clear()
if ta.crossover(b.c, sup.p.first())
bool CHoCH = na
string txt = na
if trend < 0
CHoCH := true
switch
blalert.swingbos := true
txt := "BOS"
icss := s_ms_up_BOS
isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, s_ms_up_BOS
, txt
, true
)
CHoCH =>
isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, s_ms_up_BOS.darkcss(0.25, true)
, txt
, true
)
if mtf == false
switch
trend := 1
sup.n.clear()
sup.p.clear()
if ta.crossunder(b.c, sdn.p.first())
bool CHoCH = na
string txt = na
if trend > 0
CHoCH := true
switch
bralert.swingbos := true
txt := "BOS"
icss := s_ms_dn_BOS
isdrwS := true
drw := msDraw.new(
sdn.n.first()
, sdn.p.first()
, s_ms_dn_BOS
, txt
, false
)
CHoCH =>
isdrwS := true
drw := msDraw.new(
sdn.n.first()
, sdn.p.first()
, s_ms_dn_BOS.darkcss(0.25, false)
, txt
, false
)
if mtf == false
switch
trend := -1
sdn.n.clear()
sdn.p.clear()
[css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss,
isdrwS]
[css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss,
isdrwS] = structure(false)
if isdrw
f_line(drw, size.small, line.style_dashed)
if isdrwS
f_line(drw, size.small, line.style_solid)
// ADX Function
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
p_css = css
b_css = css
w_css = css
// Multi-Timeframe Analysis
[_, _, _, itrend5, _, _, _, _, _, _, _] = request.security("", "5" ,
structure(true))
[_, _, _, itrend15, _, _, _, _, _, _, _] = request.security("", "15" ,
structure(true))
[_, _, _, itrend30, _, _, _, _, _, _, _] = request.security("", "30" ,
structure(true))
[_, _, _, itrend1H, _, _, _, _, _, _, _] = request.security("", "60" ,
structure(true))
[_, _, _, itrend4H, _, _, _, _, _, _, _] = request.security("", "240" ,
structure(true))
[_, _, _, itrend1D, _, _, _, _, _, _, _] = request.security("", "1440" ,
structure(true))
[_, _, _, itrend1W, _, _, _, _, _, _, _] = request.security("", "1W" ,
structure(true))
// Table headers
if show_itrend5 and show_mtf_str
table.cell(tab, 0, 1, text = show_itrend5 ? "5m" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend15 and show_mtf_str
table.cell(tab, 0, 2, text = show_itrend15 ? "15m" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend30 and show_mtf_str
table.cell(tab, 0, 3, text = show_itrend30 ? "30m" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend1H and show_mtf_str
table.cell(tab, 0, 4, text = show_itrend1H ? "1H" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend4H and show_mtf_str
table.cell(tab, 0, 5, text = show_itrend4H ? "4H" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend1D and show_mtf_str
table.cell(tab, 0, 6, text = show_itrend1D ? "1D" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend1W and show_mtf_str
table.cell(tab, 0, 7, text = show_itrend1W ? "1W" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_rsi and show_mtf_str
table.cell(tab, 0, 8, text = show_rsi ? "RSI" : "", text_color = color.yellow,
text_halign = text.align_center, text_size = size.normal, bgcolor = chart.bg_color,
text_font_family = font.family_monospace, width = 4)
zhl(len)=>
upper = ta.highest(len)
lower = ta.lowest(len)
[top, btm]
upphl(trend) =>
if top
phl.stopcross := true
phl.txtup := top > phl.topy ? "HH" : "HL"
if show_lbl
topl = label.new(
b.n - swing_r_lookback
, top
, phl.txtup
, color = invcol
, textcolor = toplvl
, style = label.style_label_down
, size = size.small
)
line.delete(phl.top[1])
phl.top := line.new(
b.n - sLen
, top
, b.n
, top
, color = toplvl)
phl.topy := top
phl.topx := b.n - sLen
phl.tup := top
phl.tupx := b.n - sLen
if itop
phl.itopcross := true
phl.itopy := itop
phl.itopx := b.n - iLen
if barstate.islast
line.set_xy1(
phl.top
, phl.tupx
, phl.tup
)
line.set_xy2(
phl.top
, b.n + 50
, phl.tup
)
label.set_x(
lbl
, b.n + 50
)
label.set_y(
lbl
, phl.tup
)
dnphl(trend) =>
if btm
phl.sbottomcross := true
phl.txtdn := btm > phl.bottomy ? "LH" : "LL"
if show_lbl
btml = label.new(
b.n - swing_r_lookback
, btm, phl.txtdn
, color = invcol
, textcolor = btmlvl
, style = label.style_label_up
, size = size.small
)
line.delete(phl.bottom[1])
phl.bottom := line.new(
b.n - sLen
, btm
, b.n
, btm
, color = btmlvl
)
phl.bottomy := btm
phl.bottomx := b.n - sLen
phl.tdn := btm
phl.tdnx := b.n - sLen
if ibtm
phl.ibottomcross := true
phl.ibottomy := ibtm
phl.ibottomx := b.n - iLen
if barstate.islast
line.set_xy1(
phl.bottom
, phl.tdnx
, phl.tdn
)
line.set_xy2(
phl.bottom
, b.n + 50
, phl.tdn
)
label.set_x(
lbl
, b.n + 50
)
label.set_y(
lbl
, phl.tdn
)
midphl() =>
if barstate.islast
hqlzone() =>
if barstate.islast
dZone.pbx.set_lefttop(int(math.max(phl.topx, phl.bottomx))
, phl.tup)
dZone.pbx.set_rightbottom(b.n + 50 , 0.95 * phl.tup
+ 0.05 * phl.tdn)
if show_mtb
upphl (trend)
dnphl (trend)
hqlzone()
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Volumetric Order Block
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
method eB(box[] b, bool ext, color css, bool swing, ob_tf) =>
b.unshift(
box.new(
na
, na
, na
, na
, xloc = xloc.bar_time
, extend = ext ? extend.right : extend.none
, border_color = swing ? color.new(css, 0) :
color.new(color.white,100)
, bgcolor = css
, border_width = 1
)
)
method eL(line[] l, bool ext, bool solid, color css, ob_tf) =>
l.unshift(
line.new(
na
, na
, na
, na
, width = 1
, color = css
, xloc = xloc.bar_time
, extend = ext ? extend.right : extend.none
, style = solid ? line.style_solid : line.style_dashed
)
)
method drawVOB(bool cdn, bool bull, color css, int loc, bool swing) =>
, [
close
, open
, high
, low
, volume
, lookahead = barmerge.lookahead_off
)
var obC obj = obC.new(
array.new<float>()
, array.new<float>()
, array.new< int >()
, array.new<float>()
, array.new<float>()
, array.new<float>()
, array.new< int >()
, array.new< int >()
, array.new< int >()
, array.new< int >()
, array.new<float>()
, array.new<float>()
, array.new< int >()
)
if barstate.isfirst
var table errorBox = table.new(position.bottom_right, 1, 1, bgcolor =
color.new(#363a45, 100))
table.cell(errorBox, 0, 0, "© God Slayer", text_color = color.gray,
text_halign = text.align_center, text_size = size.normal)
// Calculate 'pos' based on 'ob_pos' and the corresponding data from the 'ob_tf'
timeframe
float pos = na
if ob_pos == "Full"
pos := bull ? high_tf : low_tf
else if ob_pos == "Middle"
pos := ohlc4_tf
else if ob_pos == "Accurate"
pos := hl2_tf
else
pos := hl2_tf
if cdn
obj.h.clear()
obj.l.clear()
obj.n.clear()
obj.h.push(hH[i])
obj.l.push(lL[i])
obj.n.push(b.t[i])
// obj.h.reverse()
// obj.l.reverse()
int iU = obj.l.indexof(obj.l.min()) + 1
int iD = obj.h.indexof(obj.h.max()) + 1
obj.dir.unshift(
bull
? (b.c[iU] > b.o[iU] ? 1 : -1)
: (b.c[iD] > b.o[iD] ? 1 : -1)
)
obj.top.unshift(
bull
? pos[iU]
: obj.h.max()
)
obj.btm.unshift(
bull
? obj.l.min()
: pos[iD]
)
obj.left.unshift(
bull
? obj.n.get(obj.l.indexof(obj.l.min()))
: obj.n.get(obj.h.indexof(obj.h.max()))
)
obj.avg.unshift(
math.avg(obj.top.first(), obj.btm.first())
)
obj.cV.unshift(
bull
? b.v[iU]
: b.v[iD]
)
if ob_pos == "Precise"
switch bull
true =>
if obj.avg.get(0) < (b.c[iU] < b.o[iU] ? b.c[iU] : b.o[iU]) and
obj.top.get(0) > hlcc4[iU]
obj.top.set(0, obj.avg.get(0))
obj.avg.set(0, math.avg(obj.top.first(), obj.btm.first()))
false =>
if obj.avg.get(0) > (b.c[iU] < b.o[iU] ? b.o[iD] : b.c[iD]) and
obj.btm.get(0) < hlcc4[iD]
obj.btm.set(0, obj.avg.get(0))
obj.avg.set(0, math.avg(obj.top.first(), obj.btm.first()))
obj.blVP.unshift ( 0 )
obj.brVP.unshift ( 0 )
obj.wM .unshift ( 1 )
if use_overlap
if obj.avg.size() > 1
if bull
if barstate.isconfirmed
for x = 0 to ob_num - 1
tg = switch ob_mitigation
"Middle" => obj.avg
"Absolute" => bull ? obj.btm : obj.top
if barstate.islast
if obj.avg.size() > 0
// Alert
if bull
? ta.crossunder(low , obj.top.get(0))
: ta.crossover (high, obj.btm.get(0))
switch bull
true => blalert.obtouch := true
false => bralert.obtouch := true
float tV = 0
obj.dV.clear()
seq = math.min(ob_num - 1, obj.avg.size() - 1)
for j = 0 to seq
tV += obj.cV.get(j)
if j == seq
for y = 0 to seq
obj.dV.unshift(
math.floor(
(obj.cV.get(y) / tV) * 100)
)
obj.dV.reverse()
if use_middle_line
dmL.set_xy1(obj.left.get(i), obj.avg.get(i))
dmL.set_xy2(b.t , obj.avg.get(i))
if ob_metrics_show
rpBL = dblB.get_right()
rpBR = dbrB.get_right()
dbrB.set_right(rpBR + (b.t - b.t[1]) * obj.brVP.get(i))
dblB.set_right(rpBL + (b.t - b.t[1]) * obj.blVP.get(i))
if use_show_metric
txt = switch
deOB.set_text(
str.tostring(
txt + " (" + str.tostring(obj.dV.get(i)) + "%)")
)
deOB.set_text_size (obtxt.txSz())
deOB.set_text_halign(text.align_left)
deOB.set_text_color (use_grayscale ? color.silver :
color.new(css, 0))
if obj.wM.size() > 0
for i = 0 to obj.avg.size() - 1
switch obj.dir.get(i)
1 =>
switch obj.wM.get(i)
if iH
hN.pop()
hN.unshift(int(b.n[iLen]))
if iL
lN.pop()
lN.unshift(int(b.n[iLen]))
if sH
hS.pop()
hS.unshift(int(b.n[sLen]))
if sL
lS.pop()
lS.unshift(int(b.n[sLen]))
if ob_show
if bull_ob
blalert.ob := true
if bear_ob
bralert.ob := true
if s_bull_ob
blalert.swingob := true
if s_bear_ob
blalert.swingob := true
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - FVG | VI | OG
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
[h, l, c, o] = ghl()
[go, gh, gl, gc] = tfG()
float pup = na
float pdn = na
bool cdn = na
int pos = 2
cc = timeframe.change(fvg_tf)
if barstate.isfirst
for i = 0 to fvg_num - 1
switch what_fvg
"FVG" =>
pup := bull ? gl : l
pdn := bull ? h : gh
cdn := bull ? gl > h and cc : gh < l and cc
pos := 2
"VI" =>
pup := bull
? (gc > go
? go
: gc)
: (gc[1] > go[1]
? go[1]
: gc[1])
pdn := bull
? (gc[1] > go[1]
? gc[1]
: go[1])
: (gc > go
? gc
: go)
cdn := bull
? go > gc[1] and gh[1] > gl and gc > gc[1] and go > go[1] and
gh[1] < math.min(gc, go) and cc
: go < gc[1] and gl[1] < gh and gc < gc[1] and go < go[1] and
gl[1] > math.max(gc, go) and cc
pos := 1
"OG" =>
cords.unshift(
FVG.new(
na
, na
, bull
? true
: false
, pup
, pdn
, b.t - (b.t - b.t[1]) * pos
, b.t + (b.t - b.t[1]) * fvg_extend)
)
if bull
blalert.fvg := true
else
bralert.fvg := true
if barstate.isconfirmed
cords.remove(idx)
if barstate.islast
if cords.size() > 0
gbx = draw.box.get(i)
gln = draw.ln.get(i)
gcd = cords.get(i)
gtop = gcd.top
gbtm = gcd.btm
left = gcd.left
right = gcd.right
gbx.set_lefttop(left, gtop)
gbx.set_rightbottom(right, gbtm)
gbx.set_bgcolor(gcd.bull ? fvg_upcss : fvg_dncss)
if fvg_enable
cG(true )
cG(false)
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Accumulation And Distribution
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
if iH
z.unshift(
zone.new(
chart.point.from_time(
time[len]
, high [len]
)
, high [len]
, 1
, time[len]
)
)
if iL
z.unshift(
zone.new(
chart.point.from_time(
time[len]
, low [len]
)
, low [len]
, -1
, time[len]
)
)
if z.size() > 1
if z.get(0).c == z.get(1).c
z.clear()
switch
if z.size() > 5
blalert.zone := true
for i = 0 to 5
slice.unshift(z.get(i).points)
if z.size() > 5
bralert.zone := true
for i = 0 to 5
slice.unshift(z.get(i).points)
if z.size() > 3
blalert.zone := true
for i = 0 to 3
slice.unshift(z.get(i).points)
if z.size() > 3
bralert.zone := true
for i = 0 to 3
slice.unshift(z.get(i).points)
if show_acc_dist_zone
drawZone(iLen)
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - EQH / EQL
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
dEHL() =>
switch
top =>
mx = math.max(top, w.pt)
mn = math.min(top, w.pt)
switch
var aZ = array.new<line>()
var aL = array.new<label>()
if aZ.size() > 50
aZ.pop().delete()
aL.pop().delete()
bralert.equal := true
w.pt := top
w.t := b.n - 1
btm =>
mx = math.max(btm, w.pb)
mn = math.min(btm, w.pb)
switch
var aZ = array.new<line>()
var aL = array.new<label>()
if aZ.size() > 50
aZ.pop().delete()
aL.pop().delete()
blalert.equal := true
w.pb := btm
w.b := b.n - 1
if show_eql
dEHL()
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
BBGroup = "Breaker Blocks"
shZZ = false
len = input.int ( 5 ,
title=' Length' , inline='MS' , group=BBGroup
, minval=1, maxval=10
)
//VOLUMETRIC ORDER BLOCKS
BreakerCandleOnlyBody = input.bool ( false , title='Use only candle body'
, group=BBGroup )
BreakerCandle_2Last = input.bool ( false , title='Use 2 candles instead of 1'
, group=BBGroup, tooltip='In the same direction')
tillFirstBreak = input.bool ( true , title='Stop at first break of
center line' , group=BBGroup )
tpCss = #2157f3
//PD array
showBreaks = false
showSPD = true
PDtxtCss = color.silver
PDSCss = color.silver
Breaker = input.bool ( false , title='Hide Breaker Blocks' ,
group=BBGroup )
//Colors
cBBplusA = input.color (color.rgb(12, 181, 26, 93)
,
title=' ' , inline='bl' , group='Colours
+BB Last Swings' )
cBBplusB = input.color (color.rgb(12, 181, 26, 85)
,
title='' , inline='bl' , group='Colours
+BB Last Swings' )
cSwingBl = input.color (color.rgb(255, 82, 82, 85)
,
title=' ' , inline='bl' , group='Colours
+BB Last Swings' )
cBB_minA = input.color (color.rgb(255, 17, 0, 95)
,
title=' ' , inline='br' , group='Colours -
BB Last Swings' )
cBB_minB = input.color (color.rgb(255, 17, 0, 85)
,
title='' , inline='br' , group='Colours -
BB Last Swings' )
cSwingBr = input.color (color.rgb(0, 137, 123, 85)
,
title=' ' , inline='br' , group='Colours -
BB Last Swings' )
_arrowup = '▲'
_arrowdn = '▼'
_c = '●'
_x = '❌'
//-----------------------------------------------------------------------------}
//General Calculations
//-----------------------------------------------------------------------------{
per = last_bar_index - bar_index <= 2000
mx = math.max(close , open )
mn = math.min(close , open )
n = bar_index
hi = high
lo = low
mCxSize = 50
//-----------------------------------------------------------------------------}
//User Defined Types
//-----------------------------------------------------------------------------{
type ZZ
int [] d
int [] x
float [] y
line [] l
bool [] b
type mss
int dir
line [] l_mssBl
line [] l_mssBr
line [] l_bosBl
line [] l_bosBr
label[] lbMssBl
label[] lbMssBr
label[] lbBosBl
label[] lbBosBr
type block
int dir
bool Broken
bool Mitigated
box BB_boxA
box BB_boxB
line BB_line
box FVG_box
line line_1
line line_2
bool Broken_1
bool Broken_2
box PDa_boxA
box PDa_boxB
box PDa_box1
line PDaLine1
label PDaLab_1
box PDa_box2
line PDaLine2
label PDaLab_2
bool PDbroken1
bool PDbroken2
line TP1_line
line TP2_line
line TP3_line
bool TP1_hit
bool TP2_hit
bool TP3_hit
bool scalp
label HL
label[] aLabels
//-----------------------------------------------------------------------------}
//Variables
//-----------------------------------------------------------------------------{
BBplus = 0, signUP = 1, cnclUP = 2, LL1break = 3, LL2break = 4, SW1breakUP = 5
, SW2breakUP = 6, tpUP1 = 7, tpUP2 = 8, tpUP3 = 9, BB_endBl =10
BB_min =11, signDN =12, cnclDN =13, HH1break =14, HH2break =15, SW1breakDN =16
, SW2breakDN =17, tpDN1 =18, tpDN2 =19, tpDN3 =20, BB_endBr =21
signals =
array.from(
false // BBplus
, false // signUP
, false // cnclUP
, false // LL1break
, false // LL2break
, false // SW1breakUP
, false // SW2breakUP
, false // tpUP1
, false // tpUP2
, false // tpUP3
, false // BB_endBl
, false // BB_min
, false // signDN
, false // cnclDN
, false // HH1break
, false // HH2break
, false // SW1breakDN
, false // SW2breakDN
, false // tpDN1
, false // tpDN2
, false // tpDN3
, false // BB_endBr
)
var ZZ aZZ =
ZZ.new(
array.new < int >(mCxSize, 0),
array.new < int >(mCxSize, 0),
array.new < float >(mCxSize, na),
array.new < line >(mCxSize, na),
array.new < bool >(mCxSize, na))
//-----------------------------------------------------------------------------}
//Functions/methods
//-----------------------------------------------------------------------------{
method in_out(ZZ aZZ, int d, int x1, float y1, int x2, float y2, color col, bool b)
=>
aZZ.d.unshift(d), aZZ.x.unshift(x2), aZZ.y.unshift(y2), aZZ.b.unshift(b),
aZZ.d.pop(), aZZ.x.pop(), aZZ.y.pop(), aZZ.b.pop()
if shZZ
aZZ.l.unshift(line.new(x1, y1, x2, y2, color= col)), aZZ.l.pop().delete()
method setLine(line ln, int x1, float y1, int x2, float y2) => ln.set_xy1(x1, y1),
ln.set_xy2(x2, y2)
max_bars_back(time, 1000)
var int dir= na, var int x1= na, var float y1= na, var int x2= na, var float
y2= na
sz = aZZ.d.size( )
x2 := bar_index -1
ph = ta.pivothigh(hi, left, 1)
pl = ta.pivotlow (lo, left, 1)
if ph
dir := aZZ.d.get (0)
x1 := aZZ.x.get (0)
y1 := aZZ.y.get (0)
y2 := nz(hi[1])
if dir < 1 // if previous point was a pl, add, and change direction ( 1)
aZZ.in_out( 1, x1, y1, x2, y2, col, true)
else
if dir == 1 and ph > y1
aZZ.x.set(0, x2), aZZ.y.set(0, y2)
if shZZ
aZZ.l.get(0).set_xy2(x2, y2)
if pl
dir := aZZ.d.get (0)
x1 := aZZ.x.get (0)
y1 := aZZ.y.get (0)
y2 := nz(lo[1])
if dir > -1 // if previous point was a ph, add, and change direction (-1)
aZZ.in_out(-1, x1, y1, x2, y2, col, true)
else
if dir == -1 and pl < y1
aZZ.x.set(0, x2), aZZ.y.set(0, y2)
if shZZ
aZZ.l.get(0).set_xy2(x2, y2)
iH = aZZ.d.get(2) == 1 ? 2 : 1
iL = aZZ.d.get(2) == -1 ? 2 : 1
switch
// MSS Bullish
close > aZZ.y.get(iH) and aZZ.d.get(iH) == 1 and MSS.dir < 1 and per =>
float green1prT = na
float green1prB = na
float avg = na
green1idx = n - i
green1prT := BreakerCandleOnlyBody ? mx[i] : high[i]
green1prB := BreakerCandleOnlyBody ? mn[i] : low [i]
if BreakerCandle_2Last
if close[i +1] > open[i +1]
green2prT = BreakerCandleOnlyBody ? mx[i +1] :
high[i +1]
green2prB = BreakerCandleOnlyBody ? mn[i +1] : low
[i +1]
if green2prT > green1prT or green2prB < green1prB
green1idx -= 1
green1prT := math.max(green1prT, green2prT)
green1prB := math.min(green1prB, green2prB)
BB.BB_boxB.set_left ( n )
BB.BB_boxB.set_top (green1prT)
BB.BB_boxB.set_right ( n + 8)
BB.BB_boxB.set_bottom (green1prB)
BB.BB_boxB.set_bgcolor(cBBplusB )
BB.BB_boxB.set_text('+BB')
BB.BB_boxB.set_text_color(cBBplusB.notransp())
BB.BB_boxB.set_text_valign(text.align_bottom)
// Previous swings
cnt = 0, hh1 = high
for c = 0 to sz -2
getX = aZZ.x.get(c)
getY = aZZ.y.get(c)
if getY > hh1 and aZZ.d.get(c) == 1 and showSPD
getY2 = (high[n - getX] - mn[n - getX]) / 4
break
signals.set(BBplus, true)
alert('+BB', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, cBBplusB.notransp(),
_arrowup, size.large))
break
MSS.dir := 1
// MSS Bearish
close < aZZ.y.get(iL) and aZZ.d.get(iL) == -1 and MSS.dir > -1 and per =>
Ex = aZZ.x.get(iL -1), Ey = aZZ.y.get(iL -1)
Dx = aZZ.x.get(iL ), Dy = aZZ.y.get(iL ), DyMn = mn[n - Dx]
Cx = aZZ.x.get(iL +1), Cy = aZZ.y.get(iL +1)
Bx = aZZ.x.get(iL +2), By = aZZ.y.get(iL +2), ByMn = mn[n - Bx]
Ax = aZZ.x.get(iL +3), Ay = aZZ.y.get(iL +3), AyMx = mx[n - Ax]
_y = math.min(ByMn, DyMn)
//_x = _y == ByMn ? Bx : Dx
mid = AyMx - ((AyMx - _y) / 2) // 50% fib A- min(B, D)
isOK = Breaker ? Ay > Cy and Ay > Ey and Ey > mid : true
//
float red_1_prT = na
float red_1_prB = na
float avg = na
if Ey > Cy and Cx != Dx and isOK
// latest LL to LL further -> search first red bar
for i = n - Dx to n - Cx
if close[i] < open[i]
// reset previous swing box's
BB.PDa_box1.set_lefttop(na, na), BB.PDaLine1.set_xy1(na,
na), BB.PDaLab_1.set_xy(na, na)
BB.PDa_box2.set_lefttop(na, na), BB.PDaLine2.set_xy1(na,
na), BB.PDaLab_2.set_xy(na, na)
red_1_idx = n - i
red_1_prT := BreakerCandleOnlyBody ? mx[i] : high[i]
red_1_prB := BreakerCandleOnlyBody ? mn[i] : low [i]
if BreakerCandle_2Last
if close[i +1] < open[i +1]
red_2_prT = BreakerCandleOnlyBody ? mx[i +1] :
high[i +1]
red_2_prB = BreakerCandleOnlyBody ? mn[i +1] : low
[i +1]
if red_2_prT > red_1_prT or red_2_prB < red_1_prB
red_1_idx -= 1
red_1_prT := math.max(red_1_prT, red_2_prT)
red_1_prB := math.min(red_1_prB, red_2_prB)
BB.BB_boxB.set_left (n)
BB.BB_boxB.set_top (red_1_prT)
BB.BB_boxB.set_right ( n + 8)
BB.BB_boxB.set_bottom (red_1_prB)
BB.BB_boxB.set_bgcolor(cBB_minB )
BB.BB_boxB.set_text('-BB')
BB.BB_boxB.set_text_color(cBB_minB.notransp())
BB.BB_boxB.set_text_valign(text.align_top)
// Previous swings
cnt = 0, ll1 = low
for c = 0 to sz -2
getX = aZZ.x.get(c)
getY = aZZ.y.get(c)
if getY < ll1 and aZZ.d.get(c) == -1 and showSPD
getY2 = (mx[n - getX] - low[n - getX]) / 4
break
signals.set(BB_min, true)
alert('-BB', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high,
cBB_minB.notransp(), _arrowdn, size.large))
break
MSS.dir := -1
if barstate.isfirst
var table errorBox = table.new(position.bottom_right, 1, 1, bgcolor =
color.new(#363a45, 100))
table.cell(errorBox, 0, 0, "© God Slayer", text_color = color.gray,
text_halign = text.align_center, text_size = size.normal)
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
draw(len, tpCss)
lft = BB.BB_boxB.get_left ()
avg = BB.BB_line.get_y2 ()
l_1 = BB.line_1.get_y2 ()
l_2 = BB.line_2.get_y2 ()
TP1 = BB.TP1_line.get_y2 ()
TP2 = BB.TP2_line.get_y2 ()
TP3 = BB.TP3_line.get_y2 ()
switch BB.dir
1 =>
if not BB.Mitigated
if close < btm
BB.Mitigated := true
signals.set(BB_endBl, true)
alert('+BB Mitigated', alert.freq_once_per_bar_close)
BB.TP1_line.set_x2 (n)
BB.TP2_line.set_x2 (n)
BB.TP3_line.set_x2 (n)
if n > BB.BB_boxB.get_left()
if not BB.Broken
if BB.scalp
if not BB.TP1_hit and open < TP1 and high > TP1
BB.TP1_hit := true
signals.set(tpUP1, true)
alert('TP UP 1', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP1, #ff00dd, _c))
if not BB.TP2_hit and open < TP2 and high > TP2
BB.TP2_hit := true
signals.set(tpUP2, true)
alert('TP UP 2', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP2, #ff00dd, _c))
if not BB.TP3_hit and open < TP3 and high > TP3
BB.TP3_hit := true
signals.set(tpUP3, true)
alert('TP UP 3', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP3, #ff00dd, _c))
switch
open > avg and open < top and close > top =>
BB.TP1_hit := false
BB.TP2_hit := false
BB.TP3_hit := false
BB.scalp := true
signals.set(signUP, true)
alert('signal UP', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, color.lime,
_arrowup, size.normal))
close < avg and close > btm =>
BB.Broken := true
BB.scalp := false
signals.set(cnclUP, true)
alert('cancel UP', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, color.orange,
_x))
else
// reset
if not tillFirstBreak and close > top
BB.Broken := false
BB.scalp := true
signals.set(BBplus, true)
alert('+BB (R)', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, color.blue, 'R',
size.normal))
if not BB.Broken_1
BB.line_1.set_x2(n)
if close < l_1
BB.Broken_1 := true
signals.set(LL1break, true)
alert('LL 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))
if not BB.Broken_2
BB.line_2.set_x2(n)
if close < l_2
BB.Broken_2 := true
signals.set(LL2break, true)
alert('LL 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))
if not BB.PDbroken1
BB.PDa_box1.set_right(n)
BB.PDaLine1.set_x2 (n)
if close > BB.PDa_box1.get_top() and n > BB.PDa_box1.get_left()
BB.PDbroken1 := true
signals.set(SW1breakUP, true)
alert('Swing UP 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))
if not BB.PDbroken2
BB.PDa_box2.set_right(n)
BB.PDaLine2.set_x2 (n)
if close > BB.PDa_box2.get_top() and n > BB.PDa_box2.get_left()
BB.PDbroken2 := true
signals.set(SW2breakUP, true)
alert('Swing UP 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))
-1 =>
if not BB.Mitigated
if close > top
BB.Mitigated := true
signals.set(BB_endBr, true)
alert('-BB Mitigated', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('d', high, cBB_minB.notransp(),
_c))
BB.BB_boxB.set_right(n)
BB.BB_line.set_x2 (n)
else
BB.BB_boxB.set_right(n + 8)
BB.BB_line.set_x2 (n + 8)
BB.TP1_line.set_x2 (n)
BB.TP2_line.set_x2 (n)
BB.TP3_line.set_x2 (n)
if n > BB.BB_boxB.get_left()
if not BB.Broken
if BB.scalp
if not BB.TP1_hit and open > TP1 and low < TP1
BB.TP1_hit := true
signals.set(tpDN1, true)
alert('TP DN 1', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP1, #ff00dd, _c))
if not BB.TP2_hit and open > TP2 and low < TP2
BB.TP2_hit := true
signals.set(tpDN2, true)
alert('TP DN 2', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP2, #ff00dd, _c))
if not BB.TP3_hit and open > TP3 and low < TP3
BB.TP3_hit := true
signals.set(tpDN3, true)
alert('TP DN 3', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP3, #ff00dd, _c))
switch
open < avg and open > btm and close < btm =>
BB.TP1_hit := false
BB.TP2_hit := false
BB.TP3_hit := false
BB.scalp := true
signals.set(signDN, true)
alert('signal DN', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high, color.orange,
_arrowdn, size.normal))
close > avg and close < top =>
BB.Broken := true
BB.scalp := false
signals.set(cnclDN, true)
alert('cancel DN', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high, color.red ,
_x))
else
// reset
if not tillFirstBreak and close < btm
BB.Broken := false
BB.scalp := true
signals.set(BB_min, true)
alert('-BB (R)', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high, color.blue, 'R',
size.normal))
if not BB.Broken_1
BB.line_1.set_x2(n)
if close > l_1
BB.Broken_1 := true
signals.set(HH1break, true)
alert('HH 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))
if not BB.Broken_2
BB.line_2.set_x2(n)
if close > l_2
BB.Broken_2 := true
signals.set(HH2break, true)
alert('HH 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))
if not BB.PDbroken1
BB.PDa_box1.set_right(n)
BB.PDaLine1.set_x2 (n)
if close < BB.PDa_box1.get_bottom() and n > BB.PDa_box1.get_left()
BB.PDbroken1 := true
signals.set(SW1breakDN, true)
alert('Swing DN 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))
if not BB.PDbroken2
BB.PDa_box2.set_right(n)
BB.PDaLine2.set_x2 (n)
if close < BB.PDa_box2.get_bottom() and n > BB.PDa_box2.get_left()
BB.PDbroken2 := true
signals.set(SW2breakDN, true)
alert('Swing DN 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))
//Trendlines
trelen = input.int(5, "Period ", tooltip = "Lookback period", inline = "b", group =
"SETTINGS")
cup = input.color(#089981, "", "")
cdn = input.color(#ff0000, "", "")
space = input.float(2, "Padding", tooltip = "Padding distance", inline = "c", group
= "SETTINGS", step = 0.1)
shs = input.bool(false, "Show Breakouts", inline = "z", group = "SETTINGS")
type store
float src
int n
type draw
line[] upln
line[] dnln
atr = ta.atr(200)
vol() =>
math.min(atr * 0.1, close * (0.1 / 100))
if ph
bool remove = false
var bool valid = false
upbin.unshift(store.new(b.h[trelen], b.n[trelen]))
if upbin.size() > 1
current = upbin.get(0)
before = upbin.get(1)
if current.src < before.src
if broken
valid := true
else
valid := false
if upbin.size() > 3
pastold = upbin.get(3)
pastcur = upbin.get(2)
now = upbin.get(1)
late = upbin.get(0)
if now.src < pastcur.src and now.src < pastold.src and late.src
< pastcur.src and late.src < pastold.src
valid := true
else
valid := false
else
valid := false
if valid
if showTrendlines
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src, y2 = current.src, color = cdn))
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src - vol() * space, y2 = current.src - vol() * space, color = cdn))
ln = d.upln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if low[i] > ln.get_y2()
remove := true
break
if remove
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln.clear()
upbin.clear()
broken := true
else
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln.clear()
if d.upln.size() > 1
btm = d.upln.get(0)
top = d.upln.get(1)
if d.upln.size() > 1
slup = top.slope()
sldn = btm.slope()
top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)
btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)
if pl
bool remove = false
var bool valid = false
dnbin.unshift(store.new(b.l[trelen], b.n[trelen]))
if dnbin.size() > 1
current = dnbin.get(0)
before = dnbin.get(1)
if current.src > before.src
if broken
valid := true
else
valid := false
if dnbin.size() > 3
pastold = dnbin.get(3)
pastcur = dnbin.get(2)
now = dnbin.get(1)
late = dnbin.get(0)
if valid
if showTrendlines
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src, y2 = current.src, color = cup))
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src + vol() * space, y2 = current.src + vol() * space, color = cup))
ln = d.dnln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if high[i] < ln.get_y2()
remove := true
break
if remove
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln.clear()
dnbin.clear()
broken := true
else
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln.clear()
if d.dnln.size() > 1
btm = d.dnln.get(0)
top = d.dnln.get(1)
if d.dnln.size() > 1
slup = top.slope()
sldn = btm.slope()
top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)
btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)
pvhh = ta.pivothigh(pvllen, 0)
pvll = ta.pivotlow(pvllen, 0)
f_get_candle(_index) =>
[open[_index], high[_index], low[_index], close[_index], bar_index[_index]]
f_sfp() =>
[so, sh, sl, sc, si] = f_get_candle(0)
// High SFP
hc1 = pvhh
maxp = high[1]
hc2 = false
hx = 0
hy = 0.0
for i=1 to lookback
[co, ch, cl, cc, ci] = f_get_candle(i)
if ch >= sh
break
if ch < sh and ch > math.max(so, sc) and pvhh[bar_index - ci] and ch > maxp
hc2 := true
hx := bar_index[i]
hy := ch
if ch > maxp
maxp := ch
// Low SFP
lc1 = pvll
minp = low[1]
lc2 = false
lx = 0
ly = 0.0
for i=2 to lookback
[co, ch, cl, cc, ci] = f_get_candle(i)
if cl < sl
break
if sl < cl and math.min(so, sc) > cl and pvll[bar_index - ci] and cl < minp
lc2 := true
lx := bar_index[i]
ly := cl
if cl < minp
minp := cl
//-----------------------------------------------------------------------------}
//Enable/Disable alerts
//-----------------------------------------------------------------------------{
// Swing Bullish
bool s_bull_bos = input.bool(false, "S - Bullish BOS", inline = '6', group =
anyalert)
bool s_bull_choch = input.bool(false, "S - Bullish CHoCH", inline = '4', group =
anyalert)
bool s_bull_chochp = input.bool(false, "S - Bullish CHoCH+", inline = '5', group =
anyalert)
// Internal Bearish
bool i_bear_bos = input.bool(false, "I - Bearish BOS ", inline = '3', group =
anyalert)
bool i_bear_choch = input.bool(false, "I - Bearish CHoCH ", inline = '1', group =
anyalert)
bool i_bear_chochp = input.bool(false, "I - Bearish CHoCH+ ", inline = '2', group
= anyalert)
// Swing Bearish
bool s_bear_bos = input.bool(false, "S - Bearish BOS", inline = '6', group =
anyalert)
bool s_bear_choch = input.bool(false, "S - Bearish CHoCH", inline = '4', group =
anyalert)
bool s_bear_chochp = input.bool(false, "S - Bearish CHoCH+", inline = '5', group =
anyalert)