Smart Money
Smart Money
0
at https://mozilla.org/MPL/2.0/
// © BigBeluga
//
//@version=5
indicator("Price Action Smart Money Concepts [BigBeluga]", "Price Action Smart
Money Concepts [BigBeluga]", overlay = true, max_bars_back = 5000, max_boxes_count
= 500, max_labels_count = 500, max_lines_count = 500, max_polylines_count = 100)
plot(na)
_
='
------------
–––––––––––––––––––––––––– INPUTS
–––––––––––––––––––––––––––
------------
'//{
windowsis = input.bool(true, "Window ", inline
= "kla", group = "MARKET STRUCTURE")
mswindow = input.int(5000, "", tooltip = "Limit market structure calculation to
improve memory speed time", group = "MARKET STRUCTURE", inline = "kla", minval =
1000)
showSwing = input.bool ( true ,
"Swing ", inline = "scss", group = "MARKET
STRUCTURE")
swingLimit = input.int (100, "", tooltip = "[INPUT] Limit swing structure to
tot bars back", inline = "scss", group = "MARKET STRUCTURE", minval = 10, maxval =
200)
swingcssup = input.color (#089981, "", inline = "scss", group = "MARKET
STRUCTURE")
swingcssdn = input.color (#f23645, "", inline = "scss", group = "MARKET
STRUCTURE")
ehlshow = input.bool(true, "Equal H&L ", tooltip = "Display EQH and EQL",
inline = "ehl", group = "LIQUIDITY CONCEPTS")
ehlmode = input.string("Short-Term", "", options = ["Short-Term", "Mid-Term",
"Long-Term"], inline = "ehl", group = "LIQUIDITY CONCEPTS")
ehldowncs = input.color(#6fad6f, "", inline = "ehl", group = "LIQUIDITY
CONCEPTS")
ehlupcs = input.color(#ce636d, "", inline = "ehl", group = "LIQUIDITY CONCEPTS")
type alert
bool b = false // If condition has been met or not
string d = na // Bullish or Bearish direction
string n = na // Name of alert
if barstate.isfirst
for i in a
if i
b := true
break
for i = 0 to inputs.size() - 1
a.unshift(alert.new())
//}
_
='
------------
–––––––––––––––––––––––––– UDT
–––––––––––––––––––––––––––
------------
'//{
// type alert
// bool bos = false // BOS Created
// bool choch = false // CHoCH Created
// bool bosx = false // BOS Sweep
// bool chochx = false // CHoCH Sweep
// bool obmitigated = false // Order Block Mitigated
// bool bbmitigated = false // Breaker Block Mitigated
// bool priceenteredob = false // Price Enetered Order block
// bool priceenteredbb = false // price enetered breaker block
// bool pricewithinob = false // price within order block
// bool pricewithinbb = false // price within order block
// bool fvgcreated = false // fvg created
// bool fvgmitigated = false // fvg mitigated
// bool bfvgmitigated = false // breaker fvg mitigated
// bool priceenteredfvg = false // price entered fvg
// bool priceenteredbfvg = false // price enetered breaker fvg
// bool pricewithinfvg = false // price within fvg
// bool pricewithinbfvg = false // price within breaker fvg
// bool sfpcreated = false // sfp
// bool priceenteredarea = false // price enetered area
// bool pricewithinarea = false // price within area
// bool areamitigated = false // area mitigated
// bool areacreated = false // area created
// bool equal = false // equal
// bool print = false // liquidity print
type hqlzone
box pbx
box ebx
box lbx
label plb
label elb
label lbl
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 entered
bool normal = false
bool breaker = false
type store
line [] ln
label [] lb
box [] bx
linefill[] lf
type structure
int zn
float zz
float bos
float choch
int loc
int temp
int trend
int start
float main
int xloc
bool upsweep
bool dnsweep
string txt = na
type drawms
int x1
int x2
float y
string txt
color css
string style
type ob
bool bull
float top
float btm
float avg
int loc
color css
float vol
int dir
int move
int blPOS
int brPOS
int xlocbl
int xlocbr
bool isbb = false
int bbloc
type FVG
float top = na
float btm = na
int loc = bar_index
bool isbb = false
int bbloc = na
bool israid = false
float raidy = na
int raidloc = na
int raidx2 = na
bool active = false
color raidcs = na
type SFP
float y
int loc
float ancor
type sfpbuildlbl
int x
float y
string style
color css
string txt
type sfpbuildline
int x1
int x2
float y
color css
float ancor
int loc
type equalbuild
int x1
float y1
int x2
float y2
color css
string style
type equalname
int x
float y
string txt
color css
string style
type ehl
float pt
int t
float pb
int b
type sellbuyside
float top
float btm
int loc
color css
string txt
float vol
type timer
bool start = false
int count = 0
//}
_
='
------------
–––––––––––––––––––––––––– SETUP
–––––––––––––––––––––––––––
------------
'//{
if barstate.islast
for obj in bin.ln
obj.delete()
for obj in bin.lb
obj.delete()
for obj in bin.bx
obj.delete()
for obj in bin.lf
obj.delete()
bin.ln.clear()
bin.lb.clear()
bin.bx.clear()
bin.lf.clear()
invcol = #ffffff00
hl () => [high, low]
min = 99999999.
max = 0.
idx = 0
if use_max
for i = 0 to (bar_index - loc)
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
else
for i = 0 to (bar_index - loc)
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
idx
indexHighTF = barstate.isrealtime ? 1 : 0
indexCurrTF = barstate.isrealtime ? 0 : 1
method find(structure ms, bool use_max, bool sweep, bool useob) =>
min = 99999999.
max = 0.
idx = 0
if not sweep
if ((bar_index - ms.loc) - 1) > 0
if use_max
for i = 0 to (bar_index - ms.loc) - 1
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
if useob
if high[idx + 1] > high[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
for i = 0 to (bar_index - ms.loc) - 1
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
if useob
if low[idx + 1] < low[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
if use_max
for i = 0 to (bar_index - ms.loc)
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
if useob
if high[idx + 1] > high[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
for i = 0 to (bar_index - ms.loc)
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
if useob
if low[idx + 1] < low[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
if ((bar_index - ms.xloc) - 1) > 0
if use_max
for i = 0 to (bar_index - ms.xloc) - 1
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
if useob
if high[idx + 1] > high[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
for i = 0 to (bar_index - ms.xloc) - 1
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
if useob
if low[idx + 1] < low[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
if use_max
for i = 0 to (bar_index - ms.xloc)
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
if useob
if high[idx + 1] > high[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
else
for i = 0 to (bar_index - ms.xloc)
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
if useob
if low[idx + 1] < low[idx]
max := high[idx + 1]
min := low [idx + 1]
idx := idx + 1
idx
method fnOB(ob[] block, bool bull, float cords, int idx) =>
switch bull
true =>
blobenter.normal := false
blobenter.breaker := false
block.unshift(
ob.new(
true
, cords
, low [idx]
, math.avg(cords, low[idx])
, time [idx]
, obupcs
, volume[idx]
, close [idx] > open[idx] ? 1 : -1
, 1
, 1
, 1
, time [idx]
)
)
false =>
brobenter.normal := false
brobenter.breaker := false
block.unshift(
ob.new(
false
, high [idx]
, cords
, math.avg(cords, high[idx])
, time [idx]
, obdncs
, volume[idx]
, close [idx] > open[idx] ? 1 : -1
, 1
, 1
, 1
, time [idx]
)
)
false =>
if obmiti == "Close" ? math.max(close, open) > stuff.top :
obmiti == "Wick" ? high > stuff.top : obmiti == "Avg" ? high > stuff.avg : na
bralerts.set(4, alert.new(true, "Bearish", "OB
Mitigated\n"))
stuff.isbb := true
stuff.bbloc := time
if not obshowbb
block.remove(i)
else
switch stuff.bull
true =>
if obmiti == "Close" ? math.max(close, open) > stuff.top :
obmiti == "Wick" ? high > stuff.top : obmiti == "Avg" ? high > stuff.avg : na
block.remove(i)
false =>
if obmiti == "Close" ? math.min(close, open) < stuff.btm :
obmiti == "Wick" ? low < stuff.btm : obmiti == "Avg" ? low < stuff.avg : na
block.remove(i)
if bear.size() > 1
for i = bear.size() - 1 to 1
stuff = bear.get(i)
current = bear.get(0)
v = wichlap == "Recent" ? i : 0
switch
stuff.btm > current.btm and stuff.btm < current.top =>
bear.remove(v)
stuff.top < current.top and stuff.btm > current.btm =>
bear.remove(v)
stuff.top > current.top and stuff.btm < current.btm =>
bear.remove(v)
stuff.top < current.top and stuff.top > current.btm =>
bear.remove(v)
if brFVG.size() > 1
for i = brFVG.size() - 1 to 1
stuff = brFVG.get(i)
current = brFVG.get(0)
switch
stuff.btm > current.btm and stuff.btm < current.top =>
brFVG.remove(i)
stuff.top < current.top and stuff.btm > current.btm =>
brFVG.remove(i)
stuff.top > current.top and stuff.btm < current.btm =>
brFVG.remove(i)
stuff.top < current.top and stuff.top > current.btm =>
brFVG.remove(i)
-1 =>
switch metric.move
1 => metric.brPOS := metric.brPOS + 1, metric.move := 2
2 => metric.brPOS := metric.brPOS + 1, metric.move := 3
3 => metric.blPOS := metric.blPOS + 1, metric.move := 1
else
bin.bx.unshift(box.new (top = id.top, bottom = id.btm, left = id.loc ,
right = id.bbloc , border_color = na , bgcolor = id.css , xloc =
xloc.bar_time))
bin.bx.unshift(box.new (top = id.top, bottom = id.btm, left = id.bbloc ,
right = time , border_color = id.css , bgcolor = id.bull ? bbup : bbdn , xloc =
xloc.bar_time, border_width = 2))
bin.bx.unshift(box.new (top = id.top, bottom = id.btm, left = time ,
right = time + 1 , border_color = id.css , bgcolor = id.bull ? bbup : bbdn , xloc =
xloc.bar_time, extend = extend.right))
if obshowactivity
bin.bx.unshift(box.new (top = id.top, bottom = id.avg, left = id.loc ,
right = id.xlocbl, border_color = na , bgcolor = obactup, xloc =
xloc.bar_time))
bin.bx.unshift(box.new (top = id.avg, bottom = id.btm, left = id.loc ,
right = id.xlocbr, border_color = na , bgcolor = obactdn, xloc =
xloc.bar_time))
if showline
bin.ln.unshift(line.new(
x1 = id.loc
, x2 = time
, 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>()
seq = math.min(oblast - 1, full.size() - 1)
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)
)
ids = full.get(y)
bin.lb.unshift(label.new(
bar_index - 1
, ids.avg
, textcolor = color.new(ids.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)) + "%)"
)
)
else
bin.bx.unshift(box .new(top = fvg.top , bottom = fvg.btm, left = fvg.loc
, right = fvg.bbloc , border_color = na
, bgcolor = bull ? fvg_upcss : fvg_dncss, xloc = xloc.bar_time))
bin.bx.unshift(box .new(top = fvg.top , bottom = fvg.btm, left = fvg.bbloc
, right = time , border_color = bull ? fvg_dncss : fvg_upcss
, bgcolor = bull ? fvg_dncss : fvg_upcss, xloc = xloc.bar_time, extend = ext))
if fvgline
bin.ln.unshift(line.new(x1 = fvg.loc , x2 = fvg.bbloc , y1 =
math.avg(fvg.top, fvg.btm), y2 = math.avg(fvg.top, fvg.btm), color = color.new(bull
? fvg_upcss : fvg_dncss, 0) , xloc =
xloc.bar_time))
bin.ln.unshift(line.new(x1 = fvg.bbloc, x2 = time , y1 =
math.avg(fvg.top, fvg.btm), y2 = math.avg(fvg.top, fvg.btm), color = color.new(bull
? fvg_dncss : fvg_upcss, 0) , xloc =
xloc.bar_time, extend = ext, style = line.style_dashed))
//}
_
='
------------
–––––––––––––––––––––––––– FUNCTION
–––––––––––––––––––––––––––
------------
'//{
mapping() =>
var float up = na
var float dn = na
var float point = na
var int trend = 0
var int idx = na
var int sum = na
var int project = na
var chart.point[] charts = array.new<chart.point>()
if na(up)
up := high
idx := bar_index
if na(dn)
dn := low
idx := bar_index
if high > up
if trend == -1
id = IDMIDX(false, idx)
charts.unshift(
chart.point.from_time(
time[id]
, low [id]
)
)
idx := bar_index
point := low [id]
sum := time[id]
up := high
dn := low
project := time
trend := 1
if low < dn
if trend == 1
id = IDMIDX(true, idx)
charts.unshift(
chart.point.from_time(
time[id]
, high[id]
)
)
idx := bar_index
point := high[id]
sum := time[id]
up := high
dn := low
project := time
trend := -1
if barstate.islast
var line ln = na
var polyline pl = na
ln.delete()
pl.delete()
ln := na
pl := na
ln := line.new(
x1 = sum
, x2 = project
, y1 = point
, y2 = trend == 1 ? up : dn
, xloc = xloc.bar_time
, color = color.red
)
pl := polyline.new(
charts
, line_color = mappingcss
, xloc = xloc.bar_time
, line_style = mappingStyle.lstyle()
)
posLIQ() =>
ph = ta.pivothigh(high, 5, 5)
pl = ta.pivotlow (low , 5, 5)
if ph
lUp.set(0, ph)
if pl
lDn.set(0, pl)
if high > lUp.get(0) and close < lUp.get(0) and upallow and high > high[1]
bralerts.set(10, alert.new(true, "Bearish", "Liquidity Print\n"))
upallow := false
printup := true
if low < lDn.get(0) and close > lDn.get(0) and dnallow and low < low[1]
blalerts.set(10, alert.new(true, "Bullish", "Liquidity Print\n"))
dnallow := false
printdn := true
[printup, printdn]
dEHL() =>
var equalbuild[] bleqal = array.new<equalbuild>()
var equalbuild[] breqal = array.new<equalbuild>()
var equalname [] blname = array.new<equalname >()
var equalname [] brname = array.new<equalname >()
int pos = 2
float thresh = 0.1
switch ehlmode
"Short-Term" => pos := 2, thresh := 0.1
"Mid-Term" => pos := 6, thresh := 0.25
"Long-Term" => pos := 10, thresh := 0.5
switch
top =>
mx = math.max(top, w.pt)
mn = math.min(top, w.pt)
switch
mx < mn + atr * thresh =>
bleqal.unshift(
equalbuild.new(
w.t
, w.pt
, bar_index - pos
, top
, ehlupcs
, line.style_dotted
)
)
blname.unshift(
equalname.new(
int(math.avg(bar_index - pos, w.t))
, top
, "EQH"
, ehlupcs
, label.style_label_down
)
)
w.pt := top
w.t := bar_index - pos
btm =>
mx = math.max(btm, w.pb)
mn = math.min(btm, w.pb)
switch
mn > mx - atr * thresh =>
breqal.unshift(
equalbuild.new(
w.b
, w.pb
, bar_index - pos
, btm
, ehldowncs, line.style_dotted
)
)
brname.unshift(
equalname.new(
int(math.avg(bar_index - pos, w.b))
, btm
, "EQL"
, ehldowncs
, label.style_label_up
)
)
w.pb := btm
w.b := bar_index - pos
if barstate.islast
if bleqal.size() > 0
for i = 0 to bleqal.size() - 1
draw = bleqal.get(i)
labe = blname.get(i)
if i < 10
bin.ln.unshift(
line.new(
draw.x1
, draw.y1
, draw.x2
, draw.y2
, color = draw.css
, style = draw.style
)
)
bin.lb.unshift(
label.new(
x = labe.x
, y = labe.y
, color = #ffffff00
, style = labe.style
, textcolor = labe.css
, size = mstext.txSz()
, text = labe.txt
)
)
if breqal.size() > 0
for i = 0 to breqal.size() - 1
draw = breqal.get(i)
labe = brname.get(i)
if i < 10
bin.ln.unshift(
line.new(
draw.x1
, draw.y1
, draw.x2
, draw.y2
, color = draw.css
, style = draw.style
)
)
bin.lb.unshift(
label.new(
x = labe.x
, y = labe.y
, color = #ffffff00
, style = labe.style
, textcolor = labe.css
, size = mstext.txSz()
, text = labe.txt
)
)
if not sfpuse
h := high
h1 := high[1]
h2 := high[2]
l := low
l1 := low [1]
l2 := low [2]
c := close
v := volume
t := time
n := bar_index
t1 := time[1]
switch sfpfilter
"Trend Following" =>
switch ms.trend
1 => blPrint := true , brPrint := false
-1 => blPrint := false , brPrint := true
=> na
BLsfp.unshift(
SFP.new(
lg.min()
, tn.get(lg.indexof(lg.min()))
, ac.get(lg.indexof(lg.min()))
)
)
if lg.min() != l1
BLsfp.unshift(
SFP.new(
l1
, t1
, h1
)
)
else
BLsfp.unshift(
SFP.new(
l1
, t1
, h1
)
)
BRsfp.unshift(
SFP.new(
lg.max()
, tn.get(lg.indexof(lg.max()))
, ac.get(lg.indexof(lg.max()))
)
)
if lg.max() != h1
BRsfp.unshift(
SFP.new(
h1
, t1
, l1
)
)
else
BRsfp.unshift(
SFP.new(
h1
, t1
, l1
)
)
BLsfp.remove(i)
else
BLsfp.remove(i)
BRsfp.remove(i)
else
BRsfp.remove(i)
if barstate.islast
if sfpshow > 0 and BLlb.size() > 0
for i = 0 to math.min(sfpshow - 1, BLlb.size() - 1)
x = BLlb.get(i)
bin.lb.unshift(
label.new(
x = x.x
, y = x.y
, text = x.txt
, color = #ffffff00
, style = x.style
, size = size
, textcolor = x.css
, xloc = xloc.bar_time
)
)
if sfpshow > 0 and BLln.size() > 0 and BRln.size() > 0 and showdev
max = math.max(BLln.get(0).loc, BRln.get(0).loc)
use = math.max(BLln.get(0).loc, BRln.get(0).loc) == BLln.get(0).loc ?
BLln.get(0) : BRln.get(0)
bull = math.max(BLln.get(0).loc, BRln.get(0).loc) == BLln.get(0).loc ?
true : false
switch bull
false =>
bin.ln.unshift(line.new(x1 = use.x1, x2 = time, y1 = use.ancor
- 4.0 * (use.y - use.ancor), y2 = use.ancor - 4.0 * (use.y - use.ancor), xloc =
xloc.bar_time, color = chart.fg_color, style = devstyle.lstyle()))
bin.ln.unshift(line.new(x1 = use.x1, x2 = time, y1 = use.ancor
- 2.0 * (use.y - use.ancor), y2 = use.ancor - 2.0 * (use.y - use.ancor), xloc =
xloc.bar_time, color = devcss, style = devstyle.lstyle()))
bin.ln.unshift(line.new(x1 = use.x1, x2 = time, y1 = use.ancor
- 2.5 * (use.y - use.ancor), y2 = use.ancor - 2.5 * (use.y - use.ancor), xloc =
xloc.bar_time, color = devcss, style = devstyle.lstyle()))
if devfill
bin.lf.unshift(
linefill.new(
bin.ln.get(0)
, bin.ln.get(1)
, color = color.new(devcss, 90)
)
)
if devlvl
bin.lb.unshift(label.new(x = use.x1, y = use.ancor + 4.0 *
(use.ancor - use.y), text = str.tostring(4.0 * 100) + "%" + " (" +
str.tostring(math.round(use.ancor + 4.0 * (use.ancor - use.y), 2)) + ")", style =
label.style_label_right, textcolor = chart.fg_color, color = #ffffff00, size =
devsize.txSz(), xloc = xloc.bar_time))
bin.lb.unshift(label.new(x = use.x1, y = use.ancor + 2.0 *
(use.ancor - use.y), text = str.tostring(2.0 * 100) + "%" + " (" +
str.tostring(math.round(use.ancor + 2.0 * (use.ancor - use.y), 2)) + ")", style =
label.style_label_right, textcolor = devcss , color = #ffffff00, size =
devsize.txSz(), xloc = xloc.bar_time))
bin.lb.unshift(label.new(x = use.x1, y = use.ancor + 2.5 *
(use.ancor - use.y), text = str.tostring(2.5 * 100) + "%" + " (" +
str.tostring(math.round(use.ancor + 2.5 * (use.ancor - use.y), 2)) + ")", style =
label.style_label_right, textcolor = devcss , color = #ffffff00, size =
devsize.txSz(), xloc = xloc.bar_time))
true =>
bin.ln.unshift(line.new(x1 = use.x1, x2 = time, y1 = use.ancor
+ 4.0 * (use.ancor - use.y), y2 = use.ancor + 4.0 * (use.ancor - use.y), xloc =
xloc.bar_time, color = chart.fg_color, style = devstyle.lstyle()))
bin.ln.unshift(line.new(x1 = use.x1, x2 = time, y1 = use.ancor
+ 2.0 * (use.ancor - use.y), y2 = use.ancor + 2.0 * (use.ancor - use.y), xloc =
xloc.bar_time, color = devcss, style = devstyle.lstyle()))
bin.ln.unshift(line.new(x1 = use.x1, x2 = time, y1 = use.ancor
+ 2.5 * (use.ancor - use.y), y2 = use.ancor + 2.5 * (use.ancor - use.y), xloc =
xloc.bar_time, color = devcss, style = devstyle.lstyle()))
if devfill
bin.lf.unshift(
linefill.new(
bin.ln.get(0)
, bin.ln.get(1)
, color = color.new(devcss, 90)
)
)
if devlvl
bin.lb.unshift(label.new(x = use.x1, y = use.ancor + 4.0 *
(use.ancor - use.y), text = str.tostring(4.0 * 100) + "%" + " (" +
str.tostring(math.round(use.ancor + 4.0 * (use.ancor - use.y), 2)) + ")", style =
label.style_label_right, textcolor = chart.fg_color, color = #ffffff00, size =
devsize.txSz(), xloc = xloc.bar_time))
bin.lb.unshift(label.new(x = use.x1, y = use.ancor + 2.0 *
(use.ancor - use.y), text = str.tostring(2.0 * 100) + "%" + " (" +
str.tostring(math.round(use.ancor + 2.0 * (use.ancor - use.y), 2)) + ")", style =
label.style_label_right, textcolor = devcss, color = #ffffff00, size =
devsize.txSz(), xloc = xloc.bar_time))
bin.lb.unshift(label.new(x = use.x1, y = use.ancor + 2.5 *
(use.ancor - use.y), text = str.tostring(2.5 * 100) + "%" + " (" +
str.tostring(math.round(use.ancor + 2.5 * (use.ancor - use.y), 2)) + ")", style =
label.style_label_right, textcolor = devcss, color = #ffffff00, size =
devsize.txSz(), xloc = xloc.bar_time))
dFVG() =>
[h2, l2, c1, o1, c, o, h, l, h1, l1, fvatr] = ghl()
var FVG[] blFVG = array.new<FVG>()
var FVG[] brFVG = array.new<FVG>()
bool upfvg = false
bool dnfvg = false
float blth = l1 + (fvatr[1] * fvgthresh)
float brth = h1 - (fvatr[1] * fvgthresh)
cc = timeframe.change(fvg_tf)
switch
what_fvg == "FVG" or what_fvg == "Breakers" =>
if l > h2 and cc and c1 > blth
upfvg := true
if upfvg[1]
if blFVG.size() > 0
fvg = blFVG.get(0)
if fvg.israid == true and fvg.active == false
fvg.active := true
fvg.raidloc := na
fvg.raidx2 := na
fvg.raidy := na
fvg.raidcs := #ffffff00
blFVG.unshift(
FVG.new(
l [1]
, h2 [1]
, time[3]
, false
, na
)
)
if dnfvg[1]
if brFVG.size() > 0
fvg = brFVG.get(0)
if fvg.israid == true and fvg.active == false
fvg = brFVG.get(0)
fvg.active := true
fvg.active := true
fvg.raidloc := na
fvg.raidx2 := na
fvg.raidy := na
fvg.raidcs := #ffffff00
brFVG.unshift(
FVG.new(
l2 [1]
, h [1]
, time[3]
, false
, na
)
)
if blFVG.size() > 0
for [i, fvg] in blFVG
if not fvg.isbb
if fvg_src == "Close" ? math.min(c, o) < fvg.btm : fvg_src ==
"Wick" ? l < fvg.btm : fvg_src == "Avg" ? l < math.avg(fvg.top, fvg.btm) : na
blalerts.set(6, alert.new(true, "Bullish", "FVG Mitigated\n"))
fvg.isbb := true
fvg.bbloc := time
if what_fvg == "FVG"
blFVG.remove(i)
else
if (fvg_src == "Close" ? math.max(c, o) > fvg.top : fvg_src ==
"Wick" ? h > fvg.top : fvg_src == "Avg" ? h > math.avg(fvg.top, fvg.btm) : na) and
what_fvg == "Breakers"
blFVG.remove(i)
if brFVG.size() > 0
for [i, fvg] in brFVG
if not fvg.isbb
if (fvg_src == "Close" ? math.max(c, o) > fvg.top : fvg_src ==
"Wick" ? h > fvg.top : fvg_src == "Avg" ? h > math.avg(fvg.top, fvg.btm) : na)
bralerts.set(6, alert.new(true, "Bearish", "FVG Mitigated\n"))
fvg.isbb := true
fvg.bbloc := time
if what_fvg == "FVG"
brFVG.remove(i)
else
if (fvg_src == "Close" ? math.min(c, o) < fvg.btm : fvg_src ==
"Wick" ? l < fvg.btm : fvg_src == "Avg" ? l < math.avg(fvg.top, fvg.btm) : na) and
what_fvg == "Breakers"
brFVG.remove(i)
if fvgoverlap
overlapFVG(blFVG, brFVG)
if blFVG.size() > 0
fvg = blFVG.get(0)
if not fvg.isbb
if low < fvg.top
blalerts.set(8, alert.new(true, "Bullish", "Price Inside FVG\n"))
if brFVG.size() > 0
fvg = brFVG.get(0)
if not fvg.isbb
if high > fvg.btm
bralerts.set(8, alert.new(true, "Bearish", "Price Inside FVG\n"))
if dispraid
for [i, fvg] in blFVG
if not fvg.israid and not fvg.isbb
if low < fvg.top and close > fvg.top
fvg.israid := true
fvg.raidloc := time
fvg.raidx2 := time
fvg.raidy := low
fvg.raidcs := chart.fg_color
else
if low <= fvg.raidy and fvg.active == false and not fvg.isbb
blalerts.set(7, alert.new(true, "Bullish", "Raid Found\n"))
fvg.active := true
fvg.raidx2 := time
else
if fvg.active == false and not fvg.isbb
fvg.raidx2 := time
if barstate.islast
if blFVG.size() > 0 and fvg_num > 0
for i = 0 to math.min(fvg_num - 1, blFVG.size() - 1)
fvg = blFVG.get(i)
dispFVG(fvg, i, true)
structure(color upcss, color dncss, bool draw, bool internal, int limit) =>
var structure ms = structure.new(start = 0)
var ob [] blob = array.new< ob >()
var ob [] brob = array.new< ob >()
var drawms [] bldw = array.new< drawms >()
var drawms [] brdw = array.new< drawms >()
var sellbuyside[] sellside = array.new<sellbuyside>()
var sellbuyside[] buyside = array.new<sellbuyside>()
bool crossup = false
bool crossdn = false
var float up = na
var float dn = na
idbull = ms.find(false, false, true)
idbear = ms.find(true , false, true)
btmP = obmode == "Length" ? (high[idbear] - 1 * atr[idbear]) <
low [idbear] ? low [idbear] : (high[idbear] - 1 * atr[idbear]) : low [idbear]
topP = obmode == "Length" ? (low [idbull] + 1 * atr[idbull]) >
high[idbull] ? high[idbull] : (low [idbull] + 1 * atr[idbull]) : high[idbull]
atr = ta.atr (200)
buy = low + atr
sel = high - atr
ph = ta.pivothigh(high, mslen, mslen)
pl = ta.pivotlow (low , mslen, mslen)
var int [] phn = array.new< int >(1, na)
var int [] pln = array.new< int >(1, na)
var float[] php = array.new<float>(1, na)
var float[] plp = array.new<float>(1, na)
if internal
blob.clear()
brob.clear()
if ph
phn.unshift(bar_index[mslen])
php.unshift(high[mslen])
if pl
pln.unshift(bar_index[mslen])
plp.unshift(low[mslen])
if php.size() > 0
if high > php.get(0)
php.clear()
phn.clear()
if plp.size() > 0
if low < plp.get(0)
plp.clear()
pln.clear()
if na(up)
up := high
if na(dn)
dn := low
if high > up
up := high
dn := low
crossup := true
if low < dn
up := high
dn := low
crossdn := true
if ms.start == 0
ms := structure.new(bar_index, na, high, low , bar_index,
bar_index, 0, 1, na, bar_index)
if draw
bldw.unshift(drawms.new(time, time, high , "CHoCH" , upcss,
line.style_dashed))
brdw.unshift(drawms.new(time, time, low , "CHoCH" , dncss,
line.style_dashed))
ms.upsweep := false
ms.dnsweep := false
if ms.start == 1
switch
low <= ms.choch and close >= ms.choch and buildsweep =>
bralerts.set(2, alert.new(true, "Bearish", "CHoCH Sweep\n"))
ms.dnsweep := true
ms.choch := low
ms.xloc := bar_index
if draw
dw = brdw.get(0)
dw.x2 := time
dw.style := line.style_dotted
dw.txt := "x"
brdw.unshift(
drawms.new(
time
, time
, low
, "CHoCH"
, dncss
, line.style_dashed
)
)
high >= ms.bos and close <= ms.bos and buildsweep =>
blalerts.set(2, alert.new(true, "Bullish", "CHoCH Sweep\n"))
ms.upsweep := true
ms.bos := high
ms.xloc := bar_index
if draw
dw = bldw.get(0)
dw.x2 := time
dw.style := line.style_dotted
dw.txt := "x"
bldw.unshift(
drawms.new(
time
, time
, high
, "CHoCH"
, upcss
, line.style_dashed
)
)
close <= ms.choch =>
bralerts.set(0, alert.new(true, "Bearish", "CHoCH\n"))
ms.txt := "choch"
lc.start := true
lc.count := 0
blob.fnOB(true, topP, idbull)
ms.trend := -1
ms.choch := ms.bos
ms.bos := na
ms.start := 2
ms.loc := bar_index
ms.main := low
ms.temp := ms.loc
ms.xloc := bar_index
if draw
dw = brdw.get(0)
dw.x2 := time
dw.style := internal ? line.style_dashed : line.style_solid
if ms.start == 2
switch ms.trend
-1 =>
if low <= ms.main
ms.main := low
ms.temp := bar_index
if bar_index % mslen * 2 == 0
if not na(ms.bos) and msmode == "Adjusted Points" and
php.size() > 0
if php.get(0) < ms.choch
// ms.xloc := phn.get(0)
ms.choch := php.get(0)
ms.loc := phn.get(0)
ms.xloc := phn.get(0)
ms.temp := phn.get(0)
if draw
choch = bldw.get(0)
choch.x1 := time [bar_index - phn.get(0)]
choch.x2 := time
choch.y := php.get(0)
if na(ms.bos)
if crossup and close > open and close[1] > open[1]
ms.bos := ms.main
ms.loc := ms.temp
ms.xloc := ms.loc
if draw
brdw.unshift(
drawms.new(
time[bar_index - ms.loc]
, time
, low [bar_index - ms.loc]
, "BOS"
, dncss
, line.style_dashed
)
)
if draw
choch = bldw.get(0)
choch.x2 := time
switch
low <= ms.bos and close >= ms.bos and not na(ms.bos) and
buildsweep =>
bralerts.set(3, alert.new(true, "Bearish", "BOS Sweep\n"))
ms.dnsweep := true
ms.bos := low
if draw
dw = brdw.get(0)
dw.x2 := time
dw.style := line.style_dotted
dw.txt := "x"
brdw.unshift(
drawms.new(
time
, time
, low
, "BOS"
, dncss
, line.style_dashed
)
)
if showside
id = ms.find(true, true, true)
btm = (high[id] - atr[id]) > low[id] ? (high[id] -
atr[id]) : low[id]
sellside.unshift(
sellbuyside.new(
high[id]
, btm
, time[id]
, sidesidecss
, "Sell Side"
, volume[id]
)
)
brarea.normal := false
ms.xloc := bar_index
bralert
switch
high >= ms.choch and close <= ms.choch and buildsweep =>
blalerts.set(2, alert.new(true, "Bullish", "CHoCH Sweep\
n"))
ms.upsweep := true
ms.choch := high
ms.xloc := bar_index
if draw
dw = bldw.get(0)
dw.x2 := time
dw.style := line.style_dotted
dw.txt := "x"
bldw.unshift(
drawms.new(
time
, time
, high
, "CHoCH"
, upcss
, line.style_dashed
)
)
if showside
id = ms.find(false, true, true)
top = (low[id] + atr[id]) < high[id] ? (low[id] +
atr[id]) : high[id]
buyside.unshift(
sellbuyside.new(
low[id]
, top
, time[id]
, buysidecss
, "Buy Side"
, volume[id]
)
)
ms.xloc := bar_index
blarea.normal := false
1 =>
if high >= ms.main
ms.main := high
ms.temp := bar_index
if na(ms.bos)
if crossdn and close < open and close[1] < open[1]
ms.bos := ms.main
ms.loc := ms.temp
ms.xloc := ms.loc
if draw
bldw.unshift(
drawms.new(
time[bar_index - ms.loc]
, time
, high[bar_index - ms.loc]
, "BOS"
, upcss
, line.style_dashed
)
)
if bar_index % mslen * 2 == 0
if not na(ms.bos) and msmode == "Adjusted Points" and
plp.size() > 0
if plp.get(0) > ms.choch
// ms.xloc := pln.get(0)
ms.choch := plp.get(0)
ms.loc := pln.get(0)
ms.xloc := pln.get(0)
ms.temp := pln.get(0)
// ms.loc := pln.get(0)
if draw
choch = brdw.get(0)
choch.x1 := time [bar_index - pln.get(0)]
choch.x2 := time
choch.y := plp.get(0)
if draw
choch = brdw.get(0)
choch.x2 := time
switch
high >= ms.bos and close <= ms.bos and not na(ms.bos) and
buildsweep =>
blalerts.set(3, alert.new(true, "Bullish", "BOS Sweep\n"))
ms.upsweep := true
ms.bos := high
if draw
dw = bldw.get(0)
dw.x2 := time
dw.style := line.style_dotted
dw.txt := "x"
bldw.unshift(
drawms.new(
time
, time
, high
, "BOS"
, upcss
, line.style_dashed
)
)
if showside
id = ms.find(false, true, true)
top = (low[id] + atr[id]) < high[id] ? (low[id] +
atr[id]) : high[id]
buyside.unshift(
sellbuyside.new(
low[id]
, top
, time[id]
, buysidecss
, "Buy Side"
, volume[id]
)
)
ms.xloc := bar_index
blalert
switch
low <= ms.choch and close >= ms.choch and buildsweep =>
bralerts.set(2, alert.new(true, "Bearish", "CHoCH Sweep\
n"))
ms.dnsweep := true
ms.choch := low
ms.xloc := bar_index
if draw
dw = brdw.get(0)
dw.x2 := time
dw.style := line.style_dotted
dw.txt := "x"
brdw.unshift(
drawms.new(
time
, time
, low
, "CHoCH"
, dncss
, line.style_dashed
)
)
if showside
id = ms.find(true, true, true)
btm = (high[id] - atr[id]) > low[id] ? (high[id] -
atr[id]) : low[id]
sellside.unshift(
sellbuyside.new(
high[id]
, btm
, time[id]
, sidesidecss
, "Sell Side"
, volume[id]
)
)
ms.xloc := bar_index
if blob.size() > 0
ob = blob.get(0)
if low < ob.top
blalerts.set(5, alert.new(true, "Bullish", "Price Inside OB\n"))
if brob.size() > 0
ob = brob.get(0)
if high > ob.btm
bralerts.set(5, alert.new(true, "Bearish", "Price Inside OB\n"))
if showside
if buyside.size() > 0
side = buyside.get(0)
if low < side.btm
if blarea.normal == false
if brarea.normal == false
if sidemode == "Area"
bin.bx.unshift(
box.new(
top = side.top
, bottom = side.btm
, left = side.loc
, right = time
, border_color = na
, bgcolor = side.css
, xloc = xloc.bar_time
)
)
bin.ln.unshift(
line.new(
x1 = side.loc
, x2 = time
, y1 = side.top
, y2 = side.top
, xloc = xloc.bar_time
, color = color.new(side.css, 0)
, style = line.style_solid
)
)
bin.ln.unshift(
line.new(
x1 = bar_index
, x2 = bar_index + 10
, y1 = side.top
, y2 = side.top
, xloc = xloc.bar_index
, color = color.new(side.css, 0)
, style = line.style_dotted
)
)
bin.lb.unshift(
label.new(
x = bar_index
, y = side.top
, color = #ffffff00
, style = label.style_label_up
, textcolor = color.new(side.css, 0)
, size = mstext.txSz()
, text = "Buyside - " +
str.tostring(math.floor((side.vol / sum) * 100)) + "%"
)
)
if sellside.size() > 0
side = sellside.get(0)
float sum = side.vol
if buyside.size() > 0 and sellside.size() > 0
sum := buyside.get(0).vol + sellside.get(0).vol
if sidemode == "Area"
bin.bx.unshift(
box.new(
top = side.top
, bottom = side.btm
, left = side.loc
, right = time
, border_color = na
, bgcolor = side.css
, xloc = xloc.bar_time
)
)
bin.ln.unshift(
line.new(
x1 = side.loc
, x2 = time
, y1 = side.top
, y2 = side.top
, xloc = xloc.bar_time
, color = color.new(side.css, 0)
, style = line.style_solid
)
)
bin.ln.unshift(
line.new(
x1 = bar_index
, x2 = bar_index + 10
, y1 = side.top
, y2 = side.top
, xloc = xloc.bar_index
, color = color.new(side.css, 0)
, style = line.style_dotted
)
)
bin.lb.unshift(
label.new(
x = bar_index
, y = side.top
, color = #ffffff00
, style = label.style_label_down
, textcolor = color.new(side.css, 0)
, size = mstext.txSz()
, text = "Sellside - "+
str.tostring(math.floor((side.vol / sum) * 100)) + "%"
)
)
if blob.size() > 0
ob = blob.get(0)
if not ob.isbb
if low < ob.top
blalert
if blobenter.normal == false
blobenter.normal := true
else
if high > ob.btm
blalert
if blobenter.breaker == false
blobenter.breaker := true
if brob.size() > 0
ob = brob.get(0)
if not ob.isbb
if high > ob.btm
bralert
if brobenter.normal == false
brobenter.normal := true
else
if low < ob.top
bralert
if brobenter.breaker == false
brobenter.breaker := true
if blob.size() > 0
for [i, metric] in blob
metric.umt()
if brob.size() > 0
for [i, metric] in brob
metric.umt()
if barstate.islast
if blob.size() > 0
for i = 0 to math.min(oblast - 1, blob.size() - 1)
obs = blob.get(i)
display(obs, blob, i)
if brob.size() > 0
for i = 0 to math.min(oblast - 1, brob.size() - 1)
obs = brob.get(i)
display(obs, brob, i)
if msbubble
bin.lb.unshift(
label.new(
x = obj.x1
, y = obj.y
, xloc = xloc.bar_time
, color = color.new(obj.css, 80)
, style = label.style_circle
, size = size.tiny
)
)
for i = 0 to brdw.size() - 1
obj = brdw.get(i)
if i <= limit
bin.ln.unshift(
line.new(
x1 = obj.x1
, x2 = obj.x2
, y1 = obj.y
, y2 = obj.y
, color = obj.css
, style = obj.style
, xloc = xloc.bar_time
)
)
bin.lb.unshift(
label.new(
x = int(math.avg(bin.ln.get(0).get_x1(),
bin.ln.get(0).get_x2()))
, y = obj.y
, xloc = xloc.bar_time
, color = #ffffff00
, style = label.style_label_up
, textcolor = obj.css
, size = mstext.txSz()
, text = obj.txt
)
)
if msbubble
bin.lb.unshift(
label.new(
x = obj.x1
, y = obj.y
, xloc = xloc.bar_time
, color = color.new(obj.css, 80)
, style = label.style_circle
, size = size.tiny
)
)
ms
//}
_
='
------------
–––––––––––––––––––––––––– EXECUTION
–––––––––––––––––––––––––––
------------
'//{
structure ms = na
if windowsis
if (bar_index > last_bar_index - mswindow)
ms := structure(swingcssup , swingcssdn , showSwing , false, swingLimit)
if windowsis == false
ms := structure(swingcssup , swingcssdn , showSwing , false, swingLimit)
color css = na
switch ms.trend
-1 =>
if lc.count <= zonethresh
if high > ms.zz and close < ms.zz
lc.count := 0
if close > ms.zz
blalerts.set(11, alert.new(true, "Bullish", "Sweep Area\n"))
lc.start := false
lc.count := 0
float[] pp = array.new<float>()
for i = 0 to bar_index - ms.zn
pp.unshift(low[i])
1 =>
if lc.count <= zonethresh
if low < ms.zz and close > ms.zz
lc.count := 0
if close < ms.zz
bralerts.set(11, alert.new(true, "Bearish", "Sweep Area\n"))
lc.start := false
lc.count := 0
float[] pp = array.new<float>()
for i = 0 to bar_index - ms.zn
pp.unshift(high[i])
lc.count += 1
if fvg_enable
dFVG()
if ehlshow
dEHL()
if showMapping
mapping()
if lvl_daily
mtfphl(pdh, pdl, 'D', css_d, s_d)
if lvl_weekly
mtfphl(pwh, pwl, 'W', css_w, s_w)
if lvl_monthly
mtfphl(pmh, pml, 'M', css_m, s_m)
if lvl_quartely
mtfphl(pqh, pql, 'Q', css_q, s_q)
if lvl_yearly
mtfphl(pyh, pyl, 'Y', css_y, s_y)
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"
// phl.uV := volume[zonelen]
// if showhl
// line.delete(phl.top[1])
// phl.top := line.new(
// bar_index- zonelen
// , top
// , bar_index
// , top
// , color = swingcssdn)
// phl.topy := top
// phl.topx := bar_index - zonelen
// phl.tup := top
// phl.tupx := bar_index - zonelen
// line.set_xy1(
// phl.top
// , phl.tupx
// , phl.tup
// )
// line.set_xy2(
// phl.top
// , bar_index+ 20
// , phl.tup
// )
// label.set_x(
// lbl
// , bar_index+ 20
// )
// label.set_y(
// lbl
// , phl.tup
// )
// dnphl(trend) =>
// if btm
// phl.sbottomcross := true
// phl.txtdn := btm > phl.bottomy ? "LH" : "LL"
// phl.dV := volume[zonelen]
// if showhl
// line.delete(phl.bottom[1])
// phl.bottom := line.new(
// bar_index- 50
// , btm
// , bar_index
// , btm
// , color = swingcssup
// )
// phl.bottomy := btm
// phl.bottomx := bar_index- zonelen
// phl.tdn := btm
// phl.tdnx := bar_index- zonelen
// line.set_xy1(
// phl.bottom
// , phl.tdnx
// , phl.tdn
// )
// line.set_xy2(
// phl.bottom
// , bar_index+ 20
// , phl.tdn
// )
// label.set_x(
// lbl
// , bar_index+ 20
// )
// label.set_y(
// lbl
// , phl.tdn
// )
// midphl() =>
// if showpdzone
// avg = math.avg(phl.tdn, phl.tup)
// hqlzone() =>
// dZone.pbx.set_lefttop(int(math.max(phl.topx, phl.bottomx))
, phl.tup)
// dZone.pbx.set_rightbottom(bar_index+ 20 , 0.95 *
phl.tup + 0.05 * phl.tdn)
//}
// // _
='
// // ------------
// // –––––––––––––––––––––––––– ANYALERT
–––––––––––––––––––––––––––
// // ------------
'//{