Professional Documents
Culture Documents
AlgoPoint_PA_Toolkit_V1
AlgoPoint_PA_Toolkit_V1
//@version=5
indicator("AlgoPoint PA Toolkit [V1]", shorttitle = "AlgoPoint PA Toolkit [V1]",
overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count =
500, max_bars_back = 500, max_polylines_count = 100)
//-----------------------------------------------------------------------------{
//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)
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - UDT
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
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
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - General Setup
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
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
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - ARRAYS
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
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
if lvl_yearly
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Market Structure
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
id := line.new(
d.n
, d.p
, b.n
, d.p
, color = d.css
, width = 1
, style = style
)
line.delete(msline.shift())
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
, text_font_family = font.family_monospace
)
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_swing_ms
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
itrend := 1
up.n.clear()
up.p.clear()
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
not CHoCH =>
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)
if show_mtf_str
table.merge_cells(tab, 0, 5, 1, 5)
table.merge_cells(tab, 0, 6, 1, 6)
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Strong/Weak High/Low And Equilibrium
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
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
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
, [
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
for i = 0 to ob_num - 1
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 (size.auto)
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)
switch obj.wM.get(i)
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 ob_swings
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[1]
, pdn[1]
, b.t - (b.t - b.t[1]) * pos + 1
, b.t + (b.t - b.t[1]) * fvg_extend + 1)
)
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
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Plotting And Coloring
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
p_css = css
b_css = css
w_css = css
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
if barstate.isfirst
var table errorBox = table.new(position.bottom_right, 1, 1, bgcolor =
color.new(#363a45, 100))
table.cell(errorBox, 0, 0, "© Stratify", text_color = color.gray,
text_halign = text.align_center, text_size = size.normal)
// # ============================[Liquidity]============================ #
gr_fts = "FEATURES"
liquidity = input(false, "Liquidity", inline = "4", group = gr_fts)
htfTF = input.timeframe("", "", inline = "4", tooltip = "Shows areas of market
liquidity", group = gr_fts)
trendline = input(true, "Trend Lines", inline = "2", group = gr_fts)
trendlilenght = input.int(50, "", inline = "2", step = 1, minval = 2, tooltip =
"Enables automatic drawing of trend lines", group = gr_fts)
// Get Components
mitiOptions = "Remove"
displayStyle_liq = "Boxes"
hh = close
ll = close
timediff=(time[1]-time[101])/100
atr_liq = ta.atr(300)
float thold_liq = atr_liq * (2.5 / 10)
// Functions
tf_multi(tf) =>
ts = timeframe.in_seconds("")
htfs = timeframe.in_seconds(tf)
htfs/ts
display_limit_line(_array) =>
if array.size(_array) > 6/2
a = array.shift(_array)
line.delete(a)
display_limit_box(_array) =>
if array.size(_array) > 6/2
a = array.shift(_array)
box.delete(a)
remove_mitigated_lines(_array, _hl) =>
m = false
if array.size(_array) > 0
for i = array.size(_array) - 1 to 0 by 1
l = array.get(_array, i)
if _hl == "High" and hh > line.get_y1(l)
array.remove(_array, i)
if mitiOptions == "Show"
line.new(line.get_x1(l),line.get_y1(l),time,line.get_y1(l),
xloc=xloc.bar_time, color = color.new(#f23645,50), style=line.style_solid, width =
2)
line.delete(l)
m := true
if _hl == "Low" and ll < line.get_y1(l)
array.remove(_array, i)
if mitiOptions == "Show"
line.new(line.get_x1(l),line.get_y1(l),time,line.get_y1(l),
xloc=xloc.bar_time, color = color.new(#089981,50), style=line.style_solid, width =
2)
line.delete(l)
m := true
display_limit_line(_array)
m
remove_mitigated_boxes(_array, _hl) =>
m = false
if array.size(_array) > 0
for i = array.size(_array) - 1 to 0 by 1
l = array.get(_array, i)
if _hl == "High" and hh > box.get_top(l)
array.remove(_array, i)
if mitiOptions == "Show"
box.new(box.get_left(l),box.get_top(l),time,box.get_bottom(l),
xloc=xloc.bar_time, bgcolor = color.new(#f23645, 90), border_color =
color.new( #f23645, 90), border_style = line.style_solid)
box.delete(l)
m := true
if _hl == "Low" and ll < box.get_top(l)
array.remove(_array, i)
if mitiOptions == "Show"
box.new(box.get_left(l),box.get_top(l),time,box.get_bottom(l),
xloc=xloc.bar_time, bgcolor = color.new(#089981, 90), border_color =
color.new(#089981, 90), border_style = line.style_solid)
box.delete(l)
m := true
display_limit_box(_array)
m
extend_line_to_current(lineArray) =>
if array.size(lineArray) > 0
for i = array.size(lineArray) - 1 to 0 by 1
l = array.get(lineArray, i)
timeExt = timenow + ((timediff)*30)
line.set_x2(l, timeExt)
extend_box_to_current(boxArray) =>
if array.size(boxArray) > 0
for i = array.size(boxArray) - 1 to 0 by 1
b = array.get(boxArray, i)
timeExt = timenow + ((timediff)*30)
box.set_right(b, timeExt)
// ----------------------------------------------------
// Higher TimeFrame
// ----------------------------------------------------
// Varibles
// Lines
var highLineArrayHTF = array.new_line()
var lowLineArrayHTF = array.new_line()
// Boxes
var highBoxArrayHTF = array.new_box()
var lowBoxArrayHTF = array.new_box()
// Get HTF
[_time, _open, _high, _low, _close] = request.security(syminfo.tickerid, htfTF,
[time, open, high, low, close])
// Pivots
pivotHighHTF = ta.pivothigh(_high, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
pivotLowHTF = ta.pivotlow(_low, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
if liquidity
timeExt = time+((time[1]-time[2])*10)
dis = 8+tf_multi(htfTF)
if pivotHighHTF
if displayStyle_liq == "Lines"
array.push(highLineArrayHTF,
line.new(_time[dis],_high[dis],_time[+1],_high[dis],color = color.new(#f23645,50),
style=line.style_solid, xloc=xloc.bar_time, extend=extend.none, width = 2))
else
y1 = _high[dis]-thold_liq//math.max(_open[dis], _close[dis])
array.push(highBoxArrayHTF,
box.new(_time[dis],_high[dis],_time[+1],y1,bgcolor = color.new(#f23645,50) ,
border_color=color.new(#f23645,90), xloc=xloc.bar_time, border_style =
line.style_solid, extend=extend.none, border_width = 2,text="$",text_halign =
text.align_center,text_color = color.white,text_size = size.small))
if pivotLowHTF
if displayStyle_liq == "Lines"
array.push(lowLineArrayHTF,
line.new(_time[dis],_low[dis],_time[+1],_low[dis],color = color.new(#089981,50),
style=line.style_solid, xloc=xloc.bar_time, extend=extend.none, width = 2))
else
y1 = _low[dis]+thold_liq//math.min(_open[dis], _close[dis])
array.push(lowBoxArrayHTF,
box.new(_time[dis],_low[dis],_time[+1],y1,bgcolor = color.new(#089981,50),
border_color=color.new(#089981,90), xloc=xloc.bar_time, border_style =
line.style_solid, extend=extend.none, border_width = 2,text="$",text_halign =
text.align_center,text_color = color.white,text_size = size.small))
// ----------------------------------------------------
// Run Functions
// ----------------------------------------------------
highLineAlertHTF = remove_mitigated_lines(highLineArrayHTF, "High")
lowLineAlertHTF = remove_mitigated_lines(lowLineArrayHTF, "Low")
highBoxAlertHTF = remove_mitigated_boxes(highBoxArrayHTF, "High")
lowBoxAlertHTF = remove_mitigated_boxes(lowBoxArrayHTF, "Low")
extend_line_to_current(highLineArrayHTF)
extend_line_to_current(lowLineArrayHTF)
extend_box_to_current(highBoxArrayHTF)
extend_box_to_current(lowBoxArrayHTF)
// # ============================[Trend Lines]============================ #
//Downtrendline
var int phx1 = na
var float phslope = na
var float phy1 = na
var float upper = na
var float plotH = na
var bool isOnH = false
//Uptrendline
var int plx1 = na
var float plslope = na
var float ply1 = na
var float lower = na
var float plotL = na
var bool isOnL = false
phy1 := ph
phx1 := n - trendlilenght
upper += phslope
plotH := not na(ph) and ta.change(phslope) ? na : srcBl[1] > upper[1] ? na :
upper
bs_H = ta.barssince(na(plotH))
if not na(pl)
if pl > ply1
[normalised_slope, slope, angle] = calculate_slope(plx1, n - trendlilenght,
ply1, pl)
testLine.set_xy1(plx1, ply1), testLine.set_xy2(n, pl + slope *
trendlilenght)
src = source, max_bars_back(src, 2000)
isOnL := false
broken = false
if angle > 0.1 and angle < 90
for i = trendlilenght to n - plx1
if src[i] < testLine.get_price(n - i)
broken := true
break
if not broken
plslope := slope
isOnL := true
lower := pl + slope * trendlilenght
line.new(plx1, ply1, n, pl + slope * trendlilenght,
color=color.red, style=line.style_dotted)
ply1 := pl
plx1 := n - trendlilenght
lower += plslope
plotL := not na(pl) and ta.change(plslope) ? na : srcBr[1] < lower[1] ? na :
lower
bs_L = ta.barssince(na(plotL))
///
// Pre-DEFINE
//
//---------------------------------------------------
var COLOR_TRANSP = color.new(#ffffff,100)
var COLOR_BLACK = color.new(#000000,0)
//---------------------------------------------------
var basicgr = "🧊 PunkAlgo Smart Fibonacci"
var fb_tooltip = "\nDepth ; The minimum number of bars that will be taken into
account when calculating the indicator.\n\nDeviation ; a multiplier that affects
how much the price should deviate from the previous pivot in order for the bar to
become a new pivot.\n"
// INPUT
//---------------------------------------------------------------------------------
------------------------------------------------------------------
view_gr = '🔴🟠🟡🟢🔵'
//---------------------------------------------------------------------------------
------------------------------------------------------------------
//---------------------------------------------------------------------------------
------------------------------------------------------------------
//---------------------------------------------------------------------------------
------------------------------------------------------------------
[k_volume,k_open,k_close,k_high,k_low,k_hlc3,k_hlcc4,k_ohlc4,k_hl2,k_close_mintick,
k_trtrue,k_atr14,k_atr14_mintick,k_rsipvt14]
= request.security(syminfo.tickerid ,'',
[volume,open,close,high,low,hlc3,hlcc4,ohlc4,hl2,str.tostring(close,format.mintick)
,ta.tr(true),ta.atr(14),str.tostring(ta.atr(14),format.mintick),ta.rsi(ta.pvt,14)]
)
//
// Background
//
//
//
// pre-define
-----------------------------------------------------------------------------------
---
var line fb_lineLast = na
var label fb_label_start_last = na
var label fb_label_end_last = na
var int fb_iLast = 0
var int fb_iPrev = 0
var float fb_pLast = 0
var fb_isHighLast = false // otherwise the last pivot is a low
pivot
// pivot
-----------------------------------------------------------------------------------
---
high_none = ta.highest(high,fb_depth) > nz(high[fb_depth/2])
fb_iH = high_none ? int(na) : bar_index[fb_depth/2]
fb_pH = high_none ? float(na) : nz(high[fb_depth/2])
low_none = ta.lowest (low ,fb_depth) < nz(low [fb_depth/2])
fb_iL = low_none ? int(na) : bar_index[fb_depth/2]
fb_pL = low_none ? float(na) : nz(low [fb_depth/2])
//---------------------------------------------------------------------------------
-----
calc_dev(_base_price, _price) => 100 * (_price - _base_price) / _price
//---------------------------------------------------------------------------------
-----
pivotFound(dev, isHigh, index, price) =>
if fb_isHighLast == isHigh and not na(fb_lineLast)
// same direction
if fb_isHighLast ? price > fb_pLast : price < fb_pLast
line.set_xy2(fb_lineLast, index, price)
label.set_xy(fb_label_end_last, index, price)
[fb_lineLast, fb_isHighLast,fb_label_start_last,fb_label_end_last]
else
[line(na), bool(na), label(na), label(na)]
else // reverse the direction (or create the very first line)
if math.abs(dev) > fb_dev_threshold
// price move is significant
id_fb_line = line.new(fb_iLast, fb_pLast, index, price,
color=color.new(draw_tline_c,draw_tline?0:100), width=1, style=line.style_dashed)
// ------ FBR start -> end ; slopped line
id_fb_label_start = label.new(fb_iLast, fb_pLast ,color=COLOR_TRANSP,
size=size.huge ,style=label.style_label_center,
textcolor=color.new(draw_pmark_c,draw_pmark?0:100) ,text= '◯' )
id_fb_label_end = label.new(index , price ,color=COLOR_TRANSP,
size=size.huge ,style=label.style_label_center,
textcolor=color.new(draw_pmark_c,draw_pmark?0:100) ,text= '◯' )
[id_fb_line, isHigh, id_fb_label_start, id_fb_label_end]
else
[line(na), bool(na),label(na),label(na)]
//---------------------------------------------------------------------------------
-----
fb_new_line = false
if not na(fb_iH)
fb_dev = calc_dev(fb_pLast, fb_pH)
[fb_id, fb_isHigh, fb_la_s_id, fb_la_e_id] = pivotFound(fb_dev, true, fb_iH,
fb_pH)
if not na(fb_id)
if fb_id != fb_lineLast
line.delete (fb_lineLast)
label.delete(fb_label_start_last)
label.delete(fb_label_end_last)
fb_new_line := true
fb_lineLast := fb_id
fb_label_start_last := fb_la_s_id
fb_label_end_last := fb_la_e_id
fb_isHighLast := fb_isHigh
fb_iPrev := fb_iLast
fb_iLast := fb_iH
fb_pLast := fb_pH
else if not na(fb_iL)
fb_dev = calc_dev(fb_pLast, fb_pL)
[fb_id, fb_isHigh, fb_la_s_id, fb_la_e_id] = pivotFound(fb_dev, false, fb_iL,
fb_pL)
if not na(fb_id)
if fb_id != fb_lineLast
line.delete (fb_lineLast)
label.delete(fb_label_start_last)
label.delete(fb_label_end_last)
fb_new_line := true
fb_lineLast := fb_id
fb_label_start_last := fb_la_s_id
fb_label_end_last := fb_la_e_id
fb_isHighLast := fb_isHigh
fb_iPrev := fb_iLast
fb_iLast := fb_iL
fb_pLast := fb_pL
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------
fb_retracement (_show, _fib_level, _col ,_switch) =>
_price = fb_pLast + ((line.get_y1(fb_lineLast)-fb_pLast))* _fib_level
_fbfb_id_line_show = false
_position = bar_index - line.get_x2(fb_lineLast)
_fbr_max_highest = math.max( ta.highest(high,
nz(math.max(1,_position),1)) , fb_pLast)
_fbr_min_lowest = math.min( ta.lowest (low ,
nz(math.max(1,_position),1)) , fb_pLast)
_fbr_max = fb_pLast < close ? _fbr_max_highest : fb_pLast > close ?
_fbr_min_lowest : fb_pLast
_fbr_line_max = fb_pLast < _price? _fbr_max_highest : fb_pLast > _price ?
_fbr_min_lowest : fb_pLast
_fbfb_id_line_show := fb_pLast < _price and _price-(k_atr14/4) <=
_fbr_line_max ? true
: fb_pLast > _price and _price+(k_atr14/4) >=
_fbr_line_max ? true
: false
if _switch =='auto' and not na(fb_lineLast)
fbfb_id_auto = line.new(line.get_x2(fb_lineLast) ,_price ,bar_index +
6 ,_price ,style=line.style_dashed,
color=color.new(_col,_fbfb_id_line_show?30:100) , width=1, extend=extend.none)
fbfb_id_ext_auto = line.new(bar_index+fb_label_position-
4,_price ,bar_index+fb_label_position+1 ,_price ,color=color.new(_col,0), width=1,
extend=extend.none)
fb_label_auto = label.new(x=bar_index+fb_label_position+1 ,y=_price,
text=str.tostring(_fib_level,"0.000")+(draw_simplelabel ? (' ' +
str.tostring(_price, format.mintick) + ' ' + str.tostring(((_price -
fb_pLast)/fb_pLast)*100,format.percent )):''),textcolor=color.new(_col,40) ,style=l
abel.style_label_left ,textalign=text.align_left , color=#00000000,
size=size.small)
line.delete(fbfb_id_auto[1] )
line.delete(fbfb_id_ext_auto[1] )
label.delete(fb_label_auto[1] )
if not _show
line.delete(fbfb_id_auto )
line.delete(fbfb_id_ext_auto )
label.delete(fb_label_auto )
if _show and _switch ==''
var fbfb_id = line.new(fb_iLast, _price, bar_index, _price,
color=color.new(_col,0) , width=1, extend=extend.none ,style=line.style_dashed )
//--- FBR | line = start to now
var fbfb_id_ext = line.new(fb_iLast, _price, bar_index, _price,
color=color.new(_col,0) , width=1, extend=extend.none) //--- FBR | line = now
to label position
var fb_label = label.new(x=bar_index ,y=_price,
text='' ,textcolor=COLOR_TRANSP ,style=label.style_label_left ,textalign=text.ali
gn_left , color=#00000000, size=size.small)
if not na(fb_lineLast)
line.set_xy1 (fbfb_id ,_fib_level==1.0?
line.get_x1(fb_lineLast):line.get_x2(fb_lineLast), _price)
line.set_xy2 (fbfb_id ,_fib_level==1.0 or _fib_level==0.0? bar_index
+ fb_label_position-4 : bar_index + 6 , _price)
line.set_color(fbfb_id ,color.new(_col, _fib_level==0.0?
0:_fib_level==1.0?0:_fbfb_id_line_show ? 30 : 100))
// line.set_style(fbfb_id ,_fib_level==0.0 or _fib_level==1.0 ?
line.style_dashed : line.style_solid)
//---------------------------------------------------------------------
------------------------------
line.set_xy1 (fbfb_id_ext ,bar_index+fb_label_position-4 ,_price)
line.set_xy2 (fbfb_id_ext ,bar_index+fb_label_position+1 ,_price)
line.set_width (fbfb_id_ext ,1)
//---------------------------------------------------------------------
------------------------------
label.set_xy (fb_label ,bar_index+fb_label_position+1 ,_price)
label.set_text (fb_label ,str.tostring(_fib_level,"0.000")+
(draw_simplelabel ? ' ' + str.tostring(_price, format.mintick) + ' ' +
str.tostring(((_price - fb_pLast)/fb_pLast)*100,format.percent ):''))
// label.set_tooltip (fb_label ,str.tostring(((_price -
fb_pLast)/fb_pLast)*100,format.percent ))
label.set_textcolor (fb_label ,color.new(_col,30))
import Trendoscope/abstractchartpatterns/5 as p
import Trendoscope/basechartpatterns/6 as bp
openSource = input.source(open, '', inline='cs', group='Source', display =
display.none)
highSource = input.source(high, '', inline='cs', group='Source', display =
display.none)
lowSource = input.source(low, '', inline='cs', group='Source', display =
display.none)
closeSource = input.source(close, '', inline='cs', group='Source', display =
display.none, tooltip = 'Source on which the zigzag and pattern calculation is
done')
allowedPatterns = array.from(
false,
allowUptrendChannel and allowRisingPatterns and allowParallelChannels and
allowChannels,
allowDowntrendChannel and allowFallingPatterns and allowParallelChannels and
allowChannels,
allowRangingChannel and allowNonDirectionalPatterns and allowParallelChannels
and allowChannels,
allowRisingWedgeExpanding and allowRisingPatterns and allowExpandingPatterns
and allowWedges,
allowFallingWedgeExpanding and allowFallingPatterns and allowExpandingPatterns
and allowWedges,
allowExpandingTriangle and allowNonDirectionalPatterns and
allowExpandingPatterns and allowTriangles,
allowRisingTriangleExpanding and allowRisingPatterns and
allowExpandingPatterns and allowTriangles,
allowFallingTriangleExpanding and allowFallingPatterns and
allowExpandingPatterns and allowTriangles,
allowRisingWedgeContracting and allowRisingPatterns and
allowContractingPatterns and allowWedges,
allowFallingWedgeContracting and allowFallingPatterns and
allowContractingPatterns and allowWedges,
allowConvergingTriangle and allowNonDirectionalPatterns and
allowContractingPatterns and allowTriangles,
allowFallingTriangleConverging and allowFallingPatterns and
allowContractingPatterns and allowTriangles,
allowRisingTriangleConverging and allowRisingPatterns and
allowContractingPatterns and allowTriangles
)
getLastPivotDirectionInt(lastPivotDirection)=>lastPivotDirection == 'up'? 1 :
lastPivotDirection == 'down'? -1 : 0
allowedLastPivotDirections = array.from(
0,
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(upTrendChannelLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(downTrendChannelLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(rangingChannelLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(risingWedgeExpandingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(fallingWedgeExpandingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(divergineTriangleLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(risingTriangleExpandingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(fallingTriangleExpandingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(risingWedgeContractingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(fallingWedgeContractingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(convergingTriangleLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(fallingTriangleContractingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection),
lastPivotDirection == 'custom'?
getLastPivotDirectionInt(risingTriangleContractingLastPivotDirection) :
getLastPivotDirectionInt(lastPivotDirection)
)
errorRatio = errorThresold/100
flatRatio = flatThreshold/100
showLabel = true
offset = 0
type Scanner
bool enabled
string ticker
string timeframe
p.ScanProperties sProperties
p.DrawingProperties dProperties
array<p.Pattern> patterns
array<zg.Zigzag> zigzags
var validPatterns = 0
mlzigzag = zigzag
if(zigzag.flags.newPivot)
while(mlzigzag.zigzagPivots.size() >= 6+offset)
lastBar = mlzigzag.zigzagPivots.first().point.index
lastDir = int(math.sign(mlzigzag.zigzagPivots.first().dir))
if(lastDBar.contains(mlzigzag.level)? lastDBar.get(mlzigzag.level) <
lastBar : true)
lastDBar.put(mlzigzag.level, lastBar)
[valid, currentPattern] = mlzigzag.find(this.sProperties,
this.dProperties, this.patterns, ohlcArray)
if(valid)
validPatterns+=1
currentPattern.draw()
this.patterns.push(currentPattern, maxPatterns)
alert('New Pattern Alert')
else
break
mlzigzag := mlzigzag.nextlevel()
true
if(barstate.isconfirmed or repaint)
scanner.scan()
// Functions
supertrend(_src, factor, atrLen) =>
atrat = ta.atr(atrLen)
upperBand = _src + factor * atrat
lowerBand = _src - factor * atrat
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atrat[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
// Get Components
ocAvg = math.avg(open, close)
ema1 = ta.ema(high, 9)
ema2 = ta.ema(high, 12)
ema3 = ta.ema(high, 15)
ema4 = ta.ema(high, 18)
sma1 = ta.sma(close, 5)
sma2 = ta.sma(close, 6)
sma3 = ta.sma(close, 7)
sma4 = ta.sma(close, 8)
sma5 = ta.sma(close, 9)
sma6 = ta.sma(close, 10)
sma7 = ta.sma(close, 11)
sma8 = ta.sma(close, 12)
sma9 = ta.sma(close, 13)
sma10 = ta.sma(close, 14)
sma11 = ta.sma(close, 15)
sma12 = ta.sma(close, 16)
sma13 = ta.sma(close, 17)
sma14 = ta.sma(close, 18)
sma15 = ta.sma(close, 19)
sma16 = ta.sma(close, 20)
psar = ta.sar(0.02, 0.02, 0.2)
[supertrend, direction] = supertrend(close, sensitivity, 11)
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR)[1])
pivotLow = fixnan(ta.pivotlow(barsL, barsR)[1])
// Colors
green = #04994b, green2 = #15c02a
red = #b4060d, red2 = #ff0002
// Strong TP Points //
maj_qual = 13
maj_len = 40
min_qual = 5
min_len = 5
min = false
selll = 0.0
buyy = 0.0
// Ha Market Bias //
ha_htf = ''
ha_len = 100
ha_len2 = 100
// Calculations {
o = ta.ema(open, ha_len)
c = ta.ema(close, ha_len)
h = ta.ema(high, ha_len)
l = ta.ema(low, ha_len)
haclose = tf(ha_htf, (o + h + l + c) / 4, 0)
xhaopen = tf(ha_htf, (o + c) / 2, 0)
haopen = na(xhaopen[1]) ? (o + c) / 2 : (xhaopen[1] + haclose[1]) / 2
hahigh = math.max(h, math.max(haopen, haclose))
halow = math.min(l, math.min(haopen, haclose))
// Oscillator {
osc_len = 7
sigcolor =
(osc_bias > 0) and (osc_bias >= osc_smooth) ? color.new(color.lime, 35) :
(osc_bias > 0) and (osc_bias < osc_smooth) ? color.new(color.lime, 75) :
(osc_bias < 0) and (osc_bias <= osc_smooth) ? color.new(color.red, 35) :
(osc_bias < 0) and (osc_bias > osc_smooth) ? color.new(color.red, 75) :
na
// }
// Plots {
p_h = plot(h2, "Bias High", color=color(na), display=display.none, editable=false)
p_l = plot(l2, "Bias Low", color=color(na), display=display.none, editable=false)
p_avg = plot(ha_avg, "Bias Avergae", color=color(na), display=display.none,
editable=false)
// Range Filter DW
//---------------------Range
Filter-----------------------------------------------------------------------------
-----------------------------------------
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Type
f_type = 'Type 2'
//Movement Source
mov_src = 'Close'
//Range Period
rng_per = 14
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0
//Colors
filt_color = upward ? #36db7f : downward ? #be130f : #cccccc
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Plot
filt_plot = plot(Show_rangefilter ? filt : na, color=filt_color, linewidth=3,
title='Filter', transp=0)
//Bar Color
// Smart Trail
trailType = input.string('modified', 'Trailtype', options=['modified',
'unmodified'])
ATRPeriod = input(13, 'ATR Period')
ATRFactor = input(4, 'ATR Factor')
smoothing = input(8, 'Smoothing')
Up = norm_c - loss
Dn = norm_c + loss
TrendUp = Up
TrendDown = Dn
Trend = 1
ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend ==
1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1]
//}
fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6
// Input
fastLength = input(title="Fast Length", defval=12)
slowLength = input(title="Slow Length", defval=26)
srrrc = input(title="Source", defval=close)
signalLength = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval
= 9)
// Data reference
[macd, signal, hist] = ta.macd(srrrc, fastLength, slowLength, signalLength)
// 4 level of green
greenHigh = #05df09
greenMidHigh = #05df09
greenMidLow = #388E3C
greenLow = #5f3a97
// Yellow
yellowLow = #5f3a97
// 4 level of red
redHigh = #ea0402
redMidHigh = #ea0402
redMidLow = #cc0402
redLow = #5f3a97
// Default color
candleBody = yellowLow
// Ranging trend
if hist > 0
if hist > hist[1] and hist[1] > 0
candleBody := greenLow
if hist < 0
if hist < hist[1] and hist[1] < 0
candleBody := redLow
// Bullish trend
if macd > 0 and hist > 0
candleBody := greenMidLow
// Bearish trend
if macd < 0 and hist < 0
candleBody := redMidLow