Price Action 152

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 66

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.

0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/

//@version=5
indicator("[v1.5.2] Price Action + ICT Toolkit", "[v1.5.2] Price Action + ICT
Toolkit "
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)

//-----------------------------------------------------------------------------{
//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 (3
, "" , 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"])
show_mtf_str = input.bool (true
, "MTF Scanner" , inline = "9", group = "MARKET STRUCTURE"
, tooltip = "Display Multi-Timeframe Market Structure Trend Directions. Green =
Bullish. Red = Bearish")
show_eql = input.bool (false
, "Show EQH/EQL" , inline = "6", group = "MARKET STRUCTURE")
plotcandle_bool = input.bool (false
, "Plotcandle" , inline = "3", group = "MARKET STRUCTURE"
, tooltip = "Displays a cleaner colored candlestick chart in place of the default
candles. (requires hiding the current ticker candles)")
barcolor_bool = input.bool (false
, "Bar Color" , inline = "4", group = "MARKET STRUCTURE"
, tooltip = "Color the candle bodies according to market strucutre trend")

i_ms_up_BOS = input.color (#089981


, "" , inline = "2", group = "MARKET STRUCTURE")
i_ms_dn_BOS = input.color (#f23645
, "" , inline = "2", group = "MARKET STRUCTURE")
s_ms_up_BOS = input.color (#089981
, "" , inline = "1", group = "MARKET STRUCTURE")
s_ms_dn_BOS = input.color (#f23645
, "" , inline = "1", group = "MARKET STRUCTURE")

lvl_daily = input.bool (false


, "Day " , inline = "1", group = "HIGHS & LOWS MTF")
lvl_weekly = input.bool (false
, "Week " , inline = "2", group = "HIGHS & LOWS MTF")
lvl_monthly = input.bool (false
, "Month" , inline = "3", group = "HIGHS & LOWS MTF")
lvl_yearly = input.bool (false
, "Year " , inline = "4", group = "HIGHS & LOWS MTF")
css_d = input.color (color.blue
, "" , inline = "1", group = "HIGHS & LOWS MTF")
css_w = input.color (color.blue
, "" , inline = "2", group = "HIGHS & LOWS MTF")
css_m = input.color (color.blue
, "" , inline = "3", group = "HIGHS & LOWS MTF")
css_y = input.color (color.blue
, "" , inline = "4", group = "HIGHS & LOWS MTF")
s_d = input.string ('⎯⎯⎯'
, '' , inline = '1', group = 'HIGHS & LOWS MTF'
, options = ['⎯⎯⎯', '----', '····'])
s_w = input.string ('⎯⎯⎯'
, '' , inline = '2', group = 'HIGHS & LOWS MTF'
, options = ['⎯⎯⎯', '----', '····'])
s_m = input.string ('⎯⎯⎯'
, '' , inline = '3', group = 'HIGHS & LOWS MTF'
, options = ['⎯⎯⎯', '----', '····'])
s_y = input.string ('⎯⎯⎯'
, '' , inline = '4', group = 'HIGHS & LOWS MTF'
, options = ['⎯⎯⎯', '----', '····'])

ob_show = input.bool (true


, "Show Last " , inline = "1", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Display volumetric order blocks on the chart \n\n[Input] Ammount of
volumetric order blocks to show")
ob_num = input.int (5
, "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Orderblocks number", minval = 1, maxval = 10)
ob_metrics_show = input.bool (true
, "Internal Buy/Sell Activity" , inline = "2", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Display volume metrics that have formed the orderblock")
css_metric_up = input.color (color.new(#089981, 40)
, " " , inline = "2", group = "VOLUMETRIC ORDER BLOCKS")
css_metric_dn = input.color (color.new(#f23645 , 40)
, "" , inline = "2", group = "VOLUMETRIC ORDER BLOCKS")

ob_filter = input.string ("None"


, "Filtering " , inline = "d", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Filter out volumetric order blocks by BOS/CHoCH/CHoCH+", options =
["None", "BOS", "CHoCH", "CHoCH+"])
ob_mitigation = input.string ("Absolute"
, "Mitigation " , inline = "4", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Trigger to remove volumetric order blocks", options = ["Absolute",
"Middle"])
ob_pos = input.string
("Full" , "Positioning " , inline = "k", group =
"VOLUMETRIC ORDER BLOCKS" , tooltip = "Position of the Order Block\n[Full]
Cover the whole candle\n[Middle] Cover half candle\n[Accurate] Adjust to
volatility\n[Precise] Same as Accurate but more precise", options = ["Full",
"Middle", "Accurate", "Precise"])
use_grayscale = input.bool (false
, "Grayscale" , inline = "6", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Use gray as basic order blocks color")
use_show_metric = input.bool (true
, "Show Metrics" , inline = "7", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Show volume associated with the orderblock and his relevance")
obtxt = input.string("Normal" , "Metric Size"
, ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "8", group = "VOLUMETRIC
ORDER BLOCKS" )
use_middle_line = input.bool (true
, "Show Middle-Line" , inline = "9", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Show mid-line order blocks")
use_overlap = input.bool (true
, "Hide Overlap" , inline = "10", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Hide overlapping order blocks")
use_overlap_method = input.string ("Previous"
, "Overlap Method " , inline = "Z", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "[Recent] Preserve the most recent volumetric order blocks\n\
n[Previous] Preserve the previous volumetric order blocks", options = ["Recent",
"Previous"])
ob_bull_css = input.color (color.new(#089981 , 80)
, "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS")
ob_bear_css = input.color (color.new(#f23645 , 80)
, "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS")

show_acc_dist_zone = input.bool (false


, "" , inline = "1", group = "Accumulation And
Distribution")
zone_mode = input.string ("Fast"
, "" , inline = "1", group = "Accumulation And
Distribution" , tooltip = "[Fast] Find small zone pattern formation\n[Slow] Find
bigger zone pattern formation" ,options = ["Slow", "Fast"])
acc_css = input.color (color.new(#089981 , 60)
, "" , inline = "1", group = "Accumulation And
Distribution")
dist_css = input.color (color.new(#f23645 , 60)
, "" , inline = "1", group = "Accumulation And
Distribution")

show_lbl = input.bool (true


, "Show swing point" , inline = "1", group = "High and Low"
, tooltip = "Display swing point")
show_mtb = input.bool (true
, "Show High/Low/Equilibrium" , inline = "2", group = "High and Low"
, tooltip = "Display Strong/Weak High And Low and Equilibrium")
toplvl = input.color (color.rgb(255, 0, 0)
, "Premium Zone " , inline = "3", group = "High and Low")
midlvl = input.color
(color.gray , "Equilibrium Zone" , inline = "4",
group = "High and Low")
btmlvl = input.color (#089981
, "Discount Zone " , inline = "5", group = "High and Low")

fvg_enable = input.bool (false


, " " , inline = "1", group = "FAIR VALUE GAP"
, tooltip = "Display fair value gap")
what_fvg = input.string ("FVG"
, "" , inline = "1", group = "FAIR VALUE GAP"
, tooltip = "Display fair value gap", options = ["FVG", "VI", "OG"])
fvg_num = input.int (5
, "Show Last " , inline = "1a", group = "FAIR VALUE GAP"
, tooltip = "Number of fvg to show")
fvg_upcss = input.color (color.new(#089981, 80)
, "" , inline = "1", group = "FAIR VALUE GAP")
fvg_dncss = input.color (color.new(color.red , 80)
, "" , inline = "1", group = "FAIR VALUE GAP")
fvg_extend = input.int (10
, "Extend FVG" , inline = "2", group = "FAIR VALUE GAP"
, tooltip = "Extend the display of the FVG.")
fvg_src = input.string ("Close"
, "Mitigation " , inline = "3", group = "FAIR VALUE GAP"
, tooltip = "[Close] Use the close of the body as trigger\n\n[Wick] Use the extreme
point of the body as trigger", options = ["Close", "Wick"])
fvg_tf = input.timeframe (""
, "Timeframe " , inline = "4", group = "FAIR VALUE GAP"
, tooltip = "Timeframe of the fair value gap")
rsi_enable = input.bool (true
, "Enable RSI" , group = "RSI"
, tooltip = "Plot overbought and oversold price to bars")
rsi_src = close
rsi_overbought_src = close
rsi_oversold_src = close
rsi_length = input.int (14, minval=1
, title="Length" , group = "RSI")
rsi_overbought_length = input.int (70, minval=1
, title="Overbought " , inline="overbought"
, group = "RSI")
rsi_oversold_length = input.int (30, minval=1
, title="Oversold " , inline = "oversold"
, group = "RSI")
rsi_overbought_color = input.color (color.green
, "", inline = "overbought" , group = "RSI")
rsi_oversold_color = input.color (color.red
, "", inline = "oversold" , group = "RSI")
t = color.t (ob_bull_css)
invcol = color.new (color.white
, 100)

method txSz(string s) =>


out = switch s
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
out

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()

alerts blalert = alerts.new()


alerts bralert = alerts.new()

if p.isfound

p.period += 1

if p.period == 50

p.period := 0
p.found := "None"
p.isfound := false
p.bull := na

switch

b.c > b.o => boolean.set(green_candle, true)


b.c < b.o => boolean.set(red_candle , true)

f_zscore(src, lookback) =>

(src - ta.sma(src, lookback)) / ta.stdev(src, lookback)

var int iLen = internal_r_lookback


var int sLen = swing_r_lookback

vv = f_zscore(((close - close[iLen]) / close[iLen]) * 100,iLen)

if ms_mode == "Dynamic"

switch

vv >= 1.5 or vv <= -1.5 => iLen := 10


vv >= 1.6 or vv <= -1.6 => iLen := 9
vv >= 1.7 or vv <= -1.7 => iLen := 8
vv >= 1.8 or vv <= -1.8 => iLen := 7
vv >= 1.9 or vv <= -1.9 => iLen := 6
vv >= 2.0 or vv <= -2.0 => iLen := 5
=> iLen
var msline = array.new<line>(0)

iH = ta.pivothigh(high, iLen, iLen)


sH = ta.pivothigh(high, sLen, sLen)
iL = ta.pivotlow (low , iLen, iLen)
sL = ta.pivotlow (low , sLen, sLen)

hl () => [high, low]

[pdh, pdl] = request.security(syminfo.tickerid , 'D' , hl() , lookahead =


barmerge.lookahead_on)
[pwh, pwl] = request.security(syminfo.tickerid , 'W' , hl() , lookahead =
barmerge.lookahead_on)
[pmh, pml] = request.security(syminfo.tickerid , 'M' , hl() , lookahead =
barmerge.lookahead_on)
[pyh, pyl] = request.security(syminfo.tickerid , '12M', hl() , lookahead =
barmerge.lookahead_on)

lstyle(style) =>

out = switch style

'⎯⎯⎯' => line.style_solid


'----' => line.style_dashed
'····' => line.style_dotted

mtfphl(h, l ,tf ,css, pdhl_style) =>

var line hl = line.new(


na
, na
, na
, na
, xloc = xloc.bar_time
, color = css
, style = lstyle(pdhl_style)
)

var line ll = line.new(


na
, na
, na
, na
, xloc = xloc.bar_time
, color = css
, style = lstyle(pdhl_style)
)

var label lbl = label.new(


na
, na
, xloc = xloc.bar_time
, text = str.format('P{0}L', tf)
, color = invcol
, textcolor = css
, size = size.small
, style = label.style_label_left
)
var label hlb = label.new(
na
, na
, xloc = xloc.bar_time
, text = str.format('P{0}H', tf)
, color = invcol
, textcolor = css
, size = size.small
, style = label.style_label_left
)

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

extension = time + (time - time[1]) * 50

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

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_yearly

mtfphl(pyh , pyl , '12M', css_y, s_y)

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - 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))

isoverbought() => rsi > rsi_overbought_length


isoversold() => rsi < rsi_oversold_length
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Market Structure
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

method darkcss(color css, float factor, bool bull) =>

blue = color.b(css) * (1 - factor)


red = color.r(css) * (1 - factor)
green = color.g(css) * (1 - factor)

color.rgb(red, green, blue, 0)

method f_line(msDraw d, size, style) =>

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
)

if msline.size() >= 250

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
)

structure(bool mtf) =>

msDraw drw = na

bool isdrw = false


bool isdrwS = false

var color css = na


var color icss = na

var int itrend = 0


var int trend = 0

bool bull_ob = false


bool bear_ob = false

bool s_bull_ob = false


bool s_bear_ob = false

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>()
)

var ms sup = ms.new(


array.new<float>()
, array.new< int >()
, array.new<float>()
)

var ms sdn = ms.new(


array.new<float>()
, array.new< int >()
, array.new<float>()
)

switch show_swing_ms

"All" => boolean.set(s_BOS , true ), boolean.set(s_CHoCH, true ) ,


boolean.set(s_CHoCHP, true )
"CHoCH" => boolean.set(s_BOS , false), boolean.set(s_CHoCH, true ) ,
boolean.set(s_CHoCHP, false )
"CHoCH+" => boolean.set(s_BOS , false), boolean.set(s_CHoCH, false) ,
boolean.set(s_CHoCHP, true )
"BOS" => boolean.set(s_BOS , true ), boolean.set(s_CHoCH, false) ,
boolean.set(s_CHoCHP, false )
"None" => boolean.set(s_BOS , false), boolean.set(s_CHoCH, false) ,
boolean.set(s_CHoCHP, false )
=> na

switch show_internal_ms

"All" => boolean.set(i_BOS, true ), boolean.set(i_CHoCH, true ),


boolean.set(i_CHoCHP, true )
"CHoCH" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, true ),
boolean.set(i_CHoCHP, false)
"CHoCH+" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, false ),
boolean.set(i_CHoCHP, true )
"BOS" => boolean.set(i_BOS, true ), boolean.set(i_CHoCH, false ),
boolean.set(i_CHoCHP, false)
"None" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, false ),
boolean.set(i_CHoCHP, false)
=> na

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])

// INTERNAL BULLISH STRUCTURE


if up.p.size() > 0 and dn.l.size() > 1

if ta.crossover(b.c, up.p.first())

bool CHoCH = na
string txt = na

if itrend < 0

CHoCH := true

switch

not CHoCH =>

txt := "BOS"
css := i_ms_up_BOS

blalert.bos := true

if boolean.get(i_BOS) and mtf == false and na(drw)

isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, i_ms_up_BOS
, txt
, true
)

CHoCH =>

dn.l.first() > dn.l.get(1) ? blalert.chochplus : blalert.choch

txt := dn.l.first() > dn.l.get(1) ? "CHoCH+" :


"CHoCH"
css := i_ms_up_BOS.darkcss(0.25, true)

if (dn.l.first() > dn.l.get(1) ?


boolean.get(i_CHoCHP) : boolean.get(i_CHoCH)) and mtf == false and na(drw)

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

ob_filter == "None" =>


bull_ob := true
ob_filter == "BOS" and txt == "BOS" =>
bull_ob := true
ob_filter == "CHoCH" and txt == "CHoCH" =>
bull_ob := true
ob_filter == "CHoCH+" and txt == "CHoCH+" =>
bull_ob := true

itrend := 1
up.n.clear()
up.p.clear()

// INTERNAL BEARISH STRUCTURE


if dn.p.size() > 0 and up.l.size() > 1

if ta.crossunder(b.c, dn.p.first())

bool CHoCH = na
string txt = na

if itrend > 0

CHoCH := true

switch

not CHoCH =>


bralert.bos := true

txt := "BOS"
css := i_ms_dn_BOS

if boolean.get(i_BOS) and mtf == false and na(drw)

isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, i_ms_dn_BOS
, txt
, false
)

CHoCH =>

if up.l.first() < up.l.get(1)


bralert.chochplus := true
else
bralert.choch := true

txt := up.l.first() < up.l.get(1) ? "CHoCH+" :


"CHoCH"
css := i_ms_dn_BOS.darkcss(0.25, false)

if (up.l.first() < up.l.get(1) ?


boolean.get(i_CHoCHP) : boolean.get(i_CHoCH)) and mtf == false and na(drw)

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

ob_filter == "None" =>


bear_ob := true
ob_filter == "BOS" and txt == "BOS" =>
bear_ob := true
ob_filter == "CHoCH" and txt == "CHoCH" =>
bear_ob := true
ob_filter == "CHoCH+" and txt == "CHoCH+" =>
bear_ob := true

itrend := -1
dn.n.clear()
dn.p.clear()

// SWING BULLISH STRUCTURE


if sup.p.size() > 0 and sdn.l.size() > 1
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

if boolean.get(s_BOS) and mtf == false and na(drw)

isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, s_ms_up_BOS
, txt
, true
)

CHoCH =>

if sdn.l.first() > sdn.l.get(1)


blalert.chochplusswing := true
else
blalert.chochswing := true

txt := sdn.l.first() > sdn.l.get(1) ? "CHoCH+" :


"CHoCH"
icss := s_ms_up_BOS.darkcss(0.25, true)

if (sdn.l.first() > sdn.l.get(1) ?


boolean.get(s_CHoCHP) : boolean.get(s_CHoCH)) and mtf == false and na(drw)

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

ob_filter == "None" =>


s_bull_ob := true
ob_filter == "BOS" and txt == "BOS" =>
s_bull_ob := true
ob_filter == "CHoCH" and txt == "CHoCH" =>
s_bull_ob := true
ob_filter == "CHoCH+" and txt == "CHoCH+" =>
s_bull_ob := true

trend := 1
sup.n.clear()
sup.p.clear()

// SWING BEARISH STRUCTURE


if sdn.p.size() > 0 and sup.l.size() > 1

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

if boolean.get(s_BOS) and mtf == false and na(drw)

isdrwS := true
drw := msDraw.new(
sdn.n.first()
, sdn.p.first()
, s_ms_dn_BOS
, txt
, false
)

CHoCH =>

if sup.l.first() < sup.l.get(1)


bralert.chochplusswing := true
else
bralert.chochswing := true

txt := sup.l.first() < sup.l.get(1) ? "CHoCH+" :


"CHoCH"
icss := s_ms_dn_BOS.darkcss(0.25, false)

if (sup.l.first() < sup.l.get(1) ?


boolean.get(s_CHoCHP) : boolean.get(s_CHoCH)) and mtf == false and na(drw)

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

ob_filter == "None" =>


s_bear_ob := true
ob_filter == "BOS" and txt == "BOS" =>
s_bear_ob := true
ob_filter == "CHoCH" and txt == "CHoCH" =>
s_bear_ob := true
ob_filter == "CHoCH+" and txt == "CHoCH+" =>
s_bear_ob := true

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)

show_itrend5 = input(true, title="Show 5m")


show_itrend15 = input(true, title="Show 15m")
show_itrend30 = input(true, title="Show 30m")
show_itrend1H = input(true, title="Show 1H")
show_itrend4H = input(true, title="Show 4H")
show_itrend1D = input(true, title="Show 1D")
show_itrend1W = input(true, title="Show 1W")
show_itrend1M = input(true, title="Show 1M")

show_rsi = input(true, title="Show RSI")

// 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))
[_, _, _, itrend1M, _, _, _, _, _, _, _] = request.security("", "1M" ,
structure(true))

rsi_value = ta.rsi(close, rsi_length)


rsi_value_str = str.format("{0,number,#.##}", rsi_value)

if show_mtf_str

var tab = table.new(position = position.top_right, columns = 20, rows = 20,


bgcolor = na, frame_color = color.rgb(54, 58, 69, 0), frame_width = 1, border_color
= color.rgb(54, 58, 69, 100), border_width = 1)

// Table headers
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)
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)
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)
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)
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)
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)
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)
table.cell(tab, 0, 8, text = show_itrend1M ? "1M" : "", 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)
table.cell(tab, 0, 9, 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)

