Professional Documents
Culture Documents
type bar
float o = open
float h = high
float l = low
float c = close
float v = volume
int i = bar_index
int t = time
type ob
float top
float btm
float avg
int loc
color css
float vol
int dir
int move
int blPOS
int brPOS
int xlocbl
int xlocbr
type alert
bool created = false
bool inside = false
bool mitigated = false
type cross
bool reset = false
if obshowactivity
if showline
line.new(
x1 = id.loc
, x2 = b.t
, y1 = id.avg
, y2 = id.avg
, color = color.new(id.css, 0)
, xloc = xloc.bar_time
, style = line.style_dashed
)
if showmetric
if i == math.min(oblast - 1, full.size() - 1)
float tV = 0
float[] dV = array.new<float>()
for j = 0 to seq
cV = full.get(j)
tV += cV.vol
if j == seq
for y = 0 to seq
dV.push(
math.floor(
(full.get(y).vol / tV) * 100)
)
id = full.get(y)
label.new(
b.i + 1
, id.avg
,
textcolor = color.new(id.css, 0)
,
style = label.style_label_left
,
size = obtxt.txSz()
,
color = #ffffff00
,
text =
str.tostring(
math.round(full.get(y).vol, 3), format =
format.volume) + " (" + str.tostring(dV.get(y)) + "%)"
)
if id.size() > 1
for i = id.size() - 1 to 1
stuff = id.get(i)
current = id.get(0)
switch
switch metric.dir
1 =>
switch metric.move
-1 =>
switch metric.move
fnOB() =>
up = ta.highest ( len )
dn = ta.lowest ( len )
pv = ta.pivothigh(b.v, len, len)
atr = ta.atr(len)
if pv and dir == 1
blob.unshift(
ob.new(
topP
, b.l[len]
, math.avg(topP, b.l[len])
, b.t[len]
, obupcs
, b.v[len]
, b.c[len] > b.o[len] ? 1 : -1
, 1
, 0
, 0
, b.t[len]
)
)
blal.created := true
blIS.reset := false
if pv and dir == -1
brob.unshift(
ob.new(
b.h[len]
, btmP
, math.avg(btmP, b.h[len])
, b.t[len]
, obdncs
, b.v[len]
, b.c[len] > b.o[len] ? 1 : -1
, 1
, 0
, 0
, b.t[len]
)
)
bral.created := true
brIS.reset := false
for j = 0 to len - 1
blob.remove(i)
blal.mitigated := true
break
for j = 0 to len - 1
brob.remove(i)
bral.mitigated := true
break
if blob.size() > 0
metric.umt()
if brob.size() > 0
metric.umt()
if overlap
blob.overlap()
brob.overlap()
if barstate.isconfirmed
if blob.size() > 0
ob = blob.get(0)
if brob.size() > 0
ob = brob.get(0)
for bx in box.all
bx.delete()
for ln in line.all
ln.delete()
for lb in label.all
lb.delete()
if blob.size() > 0
for i = 0 to math.min(oblast - 1, blob.size() - 1)
blob.get(i).display(blob, i)
if brob.size() > 0
for i = 0 to math.min(oblast - 1, brob.size() - 1)
brob.get(i).display(brob, i)
if obshow
fnOB()
// Hma
wma = ta.wma(close, length)
wma1 = ta.wma(close, length)
a = 3 * wma - 2 * wma1
// Sma
a1 = ta.sma(close, length)
// Extract the difference (HMA - SMA)
diff = a - a1
// Table Function
printTable(txt, col, row, color, txt1, col1, row1, color1) => var table t =
table.new(position.bottom_center, 60, 3),
table.cell(t, col, row, txt, bgcolor =
color),
table.cell(t, col1, row1, txt1, bgcolor =
color1, text_color = color.white)
// Normalize
x = diff
length_ = 100
xMax = ta.highest(x, length_)
xMin = ta.lowest(x, length_)
range_ = xMax - xMin
y = x / range_
// Plot
color1 = color.from_gradient(g, -2, 2, color_dn, color_up)
p1 = plot(a, 'HEMA', color1, 2)
p2 = plot(a1, 'SMA', color1, 2)
fill(p1, p2, color = color1)