Imbalance W Alert
Imbalance W Alert
0 at
https://mozilla.org/MPL/2.0/
// © LeviathanCapital
//@version=5
indicator("Gaps + Imbalances + Wicks (MTF) - By Leviathan", overlay=true,
max_boxes_count = 500, max_lines_count = 500)
// General Settings
boxtype = input.string('Imbalance', 'Zone Type ', options=['Imbalance',
'Gap', 'Wick'], group = 'General Settings', inline='1')
tfinput = input.timeframe('', ' - ', group = 'General Settings',
inline='1')
showmiddleline = input.bool(true, 'Middle Line ', inline='ln', group = 'General
Settings')
showbottomline = input.bool(false, 'Bottom Line ', inline='ln', group = 'General
Settings')
showtopline = input.bool(false, 'Top Line ', inline='ln', group = 'General
Settings')
// Distances in %
upimbdist = (l-h2) / h2 * 100
downimbdist = (l2-h) / h * 100
upgapdist = (l-h1) / h1 * 100
downgapdist = (l1-h) / h * 100
upwickdist = (h1-math.max(o1, c1)) / math.max(o1, c1) * 100
downwickdist = (math.min(o1, c1)-l1) / l1 * 100
// Candle body size and the size of lower&upper wicks
bodysize = math.abs(o1-c1)
upperWickSize = h1 - math.max(o1, c1)
lowerWickSize = math.min(o1, c1) - l1
// Hide boxes (transparency to 100)
clear = color.rgb(0,0,0,100)
color upcol = showboxes ? upcol1 : clear
color downcol = showboxes ? downcol1 : clear
// Volume
float labeltype = 0
if boxtype=='Imbalance' or boxtype=='Wick'
labeltype := tfinput==timeframe.period ? tvol[1] : tvol[2]
if boxtype=='Gap'
labeltype := tfinput==timeframe.period ? tvol[0] : tvol[1]
// Calculating inRange, used for lookback in days
MSPD = 24 * 60 * 60 * 1000
lastBarDate = timestamp(year(timenow), month(timenow), dayofmonth(timenow),
hour(timenow), minute(timenow), second(timenow))
thisBarDate = timestamp(year, month, dayofmonth, hour, minute, second)
daysLeft = math.abs(math.floor((lastBarDate - thisBarDate) / MSPD))
inRange = lookback ? (daysLeft < daysBack) : true
// Timeframe labels
timeframelabel(tfinput) =>
switch tfinput
'' => timeframe.period + (timeframe.isminutes ? 'm' : na)
'1' => '1m'
'2' => '2m'
'3' => '3m'
'4' => '4m'
'5' => '5m'
'10' => '10m'
'15' => '15m'
'30' => '30m'
'60' => '1H'
'120' => '2H'
'240' => '4H'
'480' => '8H'
'720' => '12H'
=> tfinput
// Box Text
var string imbboxtext = na, var string gapboxtext = na, var string wickboxtext
= na
if showboxtext and textType == 'Labels'
imbboxtext := str.tostring(imbtext)
gapboxtext := str.tostring(gaptext)
wickboxtext := str.tostring(wicktext)
if showboxtext and textType == 'Volume'
imbboxtext := str.tostring(labeltype, format.volume)
gapboxtext := str.tostring(labeltype, format.volume)
wickboxtext := str.tostring(labeltype, format.volume)
if showboxtext and textType == 'Labels + Timeframe'
imbboxtext := str.tostring(imbtext) + ' • ' +
str.tostring(timeframelabel(tfinput))
gapboxtext := str.tostring(gaptext) + ' • ' +
str.tostring(timeframelabel(tfinput))
wickboxtext := str.tostring(wicktext) + ' • ' +
str.tostring(timeframelabel(tfinput))
if showboxtext and textType == 'Labels + Timeframe + Volume'
imbboxtext := str.tostring(imbtext) + ' • ' +
str.tostring(timeframelabel(tfinput)) + ' • ' + str.tostring(labeltype,
format.volume)
gapboxtext := str.tostring(gaptext) + ' • ' +
str.tostring(timeframelabel(tfinput)) + ' • ' + str.tostring(labeltype,
format.volume)
wickboxtext := str.tostring(wicktext) + ' • ' +
str.tostring(timeframelabel(tfinput)) + ' • ' + str.tostring(labeltype,
format.volume)
if boxtype == 'Imbalance' and (l > h2) and showup and condition and inRange and new
imbboxUP = box.new(t[2], l, time, h2, bgcolor = upcol,
border_color=upbordercol,border_width = 1, text=imbboxtext, text_size =
switchtextsize(textsize), text_halign = switchhalign(texthalign), text_valign =
switchvalign(textvalign), text_color = uptextcol,xloc = xloc.bar_time)
topLine = showtopline ? line.new(t[2], l, time, l, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
bottomLine = showbottomline ? line.new(t[2], h2, time, h2, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
middleLine = showmiddleline ? line.new(t[2], (l + h2)/2, time, (l + h2)/2,
color=lineCol, style=lineStyle(linestyle), xloc = xloc.bar_time) : na
criado := true
array.push(topLines, topLine)
array.push(middleLines, middleLine)
array.push(bottomLines, bottomLine)
array.push(boxes, imbboxUP)
if boxtype == 'Imbalance' and (h < l2) and showdown and condition2 and inRange and
new
imbboxDOWN = box.new(t[2], h, time, l2, bgcolor = downcol,
border_color=downbordercol,border_width = 1, text=imbboxtext, text_size =
switchtextsize(textsize), text_halign = switchhalign(texthalign), text_valign =
switchvalign(textvalign), text_color = downtextcol, xloc = xloc.bar_time)
topLine = showtopline ? line.new(t[2], l2, time, l2, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
bottomLine = showbottomline ? line.new(t[2], h, time, h, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
middleLine = showmiddleline ? line.new(t[2], (h+l2)/2, time, (h+l2)/2,
color=lineCol, style=lineStyle(linestyle), xloc = xloc.bar_time) : na
criado := true
array.push(topLines, topLine)
array.push(middleLines, middleLine)
array.push(bottomLines, bottomLine)
array.push(boxes, imbboxDOWN)
if boxtype == 'Gap' and l > h1 and showup and condition3 and inRange and new
gapboxUP = box.new(t[1], l, time, h1, bgcolor = upcol,
border_color=upbordercol, border_width = 1, text=gapboxtext, text_size =
switchtextsize(textsize), text_halign = switchhalign(texthalign), text_valign =
switchvalign(textvalign), text_color = uptextcol, xloc = xloc.bar_time)
topLine = showtopline ? line.new(t[1], l, time, l, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
bottomLine = showbottomline ? line.new(t[1], h1, time, h1, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
middleLine = showmiddleline ? line.new(t[1], (l+h1)/2, time, (l+h1)/2,
color=lineCol, style=lineStyle(linestyle), xloc = xloc.bar_time) : na
array.push(topLines, topLine)
array.push(middleLines, middleLine)
array.push(bottomLines, bottomLine)
array.push(boxes, gapboxUP)
if boxtype == 'Gap' and h < l1 and showdown and condition4 and inRange and new
gapboxDOWN = box.new(t[1], l1, time, h, bgcolor = downcol,
border_color=downbordercol,border_width = 1, text=gapboxtext, text_size =
switchtextsize(textsize), text_halign = switchhalign(texthalign), text_valign =
switchvalign(textvalign), text_color = downtextcol, xloc = xloc.bar_time)
topLine = showtopline ? line.new(t[1], l1, time, l1, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
bottomLine = showbottomline ? line.new(t[1], h, time, h, color=lineCol,
style=lineStyle(linestyle), xloc = xloc.bar_time) : na
middleLine = showmiddleline ? line.new(t[1], (h+l1)/2, time, (h+l1)/2,
color=lineCol, style=lineStyle(linestyle), xloc = xloc.bar_time) : na
array.push(topLines, topLine)
array.push(middleLines, middleLine)
array.push(bottomLines, bottomLine)
array.push(boxes, gapboxDOWN)
if boxtype == 'Wick' and upperWickSize>(bodysize/6) and showup and condition5 and
inRange and new
wickboxUP = box.new(t[1], h1, time, math.max(o1, c1), bgcolor = upcol,
border_color=upbordercol,border_width = 1, text=wickboxtext, text_size =
switchtextsize(textsize), text_halign = switchhalign(texthalign), text_valign =
switchvalign(textvalign), text_color = uptextcol, xloc = xloc.bar_time)
topLine = showtopline ? line.new(t[1], math.max(h1, math.max(o1, c1)),
time, math.max(h1, math.max(o1, c1)), color=lineCol, style=lineStyle(linestyle),
xloc = xloc.bar_time) : na
bottomLine = showbottomline ? line.new(t[1], math.min(h1, math.max(o1, c1)),
time, math.min(h1, math.max(o1, c1)), color=lineCol, style=lineStyle(linestyle),
xloc = xloc.bar_time) : na
middleLine = showmiddleline ? line.new(t[1], (h1+math.max(o1, c1))/2, time,
(h1+math.max(o1, c1))/2, color=lineCol, style=lineStyle(linestyle), xloc =
xloc.bar_time) : na
array.push(topLines, topLine)
array.push(middleLines, middleLine)
array.push(bottomLines, bottomLine)
array.push(boxes, wickboxUP)
if boxtype == 'Wick' and lowerWickSize>(bodysize/6) and showdown and condition6 and
inRange and new
wickboxDOWN = box.new(t[1], math.min(o1, c1), time, l1, bgcolor = downcol,
border_color=downbordercol,border_width = 1, text=wickboxtext, text_size =
switchtextsize(textsize), text_halign = switchhalign(texthalign), text_valign =
switchvalign(textvalign), text_color = downtextcol, xloc = xloc.bar_time)
topLine = showtopline ? line.new(t[1], math.max(l1, math.min(o1, c1)),
time, math.max(l1, math.min(o1, c1)), color=lineCol, style=lineStyle(linestyle),
xloc = xloc.bar_time) : na
bottomLine = showbottomline ? line.new(t[1], math.min(l1, math.min(o1, c1)),
time, math.min(l1, math.min(o1, c1)), color=lineCol, style=lineStyle(linestyle),
xloc = xloc.bar_time) : na
middleLine = showmiddleline ? line.new(t[1], (l1+math.min(o1, c1))/2, time,
(l1+math.min(o1, c1))/2, color=lineCol, style=lineStyle(linestyle), xloc =
xloc.bar_time) : na
array.push(topLines, topLine)
array.push(middleLines, middleLine)
array.push(bottomLines, bottomLine)
array.push(boxes, wickboxDOWN)
box.set_right(box, time+1)
line.set_x2(topLine, time+1)
line.set_x2(middleLine, time+1)
line.set_x2(bottomLine, time+1)
line.delete(topLine)
line.delete(middleLine)
line.delete(bottomLine)
box.delete(box)
array.remove(boxes, i)
array.remove(topLines, i)
array.remove(middleLines, i)
array.remove(bottomLines, i)
i += 1
size2 = array.size(boxes)
if size2 > 0
var condicao = false
for i = 0 to size2 - 1
j2 = size2 - 1 - i
box2 = array.get(boxes, j2)
level2 = box.get_bottom(box2)
level22 = box.get_top(box2)
if (high > level2 and low < level2) or (high > level22 and low < level22)
alert("Imbalance atingido", alert.freq_once_per_bar)