// Table data based on user preferences


if show_itrend5
table.cell(tab, 1, 1, text = itrend5 == 1 ? "BULLISH" : itrend5 == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend5 == 1 ? #089981 : itrend5 == -1 ? #ff0000 : color.gray, bgcolor
= chart.bg_color, text_font_family = font.family_monospace)
if show_itrend15
table.cell(tab, 1, 2, text = itrend15 == 1 ? "BULLISH" : itrend15 == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend15 == 1 ? #089981 : itrend15 == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_itrend30
table.cell(tab, 1, 3, text = itrend30 == 1 ? "BULLISH" : itrend30 == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend30 == 1 ? #089981 : itrend30 == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_itrend1H
table.cell(tab, 1, 4, text = itrend1H == 1 ? "BULLISH" : itrend1H == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend1H == 1 ? #089981 : itrend1H == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_itrend4H
table.cell(tab, 1, 5, text = itrend4H == 1 ? "BULLISH" : itrend4H == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend4H == 1 ? #089981 : itrend4H == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_itrend1D
table.cell(tab, 1, 6, text = itrend1D == 1 ? "BULLISH" : itrend1D == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend1D == 1 ? #089981 : itrend1D == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_itrend1W
table.cell(tab, 1, 7, text = itrend1W == 1 ? "BULLISH" : itrend1W == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend1W == 1 ? #089981 : itrend1W == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_itrend1M
table.cell(tab, 1, 8, text = itrend1M == 1 ? "BULLISH" : itrend1M == -1 ?
"BEARISH" : na, text_halign = text.align_center, text_size = size.normal,
text_color = itrend1M == 1 ? #089981 : itrend1M == -1 ? #ff0000 : color.gray,
bgcolor = chart.bg_color, text_font_family = font.family_monospace)
if show_rsi
table.cell(tab, 1, 9, text = rsi_value_str, text_halign =
text.align_center, text_size = size.normal, text_color = isoverbought() ? #ff0000 :
isoversold() ? #089981 : color.yellow, bgcolor = chart.bg_color, text_font_family =
font.family_monospace)

// Merged cells for pattern detection


table.cell(tab, 0, 11, text = "Detected Pattern", text_halign =
text.align_center, text_size = size.normal, text_color = color.silver, bgcolor =
chart.bg_color, text_font_family = font.family_monospace)
table.cell(tab, 0, 12, text = p.found, text_halign = text.align_center,
text_size = size.normal, text_color = na(p.bull) ? color.white : p.bull ? #089981 :
#ff0000, bgcolor = chart.bg_color, text_font_family = font.family_monospace)

table.merge_cells(tab, 0, 11, 1, 11)


table.merge_cells(tab, 0, 12, 1, 12)

var phl = Zphl.new(


na
, na
, label.new(na , na , color = invcol , textcolor = i_ms_dn_BOS , style =
label.style_label_down , size = size.tiny , text = "")
, label.new(na , na , color = invcol , textcolor = i_ms_up_BOS , style =
label.style_label_up , size = size.tiny , text = "")
, true
, true
, true
, true
, ""
, ""
, 0
, 0
, 0
, 0
, high
, low
, 0
, 0
, 0
, 0
, 0
, 0
, na
, na
)

zhl(len)=>

upper = ta.highest(len)
lower = ta.lowest(len)

var float out = 0


out := b.h[len] > upper ? 0 : b.l[len] < lower ? 1 : out[1]

top = out == 0 and out[1] != 0 ? b.h[len] : 0


btm = out == 1 and out[1] != 1 ? b.l[len] : 0

[top, btm]

[top , btm ] = zhl(sLen)


[itop, ibtm] = zhl(iLen)

upphl(trend) =>

var label lbl = label.new(


na
, na
, color = invcol
, textcolor = toplvl
, style = label.style_label_down
, size = size.small
)

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

phl.tup := math.max(high, phl.tup)


phl.tupx := phl.tup == high ? b.n : phl.tupx
phl.uV := phl.tup != phl.tup[1] ? b.v : phl.uV

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
)

dist = math.abs(phl.uV / (phl.uV + phl.dV)) * 100


label.set_text (lbl, trend < 0
? "Strong High | " + str.tostring(phl.uV, format.volume) + " (" +
str.tostring(math.round(dist,0)) + "%)"
: "Weak High | " + str.tostring(phl.uV, format.volume) + " (" +
str.tostring(math.round(dist,0)) + "%)")

dnphl(trend) =>
var label lbl = label.new(
na
, na
, color = invcol
, textcolor = btmlvl
, style = label.style_label_up
, size = size.small
)

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

phl.tdn := math.min(low, phl.tdn)


phl.tdnx := phl.tdn == low ? b.n : phl.tdnx
phl.dV := phl.tdn != phl.tdn[1] ? b.v : phl.dV

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
)

dist = math.abs(phl.dV / (phl.uV + phl.dV)) * 100


label.set_text (lbl, trend > 0
? "Strong Low | " + str.tostring(phl.dV, format.volume) + " (" +
str.tostring(math.round(dist,0)) + "%)"
: "Weak Low | " + str.tostring(phl.uV, format.volume) + " (" +
str.tostring(math.round(dist,0)) + "%)")

midphl() =>

avg = math.avg(phl.bottom.get_y2(), phl.top.get_y2())

var line l = line.new(


y1 = avg
, y2 = avg
, x1 = b.n - sLen
, x2 = b.n + 50
, color = midlvl
, style = line.style_solid
)

var label lbl = label.new(


x = b.n + 50
, y = avg
, text = "Equilibrium"
, style = label.style_label_left
, color = invcol
, textcolor = midlvl
, size = size.small
)

if barstate.islast

more = (phl.bottom.get_x1() + phl.bottom.get_x2()) > (phl.top.get_x1() +


phl.top.get_x2()) ? phl.top.get_x1() : phl.bottom.get_x1()
line.set_xy1(l , more , avg)
line.set_xy2(l , b.n + 50, avg)
label.set_x (lbl , b.n + 50 )
label.set_y (lbl , avg )
dist = math.abs((l.get_y2() - close) / close) * 100
label.set_text (lbl, "Equilibrium (" + str.tostring(math.round(dist,0)) +
"%)")

hqlzone() =>
if barstate.islast

var hqlzone dZone = hqlzone.new(


box.new(
na
, na
, na
, na
, bgcolor = color.new(toplvl, 70)
, border_color = na
)
, box.new(
na
, na
, na
, na
, bgcolor = color.new(midlvl, 70)
, border_color = na
)
, box.new(
na
, na
, na
, na
, bgcolor = color.new(btmlvl, 70)
, border_color = na
)

, label.new(na, na, text = "Premium" , color = invcol, textcolor =


toplvl, style = label.style_label_down, size = size.small)
, label.new(na, na, text = "Equilibrium", color = invcol, textcolor =
midlvl, style = label.style_label_left, size = size.small)
, label.new(na, na, text = "Discount" , color = invcol, textcolor =
btmlvl, style = label.style_label_up , size = size.small)
)

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)

dZone.ebx.set_lefttop(int(math.max(phl.topx, phl.bottomx)), 0.525 * phl.tup


+ 0.475 * phl.tdn)
dZone.ebx.set_rightbottom(b.n + 50 , 0.525 * phl.tdn
+ 0.475 * phl.tup)

dZone.lbx.set_lefttop(int(math.max(phl.topx, phl.bottomx)), 0.95 * phl.tdn


+ 0.05 * phl.tup)
dZone.lbx.set_rightbottom(b.n + 50
, phl.tdn)

dZone.plb.set_xy( int(math.avg(math.max(phl.topx, phl.bottomx), int(b.n +


50))) , phl.tup)
dZone.elb.set_xy( int(b.n + 50)
, math.avg(phl.tup, phl.tdn))
dZone.lbl.set_xy( int(math.avg(math.max(phl.topx, phl.bottomx), int(b.n +
50))) , phl.tdn)
if show_mtb

upphl (trend)
dnphl (trend)
hqlzone()

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - End
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Volumetric Order Block
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

method eB(box[] b, bool ext, color css, bool swing) =>


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) =>


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) =>

[cC, oO, hH, lL, vV] = request.security(


syminfo.tickerid
, ""

, [

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))
draw.ob .eB(false, use_grayscale ? color.new(color.gray, 90) : css,
swing)
draw.blB.eB(false, css_metric_up ,
swing)
draw.brB.eB(false, css_metric_dn ,
swing)
draw.eOB.eB(true , use_grayscale ? color.new(color.gray, 90) : css,
swing)

float pos = ob_pos == "Full"


? (bull ? high : low)
: ob_pos == "Middle"
? ohlc4
: ob_pos == "Accurate"
? hl2
: hl2

if cdn

obj.h.clear()
obj.l.clear()
obj.n.clear()

for i = 1 to math.abs((loc - b.n)) - 1

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

int rmP = use_overlap_method == "Recent" ? 1 : 0

if obj.avg.size() > 1

if bull

? obj.btm.first() < obj.top.get(1)


: obj.top.first() > obj.btm.get(1)
obj.wM .remove(rmP)
obj.cV .remove(rmP)
obj.dir .remove(rmP)
obj.top .remove(rmP)
obj.avg .remove(rmP)
obj.btm .remove(rmP)
obj.left .remove(rmP)
obj.blVP .remove(rmP)
obj.brVP .remove(rmP)

if barstate.isconfirmed

for x = 0 to ob_num - 1

tg = switch ob_mitigation
"Middle" => obj.avg
"Absolute" => bull ? obj.btm : obj.top

for [idx, pt] in tg

if (bull ? cC < pt : cC > pt)


obj.wM .remove(idx)
obj.cV .remove(idx)
obj.dir .remove(idx)
obj.top .remove(idx)
obj.avg .remove(idx)
obj.btm .remove(idx)
obj.left .remove(idx)
obj.blVP .remove(idx)
obj.brVP .remove(idx)

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()

for i = 0 to math.min(ob_num - 1, obj.avg.size() - 1)

dmL = draw.mL .get(i)


dOB = draw.ob .get(i)
dblB = draw.blB.get(i)
dbrB = draw.brB.get(i)
deOB = draw.eOB.get(i)

dOB.set_lefttop (obj.left .get(i) , obj.top.get(i))


deOB.set_lefttop (b.t , obj.top.get(i))
dOB.set_rightbottom (b.t , obj.btm.get(i))
deOB.set_rightbottom(b.t + (b.t - b.t[1]) * 100 , obj.btm.get(i))

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

dblB.set_lefttop (obj.left.get(i), obj.top.get(i))


dbrB.set_lefttop (obj.left.get(i), obj.avg.get(i))
dblB.set_rightbottom(obj.left.get(i), obj.avg.get(i))
dbrB.set_rightbottom(obj.left.get(i), obj.btm.get(i))

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

obj.cV.get(i) >= 1000000000 =>


str.tostring(math.round(obj.cV.get(i) / 1000000000,3)) + "B"
obj.cV.get(i) >= 1000000 =>
str.tostring(math.round(obj.cV.get(i) / 1000000,3)) + "M"
obj.cV.get(i) >= 1000 =>
str.tostring(math.round(obj.cV.get(i) / 1000,3)) + "K"
obj.cV.get(i) < 1000 =>
str.tostring(math.round(obj.cV.get(i)))

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 ob_metrics_show and barstate.isconfirmed

if obj.wM.size() > 0

for i = 0 to obj.avg.size() - 1

switch obj.dir.get(i)

1 =>

switch obj.wM.get(i)

1 => obj.blVP.set(i, obj.blVP.get(i) + 1),


obj.wM.set(i, 2)
2 => obj.blVP.set(i, obj.blVP.get(i) + 1),
obj.wM.set(i, 3)
3 => obj.brVP.set(i, obj.brVP.get(i) + 1),
obj.wM.set(i, 1)
-1 =>

switch obj.wM.get(i)

1 => obj.brVP.set(i, obj.brVP.get(i) + 1),


obj.wM.set(i, 2)
2 => obj.brVP.set(i, obj.brVP.get(i) + 1),
obj.wM.set(i, 3)
3 => obj.blVP.set(i, obj.blVP.get(i) + 1),
obj.wM.set(i, 1)

var hN = array.new<int>(1, b.n)


var lN = array.new<int>(1, b.n)
var hS = array.new<int>(1, b.n)
var lS = array.new<int>(1, b.n)

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
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

ghl() => request.security(syminfo.tickerid, fvg_tf, [high[2], low[2], close[1],


open[1]])
tfG() => request.security(syminfo.tickerid, fvg_tf, [open, high, low, close])

cG(bool bull) =>

[h, l, c, o] = ghl()
[go, gh, gl, gc] = tfG()

var FVG draw = FVG.new(


array.new<box>()
, array.new<line>()
)

var FVG[] cords = array.new<FVG>()

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

draw.box.unshift(box.new (na, na, na, na, border_color =


color.new(color.white, 100), xloc = xloc.bar_time))
draw.ln.unshift (line.new(na, na, na, na, xloc = xloc.bar_time, width =
1, style = line.style_solid))

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" =>

pup := bull ? b.l : gl[1]


pdn := bull ? gh[1] : gh
cdn := bull ? gl > gh[1] and cc : gh < gl[1] and cc
pos := 1

if not na(cdn) and cdn

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

for [idx, obj] in cords

if obj.bull ? b.c < obj.btm : b.c > obj.top

cords.remove(idx)

if barstate.islast

if cords.size() > 0
for i = math.min(fvg_num - 1, cords.size() - 1) to 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)

gln.set_xy1(left, math.avg(gbx.get_top(), gbx.get_bottom()))


gln.set_xy2(right, math.avg(gbx.get_top(), gbx.get_bottom()))
gln.set_color(gcd.bull ? fvg_upcss : fvg_dncss)

if fvg_enable

cG(true )
cG(false)

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - IDM
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

//---------------------------------------------------------------------------------
------------------------------------}
//Settings
//---------------------------------------------------------------------------------
------------------------------------{
len = input(50, 'CHoCH Detection Period')
shortLen = input(3, 'IDM Detection Period')

//Styling
bullCss = input(#030101, 'Bullish Elements', group = 'Style')
bearCss = input(#9b0000, 'Bearish Elements', group = 'Style')

showChoch = input(false, "Show CHoCH", group = 'Style')


showBos = input(false, "Show BOS", group = 'Style')

showIdm = input(false, "Show Inducements", inline = 'idm', group = 'Style')


idmCss = input(color.rgb(14, 4, 4), "", inline = 'idm', group = 'Style')

showSweeps = input(false, "Show Sweeps", inline = 'sweeps', group = 'Style')


sweepsCss = input(color.rgb(153, 0, 0), "", inline = 'sweeps', group = 'Style')

//---------------------------------------------------------------------------------
------------------------------------}
//Functions
//---------------------------------------------------------------------------------
------------------------------------{
//Swings detection/measurements
n = bar_index

swings(len)=>
var os = 0
var int mytopx = na
var int mybtmx = na
upper = ta.highest(len)
lower = ta.lowest(len)

os := high[len] > upper ? 0 : low[len] < lower ? 1 : os[1]

mytop = os == 0 and os[1] != 0 ? high[len] : na


mytopx := os == 0 and os[1] != 0 ? n[len] : mytopx

mybtm = os == 1 and os[1] != 1 ? low[len] : na


mybtmx := os == 1 and os[1] != 1 ? n[len] : mybtmx

[mytop, mytopx, mybtm, mybtmx]

//---------------------------------------------------------------------------------
------------------------------------}
//Swings
//---------------------------------------------------------------------------------
------------------------------------{
[mytop, mytopx, mybtm, mybtmx] = swings(len)
[smytop, smytopx, smybtm, smybtmx] = swings(shortLen)

var os = 0
var mytop_crossed = false
var mybtm_crossed = false

var float max = na


var float min = na

var int max_x1 = na


var int min_x1 = na

var float mytopy = na


var float mybtmy = na
var smytop_crossed = false
var smybtm_crossed = false

//---------------------------------------------------------------------------------
------------------------------------}
//CHoCH Detection
//---------------------------------------------------------------------------------
------------------------------------{
if mytop
mytopy := mytop
mytop_crossed := false
if mybtm
mybtmy := mybtm
mybtm_crossed := false

//Test for CHoCH


if close > mytopy and not mytop_crossed
os := 1
mytop_crossed := true
if close < mybtmy and not mybtm_crossed
os := 0
mybtm_crossed := true

//Display CHoCH
if os != os[1]
max := high
min := low
max_x1 := n
min_x1 := n
smytop_crossed := false
smybtm_crossed := false

if os == 1 and showChoch
line.new(mytopx, mytopy, n, mytopy, color = bullCss, style =
line.style_dashed)
label.new(int(math.avg(n, mytopx)), mytopy, 'CHoCH', color = color(na),
style = label.style_label_down, textcolor = bullCss, size = size.tiny)
else if showChoch
line.new(mybtmx, mybtmy, n, mybtmy, color = bearCss, style =
line.style_dashed)
label.new(int(math.avg(n, mybtmx)), mybtmy, 'CHoCH', color = color(na),
style = label.style_label_up, textcolor = bearCss, size = size.tiny)

smytopy = fixnan(smytop)
smybtmy = fixnan(smybtm)

//---------------------------------------------------------------------------------
------------------------------------}
//Bullish BOS
//---------------------------------------------------------------------------------
------------------------------------{
//IDM
if low < smybtmy and not smybtm_crossed and os == 1 and smybtmy != mybtmy
if showIdm
line.new(smybtmx, smybtmy, n, smybtmy, color = color.rgb(7, 3, 3), style =
line.style_dotted)
label.new(int(math.avg(n, smybtmx)), smybtmy, 'IDM', color = color(na),
style = label.style_label_up, textcolor = color.rgb(8, 5, 5), size = size.tiny)

smybtm_crossed := true

//BOS
if close > max and smybtm_crossed and os == 1
if showBos
line.new(max_x1, max, n, max, color = bullCss)
label.new(int(math.avg(n, max_x1)), max, 'BOS', color = color(na), style =
label.style_label_down, textcolor = bullCss, size = size.tiny)

smybtm_crossed := false

//---------------------------------------------------------------------------------
------------------------------------}
//Bearish BOS
//---------------------------------------------------------------------------------
------------------------------------{
//IDM
if high > smytopy and not smytop_crossed and os == 0 and smytopy != mytopy
if showIdm
line.new(smytopx, smytopy, n, smytopy, color = color.rgb(114, 0, 0), style
= line.style_dotted)
label.new(int(math.avg(n, smytopx)), smytopy, 'IDM', color = color(na),
style = label.style_label_down, textcolor = color.rgb(119, 0, 0), size = size.tiny)
smytop_crossed := true

//BOS
if close < min and smytop_crossed and os == 0
if showBos
line.new(min_x1, min, n, min, color = bearCss)
label.new(int(math.avg(n, min_x1)), min, 'BOS', color = color(na), style =
label.style_label_up, textcolor = bearCss, size = size.tiny)

smytop_crossed := false

//---------------------------------------------------------------------------------
------------------------------------}
//Sweeps
//---------------------------------------------------------------------------------
------------------------------------{
if high > max and close < max and os == 1 and n - max_x1 > 1 and showSweeps
line.new(max_x1, max, n, max, color = color.rgb(10, 6, 6), style =
line.style_dotted)
label.new(int(math.avg(n, max_x1)), max, 'x', color = color(na), style =
label.style_label_down, textcolor = color.rgb(5, 3, 3))

if low < min and close > min and os == 0 and n - min_x1 > 1 and showSweeps
line.new(min_x1, min, n, min, color = color.rgb(14, 6, 6), style =
line.style_dotted)
label.new(int(math.avg(n, min_x1)), min, 'x', color = color(na), style =
label.style_label_up, textcolor = color.rgb(3, 2, 2))

//Trailing max/min
max := math.max(high, max)
min := math.min(low, min)

if max > max[1]


max_x1 := n
if min < min[1]
min_x1 := n

//---------------------------------------------------------------------------------
------------------------------------}
//Extensions
//---------------------------------------------------------------------------------
------------------------------------{
var ext_choch = line.new(na,na,na,na, style = line.style_dashed)
var ext_bos = line.new(na,na,na,na)
var ext_idm = line.new(na,na,na,na, style = line.style_dotted, color = idmCss)

var ext_choch_lbl = label.new(na,na, 'CHoCH', color = color(na), size = size.tiny)


var ext_bos_lbl = label.new(na,na, 'BOS' , color = color(na), size = size.tiny)
var ext_idm_lbl = label.new(na,na, 'IDM' , color = color(na), size = size.tiny,
textcolor = idmCss)

if barstate.islast
if os == 1
ext_choch.set_xy1(mybtmx, mybtmy), ext_choch.set_xy2(n, mybtmy),
ext_choch.set_color(bearCss)
ext_choch_lbl.set_xy(n, mybtmy),
ext_choch_lbl.set_style(label.style_label_up), ext_choch_lbl.set_textcolor(bearCss)

ext_bos.set_xy1(max_x1, max), ext_bos.set_xy2(n, max),


ext_bos.set_color(bullCss)
ext_bos_lbl.set_xy(n, max), ext_bos_lbl.set_style(label.style_label_down),
ext_bos_lbl.set_textcolor(bullCss)

if not smybtm_crossed
ext_idm.set_xy1(smybtmx, smybtmy), ext_idm.set_xy2(n+15, smybtmy)
ext_idm_lbl.set_xy(n+15, smybtmy),
ext_idm_lbl.set_style(label.style_label_up)
ext_idm.set_color(idmCss), ext_idm_lbl.set_textcolor(idmCss)
else
ext_idm.set_color(na)
ext_idm_lbl.set_textcolor(na)
else
ext_choch.set_xy1(mytopx, mytopy), ext_choch.set_xy2(n, mytopy),
ext_choch.set_color(bullCss)
ext_choch_lbl.set_xy(n, mytopy),
ext_choch_lbl.set_style(label.style_label_down),
ext_choch_lbl.set_textcolor(bullCss)

ext_bos.set_xy1(min_x1, min), ext_bos.set_xy2(n, min),


ext_bos.set_color(bearCss)
ext_bos_lbl.set_xy(n, min), ext_bos_lbl.set_style(label.style_label_up),
ext_bos_lbl.set_textcolor(bearCss)

if not smytop_crossed
ext_idm.set_xy1(smytopx, smytopy), ext_idm.set_xy2(n+15, smytopy)
ext_idm_lbl.set_xy(n+15, smytopy),
ext_idm_lbl.set_style(label.style_label_down)
ext_idm.set_color(idmCss), ext_idm_lbl.set_textcolor(idmCss)
else
ext_idm.set_color(na)
ext_idm_lbl.set_textcolor(na)
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - Accumulation And Distribution
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

drawZone(int len) =>


var zone[] z = array.new<zone>()

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

zone_mode == "Slow" =>

if z.size() > 5

if z.get(0).c == -1 and z.get(1).c == 1 and z.get(2).c == -1 and


z.get(3).c == 1 and z.get(4).c == -1 and z.get(5).c == 1

if z.get(0).p > z.get(2).p and z.get(2).p > z.get(4).p

if z.get(1).p < z.get(3).p and z.get(3).p < z.get(5).p

blalert.zone := true

box.new(top = z.get(5).p, bottom = z.get(4).p, left =


z.get(5).t, right = z.get(0).t, bgcolor = acc_css, border_color =
color.new(color.white, 100), xloc = xloc.bar_time)
slice = array.new<chart.point>()

for i = 0 to 5

slice.unshift(z.get(i).points)

polyline.new(slice, xloc = xloc.bar_time, line_color =


color.new(acc_css, 0), line_width = 2)
p.found := "Accumulation Zone"
p.bull := true
p.isfound := true
p.period := 0
z.clear()

if z.size() > 5

if z.get(0).c == 1 and z.get(1).c == -1 and z.get(2).c == 1 and


z.get(3).c == -1 and z.get(4).c == 1 and z.get(5).c == -1

if z.get(0).p < z.get(2).p and z.get(2).p < z.get(4).p

if z.get(1).p > z.get(3).p and z.get(3).p > z.get(5).p

bralert.zone := true

box.new(top = z.get(5).p, bottom = z.get(4).p, left =


z.get(5).t, right = z.get(0).t, bgcolor = dist_css, border_color =
color.new(color.white, 100), xloc = xloc.bar_time)
slice = array.new<chart.point>()

for i = 0 to 5

slice.unshift(z.get(i).points)

polyline.new(slice, xloc = xloc.bar_time, line_color =


color.new(dist_css, 0), line_width = 2)
p.found := "Distribution Zone"
p.bull := false
p.isfound := true
p.period := 0
z.clear()

zone_mode == "Fast" =>

if z.size() > 3

if z.get(0).c == -1 and z.get(1).c == 1 and z.get(2).c == -1 and


z.get(3).c == 1

if z.get(0).p > z.get(2).p

if z.get(1).p < z.get(3).p

blalert.zone := true

box.new(top = z.get(3).p, bottom = z.get(2).p, left =


z.get(3).t, right = z.get(0).t, bgcolor = acc_css, border_color =
color.new(color.white, 100), xloc = xloc.bar_time)
slice = array.new<chart.point>()

for i = 0 to 3

slice.unshift(z.get(i).points)

polyline.new(slice, xloc = xloc.bar_time, line_color =


color.new(acc_css, 0), line_width = 2)
p.found := "Accumulation Zone"
p.bull := true
p.isfound := true
p.period := 0
z.clear()

if z.size() > 3

if z.get(0).c == 1 and z.get(1).c == -1 and z.get(2).c == 1 and


z.get(3).c == -1

if z.get(0).p < z.get(2).p

if z.get(1).p > z.get(3).p

bralert.zone := true

box.new(top = z.get(2).p, bottom = z.get(3).p, left =


z.get(3).t, right = z.get(0).t, bgcolor = dist_css, border_color =
color.new(color.white, 100), xloc = xloc.bar_time)
slice = array.new<chart.point>()
for i = 0 to 3

slice.unshift(z.get(i).points)

polyline.new(slice, xloc = xloc.bar_time, line_color =


color.new(dist_css, 0), line_width = 2)
p.found := "Distribution Zone"
p.bull := false
p.isfound := true
p.period := 0
z.clear()

if show_acc_dist_zone

drawZone(iLen)

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - EQH / EQL
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

dEHL() =>

var ehl w = ehl.new(0, 0, 0, 0)


top = ta.pivothigh(high, 1, 1)
btm = ta.pivotlow(low , 1, 1)
atr = ta.atr(200)

switch

top =>

mx = math.max(top, w.pt)
mn = math.min(top, w.pt)
switch

mx < mn + atr * 0.1 =>

var aZ = array.new<line>()
var aL = array.new<label>()

if aZ.size() > 50

aZ.pop().delete()
aL.pop().delete()

aZ.unshift(line.new(w.t, w.pt, b.n - 1, top, color =


i_ms_dn_BOS, style = line.style_dotted))
aL.unshift(label.new(int(math.avg(b.n - 1, w.t)), top, "EQH",
color = invcol, textcolor = i_ms_dn_BOS, style = label.style_label_down, size =
size.tiny))

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

mn > mx - atr * 0.1 =>

var aZ = array.new<line>()
var aL = array.new<label>()

if aZ.size() > 50

aZ.pop().delete()
aL.pop().delete()

aZ.unshift(line.new(w.b, w.pb, b.n - 1, btm, color =


i_ms_up_BOS, style = line.style_dotted))
aL.unshift(label.new(int(math.avg(b.n - 1, w.b)), btm, "EQL",
color = invcol, textcolor = i_ms_up_BOS, style = label.style_label_up, size =
size.tiny))

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

p_css := plotcandle_bool ? (css) : na


b_css := barcolor_bool ? (css) : na
w_css := plotcandle_bool ? color.rgb(120, 123, 134, 50) : na

plotcandle(open,high,low,close , color = p_css , wickcolor = w_css , bordercolor =


p_css , editable = false)
barcolor(b_css, editable = false)

//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - END
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}

//Trendlines

// User input for trendlines visibility


showTrendlines = input(false, "Show Trendlines", inline = "a", group = "SETTINGS")

trelen = input.int(5, "Period ", tooltip = "Lookback period", inline = "b", group =
"SETTINGS")
cup = input.color(#089981, "", "")
cdn = input.color(#ff0000, "", "")
space = input.float(2, "Padding", tooltip = "Padding distance", inline = "c", group
= "SETTINGS", step = 0.1)
shs = input.bool(false, "Show Breakouts", inline = "z", group = "SETTINGS")

ph = ta.pivothigh(high, trelen, trelen)


pl = ta.pivotlow(low, trelen, trelen)

type store
float src
int n

type draw
line[] upln
line[] dnln

var store[] upbin = array.new<store>()


var store[] dnbin = array.new<store>()

var draw d = draw.new(array.new<line>(), array.new<line>())

atr = ta.atr(200)

method slope(line ln) =>


x = ln.get_x2() - ln.get_x1()
y = ln.get_y2() - ln.get_y1()
y / x

vol() =>
math.min(atr * 0.1, close * (0.1 / 100))

var bool broken = false


color active = na
bool plup = false
bool pldn = false

if ph
bool remove = false
var bool valid = false

upbin.unshift(store.new(b.h[trelen], b.n[trelen]))
if upbin.size() > 1
current = upbin.get(0)
before = upbin.get(1)
if current.src < before.src
if broken
valid := true
else
valid := false
if upbin.size() > 3
pastold = upbin.get(3)
pastcur = upbin.get(2)
now = upbin.get(1)
late = upbin.get(0)
if now.src < pastcur.src and now.src < pastold.src and late.src
< pastcur.src and late.src < pastold.src
valid := true
else
valid := false
else
valid := false

if valid
if showTrendlines
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src, y2 = current.src, color = cdn))
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src - vol() * space, y2 = current.src - vol() * space, color = cdn))
ln = d.upln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if low[i] > ln.get_y2()
remove := true
break

