Professional Documents
Culture Documents
PAT_6
PAT_6
// Благодарность приветствуется !
// Donations ~ BTC ~ 1EpDN7pg1WqURcK7te5kQtgx3H17wuHiV7
// Do it if you find the stuff useful !
max_bars_back = 1200
max_labels_count = 1200
max_lines_count = 1200
//-----------------------------------------------------------------------------{
//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
//-----------------------------------------------------------------------------{
show_swing_ms = input.string ("All"
, "Swing " , inline = "1", group = "MARKET
STRUCTURE" , options = ["All", "CHoCH", "CHoCH+", "BOS", "None"])
show_internal_ms = input.string ("All"
, "Internal " , inline = "2", group = "MARKET STRUCTURE"
, options = ["All", "CHoCH", "CHoCH+", "BOS", "None"])
internal_r_lookback = input.int (4
, "" , inline = "2", group = "MARKET STRUCTURE"
, minval = 2)
swing_r_lookback = input.int (50
, "" , inline = "1", group = "MARKET STRUCTURE"
, minval = 2)
ms_mode = input.string ("Manual"
, "Market Structure Mode" , inline = "a", group = "MARKET STRUCTURE"
, tooltip = "[Manual] Use selected lenght\n[Dynamic] Use automatic lenght" ,options
= ["Manual", "Dynamic"])
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
if lvl_yearly
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Market Structure
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
method darkcss(color css, float factor, bool bull) =>
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
)
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
)
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
not CHoCH =>
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]
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - RSI
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
up = ta.rma(math.max(ta.change(rsi_src), 0), rsi_length)
down = ta.rma(-math.min(ta.change(rsi_src), 0), rsi_length)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
// 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)
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 >()
)
var obD draw = obD.new(
array.new<box >()
, array.new<box >()
, array.new<box >()
, array.new<box >()
, array.new<line>()
)
if barstate.isfirst
for i = 0 to ob_num - 1
draw.mL.eL(false, false, use_grayscale ? color.new(color.gray, 0) :
color.new(css,0), ob_tf)
draw.ob.eB(false, use_grayscale ? color.new(color.gray, 90) : css,
swing, ob_tf)
draw.blB.eB(false, css_metric_up, swing, ob_tf)
draw.brB.eB(false, css_metric_dn, swing, ob_tf)
draw.eOB.eB(true, use_grayscale ? color.new(color.gray, 90) : css,
swing, ob_tf)
// 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)
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
bull_ob.drawVOB(true, ob_bull_css, hN.first(), false)
bear_ob.drawVOB(false, ob_bear_css, lN.first(), false)
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
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
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
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
atr = ta.atr(lookback)
trueRange = atr * atrFactor
DemaAtr = demaOut
DemaAtr := nz(DemaAtr[1], DemaAtr)
// Function Out
DemaAtr = DemaAtrWithBands(periodDema, source, periodAtr, factorAtr)
// Conditions
DemaAtrLong = DemaAtr > DemaAtr[1]
DemaAtrShort = DemaAtr < DemaAtr[1]
// Colour Condtions
var color Trend = #ffffff
if DemaAtrLong
Trend := longColour
if DemaAtrShort
Trend := shortColour
// Plotting
plot(showAtr ? DemaAtr : na, "ATR", color=Trend, linewidth=2)
// Alerts
alertcondition(DemaAtrLong, title="Dema ATR Trend Up", message="Dema ATR Trend Up -
{{ticker}} - {{interval}}")
alertcondition(DemaAtrShort, title="Dema ATR Trend Down", message="Dema ATR Trend
Down - {{ticker}} - {{interval}}")
//
===================================================================================
=================================//
confidence(pearsonR) =>
switch
pearsonR < 0.2 => "Крайне слабый"
pearsonR < 0.3 => "Очень слабый"
pearsonR < 0.4 => "Слабый"
pearsonR < 0.5 => "В основном слабый"
pearsonR < 0.6 => "Относительно слабый"
pearsonR < 0.7 => "Умеренно слабый"
pearsonR < 0.8 => "Умеренный"
pearsonR < 0.9 => "Умеренно сильный"
pearsonR < 0.92 => "В основном сильный"
pearsonR < 0.94 => "Сильный"
pearsonR < 0.96 => "Очень сильный"
pearsonR < 0.98 => "Исключительно сильный"
=> "Ультра сильный"
string t1 = "В режиме долгосрочного канала, если канал не виден, прокрутите график
для дополнительных исторических данных."
string t2 = "Коэффициент Пирсона R, статистический показатель в адаптивном поиске
трендов, оценивает линейную зависимость между ценой и проекцией тренда. Значение,
близкое к 1, указывает на сильную положительную корреляцию, укрепляя уверенность в
направлении тренда на основе исторических движений цен."
// Длины периодов
var array<int> Periods = periodMode ?
array.from(na,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1050,110
0,1150,1200) :
array.from(na,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200)
if barstate.islast
// Найти наибольший коэффициент Пирсона R
float highestPearsonR = math.max(pearsonR01, pearsonR02, pearsonR03,
pearsonR04, pearsonR05, pearsonR06, pearsonR07, pearsonR08, pearsonR09, pearsonR10,
pearsonR11, pearsonR12, pearsonR13, pearsonR14, pearsonR15, pearsonR16, pearsonR17,
pearsonR18, pearsonR19)
switch highestPearsonR
pearsonR01 =>
detectedPeriod := Periods.get(1)
detectedSlope := slope01
detectedIntrcpt := intercept01
detectedStdDev := stdDev01
pearsonR02 =>
detectedPeriod := Periods.get(2)
detectedSlope := slope02
detectedIntrcpt := intercept02
detectedStdDev := stdDev02
pearsonR03 =>
detectedPeriod := Periods.get(3)
detectedSlope := slope03
detectedIntrcpt := intercept03
detectedStdDev := stdDev03
pearsonR04 =>
detectedPeriod := Periods.get(4)
detectedSlope := slope04
detectedIntrcpt := intercept04
detectedStdDev := stdDev04
pearsonR05 =>
detectedPeriod := Periods.get(5)
detectedSlope := slope05
detectedIntrcpt := intercept05
detectedStdDev := stdDev05
pearsonR06 =>
detectedPeriod := Periods.get(6)
detectedSlope := slope06
detectedIntrcpt := intercept06
detectedStdDev := stdDev06
pearsonR07 =>
detectedPeriod := Periods.get(7)
detectedSlope := slope07
detectedIntrcpt := intercept07
detectedStdDev := stdDev07
pearsonR08 =>
detectedPeriod := Periods.get(8)
detectedSlope := slope08
detectedIntrcpt := intercept08
detectedStdDev := stdDev08
pearsonR09 =>
detectedPeriod := Periods.get(9)
detectedSlope := slope09
detectedIntrcpt := intercept09
detectedStdDev := stdDev09
pearsonR10 =>
detectedPeriod := Periods.get(10)
detectedSlope := slope10
detectedIntrcpt := intercept10
detectedStdDev := stdDev10
pearsonR11 =>
detectedPeriod := Periods.get(11)
detectedSlope := slope11
detectedIntrcpt := intercept11
detectedStdDev := stdDev11
pearsonR12 =>
detectedPeriod := Periods.get(12)
detectedSlope := slope12
detectedIntrcpt := intercept12
detectedStdDev := stdDev12
pearsonR13 =>
detectedPeriod := Periods.get(13)
detectedSlope := slope13
detectedIntrcpt := intercept13
detectedStdDev := stdDev13
pearsonR14 =>
detectedPeriod := Periods.get(14)
detectedSlope := slope14
detectedIntrcpt := intercept14
detectedStdDev := stdDev14
pearsonR15 =>
detectedPeriod := Periods.get(15)
detectedSlope := slope15
detectedIntrcpt := intercept15
detectedStdDev := stdDev15
pearsonR16 =>
detectedPeriod := Periods.get(16)
detectedSlope := slope16
detectedIntrcpt := intercept16
detectedStdDev := stdDev16
pearsonR17 =>
detectedPeriod := Periods.get(17)
detectedSlope := slope17
detectedIntrcpt := intercept17
detectedStdDev := stdDev17
pearsonR18 =>
detectedPeriod := Periods.get(18)
detectedSlope := slope18
detectedIntrcpt := intercept18
detectedStdDev := stdDev18
=> // ПирсонR19
detectedPeriod := Periods.get(19)
detectedSlope := slope19
detectedIntrcpt := intercept19
detectedStdDev := stdDev19
if na(baseLine)
baseLine := line.new(startAtBar, startPrice, bar_index, endPrice,
width=lineWidth, extend=EXTEND_STYLE,
color=color.new(colorInput, transpInput),
style=midLineStyle == "Пунктирный" ? line.style_dotted
:
midLineStyle == "Пунктирная" ? line.style_dashed
: line.style_solid)
else
line.set_xy1(baseLine, startAtBar, startPrice)
line.set_xy2(baseLine, bar_index, endPrice)
if na(upperFill)
upperFill := linefill.new(upperLine, baseLine, color=color.new(colorInput,
fillTransparency))
if na(lowerFill)
lowerFill := linefill.new(baseLine, lowerLine, color=color.new(colorInput,
fillTransparency))
table t = table.new(getTablePosition(tablePositionInput), 3, 2)
string text1 = periodMode ? "Автоматически выбранный период (долгосрочный): " +
str.tostring(detectedPeriod)
: "Автоматически выбранный период:" +
str.tostring(detectedPeriod)
var colorInputLight = color.new(colorInput, 40)
table.cell(t, 0, 0, text1, text_color=colorInputLight, text_size=textSizeInput
== "Большой" ? size.large : size.normal)
if showPearsonInput
table.cell(t, 1, 0, "Пирсон's R: " + str.tostring(detectedSlope > 0.0 ? -
highestPearsonR : highestPearsonR, "#.###"), text_color=colorInput,
text_size=textSizeInput == "Большой" ? size.large : size.normal)
else
table.cell(t, 1, 0, "Сила тренда:" + confidence(highestPearsonR),
text_color=colorInput, text_size=textSizeInput == "Большой" ? size.large :
size.normal)
//=================================================================================
===================================================================================
============================//
//
===================================================================================
=====================================================================//
Fhigh = ta.highest(FPeriod)
Flow = ta.lowest(FPeriod)
FH = ta.highestbars(high, FPeriod)
FL = ta.lowestbars(low, FPeriod)
downfibo = FH < FL
//
===================================================================================
=======================================================//