if remove
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln.clear()
upbin.clear()
broken := true
else
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln.clear()

d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =


before.src, y2 = current.src, color = cdn))
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src - vol() * space, y2 = current.src - vol() * space, color = cdn))
linefill.new(d.upln.get(0), d.upln.get(1), color =
color.new(cdn, 75))
upbin.clear()
broken := false

if d.upln.size() > 1

btm = d.upln.get(0)
top = d.upln.get(1)

if b.l > top.get_y2()


d.upln.clear()
broken := true
upbin.clear()
plup := true

if d.upln.size() > 1

slup = top.slope()
sldn = btm.slope()

top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)

btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)

if pl
bool remove = false
var bool valid = false

dnbin.unshift(store.new(b.l[trelen], b.n[trelen]))
if dnbin.size() > 1
current = dnbin.get(0)
before = dnbin.get(1)
if current.src > before.src
if broken
valid := true
else
valid := false
if dnbin.size() > 3
pastold = dnbin.get(3)
pastcur = dnbin.get(2)
now = dnbin.get(1)
late = dnbin.get(0)

if now.src > pastcur.src and now.src > pastold.src and late.src


> pastcur.src and late.src > pastold.src
valid := true
else
valid := false
else
valid := false

if valid
if showTrendlines
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src, y2 = current.src, color = cup))
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src + vol() * space, y2 = current.src + vol() * space, color = cup))

ln = d.dnln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if high[i] < ln.get_y2()
remove := true
break

if remove
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln.clear()
dnbin.clear()
broken := true
else
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln.clear()

d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =


before.src, y2 = current.src, color = cup))
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src + vol() * space, y2 = current.src + vol() * space, color = cup))

linefill.new(d.dnln.get(0), d.dnln.get(1), color =


color.new(cup, 75))
dnbin.clear()
broken := false

if d.dnln.size() > 1

btm = d.dnln.get(0)
top = d.dnln.get(1)

if b.h < btm.get_y2()


d.dnln.clear()
broken := true
dnbin.clear()
pldn := true

if d.dnln.size() > 1

slup = top.slope()
sldn = btm.slope()

top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)

btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)

plotshape(pldn and shs ? b.h[1] : na, "Breaking Down", shape.triangledown, location


= location.abovebar, color = cdn, offset = -1, size = size.tiny)
plotshape(plup and shs ? b.l[1] : na, "Breaking Up", shape.triangleup, location =
location.belowbar, color = cup, offset = -1, size = size.tiny)
const bool DEBUG = false
const int maxBoxesCount = 500
const int showLastXLiqs = 500
const int maxDistanceToLastBar = 5000 // Affects Running Time

// Killzones

//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{

disp = display.all - display.status_line

kzGR = 'Killzones'
asSH = input(true, '', inline = 'asia', group = kzGR)
asST = input.string('Asian', '', inline = 'asia', group = kzGR, display = disp)
asS = input.session('2000-0000', '', inline = 'asia', group = kzGR, display =
disp)
asC = input.color(color.new(#e91e63, 90), '', inline = 'asia', group = kzGR)

ldnOSH = input(true, '', inline = 'ldno', group = kzGR)


ldnOST = input.string('London', '', inline = 'ldno', group = kzGR, display = disp)
ldnOS = input.session('0200-0500', '', inline = 'ldno', group = kzGR, display =
disp)
ldnOC = input.color(color.new(#00bcd4, 90), '', inline = 'ldno', group = kzGR)

nySH = input(true, '', inline = 'nyam', group = kzGR)


nyST = input.string('New York AM', '', inline = 'nyam', group = kzGR, display =
disp)
nyS = input.session('0830-1100', '', inline = 'nyam', group = kzGR, display =
disp)
nyC = input.color(color.new(#ff5d00, 90), '', inline = 'nyam', group = kzGR)

ldnCSH = input(true, '', inline = 'nypm', group = kzGR)


ldnCST = input.string('New York PM', '', inline = 'nypm', group = kzGR, display =
disp)
ldnCS = input.session('1330-1600', '', inline = 'nypm', group = kzGR, display =
disp)
ldnCC = input.color(color.new(#2157f3, 90), '', inline = 'nypm', group = kzGR)

kzMML = input(true, 'Killzone Lines : Top/Bottom', inline = 'LN', group = kzGR)


kzML = input(false, 'Mean', inline = 'LN', group = kzGR)
kzLE = input(false, 'Extend Top/Bottom', inline = 'LN', group = kzGR)
kzLB = input(true, 'Killzone Labels', group = kzGR)
kzSH = input.int(15, 'Display Killzones within Timeframes Up To', options = [1,
3, 5, 15, 30, 45, 60], group = kzGR, display = disp)
dwmO = input.string('None', 'Open Price of', options = ['Killzones', 'the Day',
'the Week', 'the Month', 'None'], inline = 'OP', group = kzGR, display = disp)
dwmS = input.bool(false, 'Separator', inline = 'OP', group = kzGR)
dwmC = input(color.new(color.gray, 89), '', inline = 'OP', group = kzGR)
dwmL = input.bool(true, 'Label', inline = 'OP', group = kzGR)

//-----------------------------------------------------------------------------}
// User Defined Types
//-----------------------------------------------------------------------------{

type BB
box bxOB
box bxBB
bool ext = true
bool bb = false
int bbI = na
int lst = na

type swing
float y = na
int i = na
bool x = false

type pivotPoint
float h
int hi
bool hx

float l
int li
bool lx

type KZ
line lnT
line lnM
line lnB
line lnO
label lb
label lbO

type DWM
line ln
label lb

type MSS
line ln
box bx
//-----------------------------------------------------------------------------}
// Variables
//-----------------------------------------------------------------------------{

tfM = timeframe.multiplier

nyam = not na(time(timeframe.period, nyS , 'UTC-5')) and nySH and tfM <= kzSH
ldnO = not na(time(timeframe.period, ldnOS, 'UTC-5')) and ldnOSH and tfM <= kzSH
ldnC = not na(time(timeframe.period, ldnCS, 'UTC-5')) and ldnCSH and tfM <= kzSH
asian = not na(time(timeframe.period, asS , 'UTC-5')) and asSH and tfM <= kzSH

inKZ = nyam or ldnO or ldnC or asian


var KZ kz = KZ.new()

var DWM dwm = DWM.new()

var bLS = array.new_int()


var aLS = array.new_int()

var pivotPoint pp = pivotPoint.new()


var shift = 0

//-----------------------------------------------------------------------------}
// Functions / Methods
//-----------------------------------------------------------------------------{

method killzones(KZ _id, _s, _kz, _o, _h, _l, _c, _t, _cr, _tx, _mml, _ml, _lb,
_le, _ol, _olC, _olL, areaCss)=>
var float max = na, var float mid = na, var float min = na
var int sbT = na, var bool xt = na, var bool xb = na
var box area = na
var tC = color.rgb(color.r(_cr), color.g(_cr), color.b(_cr))

if _s and not _s[1]


max := _h
sbT := _t
min := _l
mid := math.avg(max, min)
area := box.new(bar_index, max, bar_index, min, na, bgcolor = areaCss)

if _mml
_id.lnT := line.new(sbT, max, sbT, max, xloc.bar_time, color = tC)//,
xt := true
_id.lnB := line.new(sbT, min, sbT, min, xloc.bar_time, color = tC)//,
xb := true

if _ml
_id.lnM := line.new(sbT, mid, sbT, mid, xloc.bar_time, color = tC,
style = line.style_dotted)
if _ol
_id.lnO := line.new(sbT, _o, sbT, _o, xloc.bar_time, color =
color.new(_olC, 0), style = line.style_dotted)

if _olL
_id.lbO := label.new(sbT, _o, 'KZO(' + str.tostring(_o,
format.mintick) + ')', xloc.bar_time, color = color(na), style =
label.style_label_left, textcolor = color.new(_olC, 0), size = size.tiny)

if _lb
_id.lb := label.new(sbT, max, _tx, xloc.bar_time, color = #ffffff00,
style = label.style_label_down, textcolor = tC, size = size.small)

if _s
max := math.max(_h, max)
min := math.min(_l, min)
mid := math.avg(max, min)
xt := true
xb := true

area.set_top(max)
area.set_rightbottom(bar_index, min)

if _lb
label.set_x(_id.lb, int(math.avg(_t, sbT))), label.set_y(_id.lb, max)

if _mml
_id.lnT.set_y1(max), _id.lnT.set_xy2(_t, max)
_id.lnB.set_y1(min), _id.lnB.set_xy2(_t, min)

if _ml
_id.lnM.set_y1(mid), _id.lnM.set_xy2(_t, mid)

if _ol
_id.lnO.set_x2(_t)

if _olL
_id.lbO.set_x(_t)

if not _s and _le and not _kz

if _mml
if xt
if _h < _id.lnT.get_y1()
_id.lnT.set_x2(_t)
else
_id.lnT.set_x2(_t)
xt := false

if xb
if _l > _id.lnB.get_y1()
_id.lnB.set_x2(_t)
else
_id.lnB.set_x2(_t)
xb := false

if _ml
_id.lnM.set_x2(_t)
method pDWM(DWM _id, _tC, _t, _o, _cl, _lbTX, _olL) =>
if _tC
_id.lb.delete()
_id.ln := line.new(_t, _o, _t, _o, xloc.bar_time, extend.none,
color.new(_cl, 0), line.style_dotted, 1)

if _olL
_id.lb := label.new(_t, _o, _lbTX + '(' + str.tostring(_o,
format.mintick) + ')', xloc.bar_time, yloc.price, color(na),
label.style_label_left, color.new(_cl, 0), size.tiny)
else
_id.ln.set_x2(_t)

if _olL
_id.lb.set_x(_t)
na

//-----------------------------------------------------------------------------}
// Calculations - Killzones
//-----------------------------------------------------------------------------{
kzO = dwmO == 'Killzones'

kz.killzones(nyam and timeframe.isintraday, inKZ, b.o, b.h, b.l, b.c, b.t,


nyC , nyST , kzMML, kzML, kzLB, kzLE, kzO, dwmC, dwmL, nyC)
kz.killzones(ldnO and timeframe.isintraday, inKZ, b.o, b.h, b.l, b.c, b.t, ldnOC,
ldnOST, kzMML, kzML, kzLB, kzLE, kzO, dwmC, dwmL, ldnOC)
kz.killzones(ldnC and timeframe.isintraday, inKZ, b.o, b.h, b.l, b.c, b.t, ldnCC,
ldnCST, kzMML, kzML, kzLB, kzLE, kzO, dwmC, dwmL, ldnCC)
kz.killzones(asian and timeframe.isintraday, inKZ, b.o, b.h, b.l, b.c, b.t, asC ,
asST , kzMML, kzML, kzLB, kzLE, kzO, dwmC, dwmL, asC)

[xChg, xTxt] = switch dwmO


'the Day' => [timeframe.change('D'), 'DO']
'the Week' => [timeframe.change('W'), 'WO']
'the Month' => [timeframe.change('M'), 'MO']

if not kzO and timeframe.isintraday and tfM <= kzSH


dwm.pDWM(xChg, b.t, b.o, dwmC, xTxt, dwmL)

bgcolor(dwmS and not kzO and timeframe.isintraday and tfM <= kzSH ? xChg ? dwmC :
na : na)

//-----------------------------------------------------------------------------}
// Calculations - Order Blocks & Breaker Blocks
//-----------------------------------------------------------------------------{
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(3, 'Contraction Detection Lookback', minval = 1)
liqLength = input.int(20, 'Liquidity Levels', minval = 1)

showMajor = input(false, 'Show Major Pattern')


showMinor = input(false, 'Show Minor Pattern')

//Style

showBullBox = input(false, 'Area', inline = 'bull', group = 'Pattern Style')


showBullLvl = input(false, 'Line', inline = 'bull', group = 'Pattern Style')

showBearBox = input(false, 'Area', inline = 'bear', group = 'Pattern Style')


showBearLvl = input(false, 'Line', inline = 'bear', group = 'Pattern Style')

//Liquidity Style
showLiq = input(false, 'Show Liquidity Levels', group = 'Liquidity')
bullLiqCss = input.color(color.rgb(0, 0, 0), 'Upper Liquidity', group =
'Liquidity')
bearLiqCss = input.color(color.rgb(158, 0, 0), 'Lower Liquidity', group =
'Liquidity')

//-----------------------------------------------------------------------------}
//UDT
//-----------------------------------------------------------------------------{
type mp
box area
line avg
bool breakup
bool breakdn

//-----------------------------------------------------------------------------}
//Detect contraction
//-----------------------------------------------------------------------------{
var phy = 0., var phx = 0, var pht = 0.
var ply = 0., var plx = 0, var plt = 0.

if ph
pht := math.sign(ph - phy)
phy := ph

if pht == -1 and plt == 1


top := ph
btm := ply
phx := n-length

if pl
plt := math.sign(pl - ply)
ply := pl

if pht == -1 and plt == 1


top := phy
btm := pl
plx := n-length

//-----------------------------------------------------------------------------}
//Set pattern
//-----------------------------------------------------------------------------{
var mp master = mp.new()

//Detect master pattern


isbull = high[length] > top and top > btm
isbear = low[length] < btm and top > btm

if isbull or isbear
css = isbull ? bullCss : bearCss

master.avg.set_x2(n-length)

val = math.avg(top, btm)

//Create new master pattern object


master := mp.new(
(isbull and showBullBox) or (isbear and showBearBox) ? box.new(math.max(phx,
plx), top, n-length, btm, na, bgcolor = showMinor ? color.new(css, 50) : na) : na
, (isbull and showBullLvl) or (isbear and showBearLvl) ? line.new(n-length,
val, n, val, color = showMinor ? css : na) : na
, isbull
, isbear)

top := na
btm := na

//Determine if pattern switch to major


if master.breakup
if low < master.area.get_bottom()
if not showMajor
master.area.delete()
master.avg.delete()
else
master.area.set_border_color(bullCss)
if not showMinor
master.area.set_bgcolor(color.new(bullCss, 50))
master.avg.set_color(bullCss)
else if master.breakdn
if high > master.area.get_top()
if not showMajor
master.area.delete()
master.avg.delete()
else
master.area.set_border_color(bearCss)
if not showMinor
master.area.set_bgcolor(color.new(bearCss, 50))
master.avg.set_color(bearCss)

//Set friction level x2 coordinate to current bar


if not na(master.avg)
master.avg.set_x2(n)

//-----------------------------------------------------------------------------}
//Liquidity levels
//-----------------------------------------------------------------------------{
var line liqup = na, var liqup_reach = false
var line liqdn = na, var liqdn_reach = false

liqph = ta.pivothigh(liqLength, liqLength)


liqpl = ta.pivotlow(liqLength, liqLength)

//Set upper liquidity


if liqph and showLiq
if not liqup_reach
liqup.set_x2(n-liqLength)

liqup := line.new(n-liqLength, liqph, n, liqph, color = bullLiqCss, style =


line.style_dotted)
liqup_reach := false
else if not liqup_reach and showLiq
liqup.set_x2(n)

if high > liqup.get_y1()


liqup_reach := true

//Set lower liquidity


if liqpl and showLiq
if not liqdn_reach
liqdn.set_x2(n-liqLength)

liqdn := line.new(n-liqLength, liqpl, n, liqpl, color = bearLiqCss, style =


line.style_dotted)
liqdn_reach := false
else if not liqdn_reach and showLiq
liqdn.set_x2(n)

if low < liqdn.get_y1()


liqdn_reach := true

//-----------------------------------------------------------------------------}

// Internal Bullish
bool i_bull_bos = input.bool(false, "I - Bullish BOS ", inline = 'Bull BOS',
group = 'MARKET STRUCTURES ANY ALERT()')
bool i_bull_choch = input.bool(false, "I - Bullish CHoCH ", inline = 'Bull
CHoCH', group = 'MARKET STRUCTURES ANY ALERT()')
bool i_bull_chochp = input.bool(false, "I - Bullish CHoCH+ ", inline = 'Bull
CHoCH+', group = 'MARKET STRUCTURES ANY ALERT()')
var bool bl_alert_fvg = input(false, "Bullish FVG", inline = 'Bull FVG', group =
'MARKET STRUCTURES ANY ALERT()')
var bool bl_alert_ob = input(false, "I - Bullish OB", inline = 'Bull OB', group =
'MARKET STRUCTURES ANY ALERT()')
var bool bl_alert_swingob = input(false, "S - Bullish OB", inline = 'Bull OB',
group = 'MARKET STRUCTURES ANY ALERT()')
var bool bl_alert_zone = input(false, "Accumulation Zone", inline = 'Bull FVG',
group = 'MARKET STRUCTURES ANY ALERT()')
var bool bl_alert_obtouch = input(false, "Candle Inside Bullish OB ", inline =
'Bull OB', group = 'MARKET STRUCTURES ANY ALERT()')
// Swing Bullish
bool s_bull_bos = input.bool(false, "S - Bullish BOS", inline = 'Bull BOS',
group = 'MARKET STRUCTURES ANY ALERT()')
bool s_bull_choch = input.bool(false, "S - Bullish CHoCH", inline = 'Bull CHoCH',
group = 'MARKET STRUCTURES ANY ALERT()')
bool s_bull_chochp = input.bool(false, "S - Bullish CHoCH+", inline = 'Bull
CHoCH+', group = "MARKET STRUCTURES ANY ALERT()")

// Internal Bearish
bool i_bear_bos = input.bool(false, "I - Bearish BOS ", inline = 'Bear BOS',
group = 'MARKET STRUCTURES ANY ALERT()')
bool i_bear_choch = input.bool(false, "I - Bearish CHoCH ", inline = 'Bear
CHoCH', group = 'MARKET STRUCTURES ANY ALERT()')
bool i_bear_chochp = input.bool(false, "I - Bearish CHoCH+ ", inline = 'Bear
CHoCH+', group = 'MARKET STRUCTURES ANY ALERT()')
var bool br_alert_fvg = input(false, "Bearish FVG", inline = 'Bear FVG', group =
'MARKET STRUCTURES ANY ALERT()')
var bool br_alert_ob = input(false, "I - Bearish OB", inline = 'Bear OB', group =
'MARKET STRUCTURES ANY ALERT()')
var bool br_alert_swingob = input(false, "S - Bearish OB", inline = 'Bear OB',
group = 'MARKET STRUCTURES ANY ALERT()')
var bool br_alert_zone = input(false, "Distribution Zone", inline = 'Bear FVG',
group = 'MARKET STRUCTURES ANY ALERT()')
var bool br_alert_obtouch = input(false, "Candle Inside Bearish OB", inline = 'Bear
OB', group = 'MARKET STRUCTURES ANY ALERT()')

// Swing Bearish
bool s_bear_bos = input.bool(false, "S - Bearish BOS", inline = 'Bear BOS',
group = 'MARKET STRUCTURES ANY ALERT()')
bool s_bear_choch = input.bool(false, "S - Bearish CHoCH", inline = 'Bear CHoCH',
group = 'MARKET STRUCTURES ANY ALERT()')
bool s_bear_chochp = input.bool(false, "S - Bearish CHoCH+", inline = 'Bear
CHoCH+', group = 'MARKET STRUCTURES ANY ALERT()')

bool showEQL = input.bool(false, "Show EQL", inline = 'Equal', group = 'MARKET


STRUCTURES ANY ALERT()')
bool showEQH = input.bool(false, "Show EQH", inline = 'Equal', group = 'MARKET
STRUCTURES ANY ALERT()')

//-----------------------------------------------------------------------------}
// Alerts
//-----------------------------------------------------------------------------{
var bool any_condition_triggered = false

// Combined Bullish Condition


bool anyBullishCondition = blalert.bos or blalert.choch or blalert.chochplus or
blalert.swingbos or blalert.chochswing or blalert.chochplusswing

// Combined Bearish Condition


bool anyBearishCondition = bralert.bos or bralert.choch or bralert.chochplus or
bralert.swingbos or bralert.chochswing or bralert.chochplusswing

// Combined Equal High/Low Condition


bool anyEqualCondition = (blalert.equal and showEQL) or (bralert.equal and showEQH)
if (br_alert_fvg)
any_condition_triggered := any_condition_triggered or bralert.fvg
if (bl_alert_ob)
any_condition_triggered := any_condition_triggered or blalert.ob
if (bl_alert_swingob)
any_condition_triggered := any_condition_triggered or blalert.swingob
if (bl_alert_zone)
any_condition_triggered := any_condition_triggered or blalert.zone
if (bl_alert_obtouch)
any_condition_triggered := any_condition_triggered or blalert.obtouch

if (br_alert_ob)
any_condition_triggered := any_condition_triggered or bralert.ob
if (br_alert_swingob)
any_condition_triggered := any_condition_triggered or bralert.swingob
if (br_alert_zone)
any_condition_triggered := any_condition_triggered or bralert.zone
if (br_alert_obtouch)
any_condition_triggered := any_condition_triggered or bralert.obtouch
// Any Alert Condition
bool anyAlertCondition = (blalert.bos and i_bull_bos) or
(blalert.choch and i_bull_choch) or
(blalert.chochplus and i_bull_chochp) or
(blalert.swingbos and s_bull_bos) or
(blalert.chochswing and s_bull_choch) or
(blalert.chochplusswing and s_bull_chochp) or
(bralert.bos and i_bear_bos) or
(bralert.choch and i_bear_choch) or
(bralert.chochplus and i_bear_chochp) or
(bralert.swingbos and s_bear_bos) or
(bralert.chochswing and s_bear_choch) or
(bralert.chochplusswing and s_bear_chochp) or
(blalert.equal and showEQL) or
(bralert.equal and showEQH)

// Implementing the AnyALert() Function


alertcondition(anyAlertCondition, title ="Any Alert()", message="A market
structure event has occurred.")

alertcondition(anyBullishCondition, title = 'Any Bullish', message = 'A Bullish


structure has occured')

alertcondition(anyBearishCondition, title = 'Any Bearish', message = "A Bearish


structure has occured")

alertcondition(anyEqualCondition, title = 'Equal High/Low', message = "Equal


High/Low formed")

// Internal Bullish
alertcondition(blalert.bos , title = "Bullish BOS", message = "Bullish
BOS has occured")
alertcondition(blalert.choch , "Bullish CHOCH", "Bullish CHOCH has
occured")
alertcondition(blalert.chochplus , "Bullish CHOCH+", "Bullish CHOCH+ has
occured")

// Swing Bullish
alertcondition(blalert.swingbos , "Bullish Swing BOS", "Bullish Swing BOS
has occured")
alertcondition(blalert.chochswing , "Bullish Swing CHOCH", "Bullish CHOCH has
occured")
alertcondition(blalert.chochplusswing , "Bullish Swing CHOCH+", "Bullish Swing
CHOCH+ has occured")

// Internal Bearish
alertcondition(bralert.bos , "Bearish BOS", "Bearish BOS has occured")
alertcondition(bralert.choch , "Bearish CHOCH", "Bearish CHOCH has
occured")
alertcondition(bralert.chochplus , "Bearish CHOCH+", "Bearish CHOCH+ has
occured")

// Swing Bearish
alertcondition(bralert.swingbos , "Bearish Swing BOS", "Bearish Swing BOS
has occured")
alertcondition(bralert.chochswing , "Bearish Swing CHOCH", "Bearish CHOCH has
occured")
alertcondition(bralert.chochplusswing , "Bearish Swing CHOCH+", "Bearish Swing
CHOCH+ has occured")

// Equal High/Low
alertcondition(blalert.equal , "EQL", "Equal lows formed")
alertcondition(bralert.equal , "EQH", "Equal highs formed")

You might also like