GodSlayer Price Action Toolkit v1.6.3

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

// 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/
// GodSlayer
//@version=5
indicator("[v1.6.3] Price Action Toolkit", "[v1.6.3] Price Action Toolkit "
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)

max_bars_back = 500
max_labels_count = 500
max_lines_count = 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_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_rsi = input(true, title="Show RSI")
show_adx = input(true, title="Show ADX")
lookback = 499

show_sfp = input.bool(false, "Show Swing Failure Patern", group="MARKET STRUCTURE")


pvllen = input.int(25, "Pivot Length", 1, 99, group="MARKET STRUCTURE")
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_tf = input.timeframe("","Timeframe", inline = "b", group = "VOLUMETRIC
ORDER BLOCKS", tooltip="Enter Timeframe for Order Blocks ")
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 ("Precise"
, "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 (80, minval=1
, title="Overbought " , inline="overbought"
, group = "RSI")
rsi_oversold_length = input.int (20, minval=1
, title="Oversold " , inline = "oversold"
, group = "RSI")
rsi_overbought_color = input.color (#ff0000
, "", inline = "overbought" , group = "RSI")
rsi_oversold_color = input.color (#089981
, "", 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
}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - 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)

// ADX Function
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")

dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]

adx(dilen, adxlen) =>


[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//
{----------------------------------------------------------------------------------
------------------------------------------------------------}
//{ - 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

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

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

rsi_value = ta.rsi(close, rsi_length)


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

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


= #000000, frame_color = #000000, border_width = 1)

// Table headers
if show_itrend5 and show_mtf_str
table.cell(tab, 0, 1, text = show_itrend5 ? "5m" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend15 and show_mtf_str
table.cell(tab, 0, 2, text = show_itrend15 ? "15m" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend30 and show_mtf_str
table.cell(tab, 0, 3, text = show_itrend30 ? "30m" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend1H and show_mtf_str
table.cell(tab, 0, 4, text = show_itrend1H ? "1H" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend4H and show_mtf_str
table.cell(tab, 0, 5, text = show_itrend4H ? "4H" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend1D and show_mtf_str
table.cell(tab, 0, 6, text = show_itrend1D ? "1D" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_itrend1W and show_mtf_str
table.cell(tab, 0, 7, text = show_itrend1W ? "1W" : "", text_color =
color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor =
chart.bg_color, text_font_family = font.family_monospace, width = 4)
if show_rsi and show_mtf_str
table.cell(tab, 0, 8, text = show_rsi ? "RSI" : "", text_color = color.yellow,
text_halign = text.align_center, text_size = size.normal, bgcolor = chart.bg_color,
text_font_family = font.family_monospace, width = 4)

// Table data based on user preferences


if show_itrend5 and show_mtf_str
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 and show_mtf_str
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 and show_mtf_str
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 and show_mtf_str
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 and show_mtf_str
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 and show_mtf_str
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 and show_mtf_str
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_rsi and show_mtf_str
table.cell(tab, 1, 8, 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)
// ADX data
if show_adx and show_mtf_str
adx_value = adx(dilen, adxlen)
table.cell(tab, 0, 9, text="ADX", text_halign=text.align_center,
text_size=size.normal, text_color=#00e2ff, bgcolor=chart.bg_color,
text_font_family=font.family_monospace, width=4)
table.cell(tab, 1, 9, text=str.tostring(adx_value, "#.##"),
text_halign=text.align_center, text_size=size.normal, text_color=#00e2ff,
bgcolor=chart.bg_color, text_font_family=font.family_monospace)
// Merged cells for pattern detection
if show_mtf_str
table.cell(tab, 0, 10, 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, 11, 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, 10, 1, 10)


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

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, ob_tf) =>
b.unshift(
box.new(
na
, na
, na
, na
, xloc = xloc.bar_time
, extend = ext ? extend.right : extend.none
, border_color = swing ? color.new(css, 0) :
color.new(color.white,100)
, bgcolor = css
, border_width = 1
)
)

method eL(line[] l, bool ext, bool solid, color css, ob_tf) =>
l.unshift(
line.new(
na
, na
, na
, na
, width = 1
, color = css
, xloc = xloc.bar_time
, extend = ext ? extend.right : extend.none
, style = solid ? line.style_solid : line.style_dashed
)
)

method drawVOB(bool cdn, bool bull, color css, int loc, bool swing) =>

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


syminfo.tickerid
, ob_tf

, [
close
, open
, high
, low
, volume

, lookahead = barmerge.lookahead_off
)
var obC obj = obC.new(
array.new<float>()
, array.new<float>()
, array.new< int >()
, array.new<float>()
, array.new<float>()
, array.new<float>()
, array.new< int >()
, array.new< int >()
, array.new< int >()
, array.new< int >()
, array.new<float>()
, array.new<float>()
, array.new< int >()
)

var obD draw = obD.new(


array.new<box >()
, array.new<box >()
, array.new<box >()
, array.new<box >()
, array.new<line>()
)
if barstate.isfirst
for i = 0 to ob_num - 1
draw.mL.eL(false, false, use_grayscale ? color.new(color.gray, 0) :
color.new(css,0), ob_tf)
draw.ob.eB(false, use_grayscale ? color.new(color.gray, 90) : css,
swing, ob_tf)
draw.blB.eB(false, css_metric_up, swing, ob_tf)
draw.brB.eB(false, css_metric_dn, swing, ob_tf)
draw.eOB.eB(true, use_grayscale ? color.new(color.gray, 90) : css,
swing, ob_tf)

// Define variables to hold the data from request.security()


float high_tf = request.security(syminfo.tickerid, ob_tf, high,
lookahead=barmerge.lookahead_on)
float low_tf = request.security(syminfo.tickerid, ob_tf, low,
lookahead=barmerge.lookahead_on)
float ohlc4_tf = request.security(syminfo.tickerid, ob_tf, ohlc4,
lookahead=barmerge.lookahead_on)
float hl2_tf = request.security(syminfo.tickerid, ob_tf, hl2,
lookahead=barmerge.lookahead_on)

if barstate.isfirst
var table errorBox = table.new(position.bottom_right, 1, 1, bgcolor =
color.new(#363a45, 100))
table.cell(errorBox, 0, 0, "© God Slayer", text_color = color.gray,
text_halign = text.align_center, text_size = size.normal)

// Calculate 'pos' based on 'ob_pos' and the corresponding data from the 'ob_tf'
timeframe
float pos = na
if ob_pos == "Full"
pos := bull ? high_tf : low_tf
else if ob_pos == "Middle"
pos := ohlc4_tf
else if ob_pos == "Accurate"
pos := hl2_tf
else
pos := hl2_tf

if cdn

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

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

const bool DEBUG = false


const int maxBoxesCount = 500
const int showLastXLiqs = 500
const int maxDistanceToLastBar = 5000 // Affects Running Time

//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
BBGroup = "Breaker Blocks"
shZZ = false
len = input.int ( 5 ,
title=' Length' , inline='MS' , group=BBGroup
, minval=1, maxval=10
)
//VOLUMETRIC ORDER BLOCKS
BreakerCandleOnlyBody = input.bool ( false , title='Use only candle body'
, group=BBGroup )
BreakerCandle_2Last = input.bool ( false , title='Use 2 candles instead of 1'
, group=BBGroup, tooltip='In the same direction')
tillFirstBreak = input.bool ( true , title='Stop at first break of
center line' , group=BBGroup )
tpCss = #2157f3
//PD array
showBreaks = false
showSPD = true
PDtxtCss = color.silver
PDSCss = color.silver
Breaker = input.bool ( false , title='Hide Breaker Blocks' ,
group=BBGroup )

//Colors
cBBplusA = input.color (color.rgb(12, 181, 26, 93)
,
title=' ' , inline='bl' , group='Colours
+BB Last Swings' )
cBBplusB = input.color (color.rgb(12, 181, 26, 85)
,
title='' , inline='bl' , group='Colours
+BB Last Swings' )
cSwingBl = input.color (color.rgb(255, 82, 82, 85)
,
title=' ' , inline='bl' , group='Colours
+BB Last Swings' )
cBB_minA = input.color (color.rgb(255, 17, 0, 95)
,
title=' ' , inline='br' , group='Colours -
BB Last Swings' )
cBB_minB = input.color (color.rgb(255, 17, 0, 85)
,
title='' , inline='br' , group='Colours -
BB Last Swings' )
cSwingBr = input.color (color.rgb(0, 137, 123, 85)
,
title=' ' , inline='br' , group='Colours -
BB Last Swings' )

_arrowup = '▲'
_arrowdn = '▼'
_c = '●'
_x = '❌'

//-----------------------------------------------------------------------------}
//General Calculations
//-----------------------------------------------------------------------------{
per = last_bar_index - bar_index <= 2000
mx = math.max(close , open )
mn = math.min(close , open )
n = bar_index
hi = high
lo = low
mCxSize = 50

//-----------------------------------------------------------------------------}
//User Defined Types
//-----------------------------------------------------------------------------{
type ZZ
int [] d
int [] x
float [] y
line [] l
bool [] b

type mss
int dir
line [] l_mssBl
line [] l_mssBr
line [] l_bosBl
line [] l_bosBr
label[] lbMssBl
label[] lbMssBr
label[] lbBosBl
label[] lbBosBr

type block
int dir
bool Broken
bool Mitigated
box BB_boxA
box BB_boxB
line BB_line
box FVG_box
line line_1
line line_2
bool Broken_1
bool Broken_2
box PDa_boxA
box PDa_boxB
box PDa_box1
line PDaLine1
label PDaLab_1
box PDa_box2
line PDaLine2
label PDaLab_2
bool PDbroken1
bool PDbroken2
line TP1_line
line TP2_line
line TP3_line
bool TP1_hit
bool TP2_hit
bool TP3_hit
bool scalp
label HL
label[] aLabels

//-----------------------------------------------------------------------------}
//Variables
//-----------------------------------------------------------------------------{
BBplus = 0, signUP = 1, cnclUP = 2, LL1break = 3, LL2break = 4, SW1breakUP = 5
, SW2breakUP = 6, tpUP1 = 7, tpUP2 = 8, tpUP3 = 9, BB_endBl =10
BB_min =11, signDN =12, cnclDN =13, HH1break =14, HH2break =15, SW1breakDN =16
, SW2breakDN =17, tpDN1 =18, tpDN2 =19, tpDN3 =20, BB_endBr =21

signals =
array.from(
false // BBplus
, false // signUP
, false // cnclUP
, false // LL1break
, false // LL2break
, false // SW1breakUP
, false // SW2breakUP
, false // tpUP1
, false // tpUP2
, false // tpUP3
, false // BB_endBl
, false // BB_min
, false // signDN
, false // cnclDN
, false // HH1break
, false // HH2break
, false // SW1breakDN
, false // SW2breakDN
, false // tpDN1
, false // tpDN2
, false // tpDN3
, false // BB_endBr
)

var block [] aBlockBl = array.new< block >( )


var block [] aBlockBr = array.new< block >( )

var ZZ aZZ =
ZZ.new(
array.new < int >(mCxSize, 0),
array.new < int >(mCxSize, 0),
array.new < float >(mCxSize, na),
array.new < line >(mCxSize, na),
array.new < bool >(mCxSize, na))

var mss MSS = mss.new(


0
, array.new < line >()
, array.new < line >()
, array.new < line >()
, array.new < line >()
, array.new < label >()
, array.new < label >()
, array.new < label >()
, array.new < label >()
)

var block BB = block.new(


BB_boxA = box.new (na, na, na, na, border_color=color(na))
, BB_boxB = box.new (na, na, na, na, border_color=color(na)
, text_size=size.small
, text_halign=text.align_right
, text_font_family=font.family_monospace
)
, BB_line = line.new (na, na, na, na
, style=line.style_dashed
, color=color.silver
)
, PDa_box1 = box.new (na, na, na, na, border_color=color(na))
, PDaLine1 = line.new (na, na, na, na, color=PDSCss)
, PDaLab_1 = label.new(na, na, color=color(na))
, PDa_box2 = box.new (na, na, na, na, border_color=color(na))
, PDaLine2 = line.new (na, na, na, na, color=PDSCss)
, PDaLab_2 = label.new(na, na, color=color(na))
, line_1 = line.new (na, na, na, na, color=PDSCss)
, line_2 = line.new (na, na, na, na, color=PDSCss)

, HL = label.new(na, na, color=color(na)


, textcolor=PDtxtCss
, yloc=yloc.price
)
, aLabels = array.new<label>(1, label(na))
)

//-----------------------------------------------------------------------------}
//Functions/methods
//-----------------------------------------------------------------------------{
method in_out(ZZ aZZ, int d, int x1, float y1, int x2, float y2, color col, bool b)
=>
aZZ.d.unshift(d), aZZ.x.unshift(x2), aZZ.y.unshift(y2), aZZ.b.unshift(b),
aZZ.d.pop(), aZZ.x.pop(), aZZ.y.pop(), aZZ.b.pop()
if shZZ
aZZ.l.unshift(line.new(x1, y1, x2, y2, color= col)), aZZ.l.pop().delete()

method io_box(box[] aB, box b) => aB.unshift(b), aB.pop().delete()

method setLine(line ln, int x1, float y1, int x2, float y2) => ln.set_xy1(x1, y1),
ln.set_xy2(x2, y2)

method notransp(color css) => color.rgb(color.r(css), color.g(css), color.b(css))

createLab(string s, float y, color c, string t, string sz = size.small) =>


label.new(n
, y
, style=s == 'c' ? label.style_label_center
: s == 'u' ? label.style_label_up
: label.style_label_down
, textcolor=c
, color=color(na)
, size=sz
, text=t
)

draw(left, col) =>

max_bars_back(time, 1000)
var int dir= na, var int x1= na, var float y1= na, var int x2= na, var float
y2= na

sz = aZZ.d.size( )
x2 := bar_index -1
ph = ta.pivothigh(hi, left, 1)
pl = ta.pivotlow (lo, left, 1)
if ph
dir := aZZ.d.get (0)
x1 := aZZ.x.get (0)
y1 := aZZ.y.get (0)
y2 := nz(hi[1])

if dir < 1 // if previous point was a pl, add, and change direction ( 1)
aZZ.in_out( 1, x1, y1, x2, y2, col, true)
else
if dir == 1 and ph > y1
aZZ.x.set(0, x2), aZZ.y.set(0, y2)
if shZZ
aZZ.l.get(0).set_xy2(x2, y2)

if pl
dir := aZZ.d.get (0)
x1 := aZZ.x.get (0)
y1 := aZZ.y.get (0)
y2 := nz(lo[1])

if dir > -1 // if previous point was a ph, add, and change direction (-1)
aZZ.in_out(-1, x1, y1, x2, y2, col, true)
else
if dir == -1 and pl < y1
aZZ.x.set(0, x2), aZZ.y.set(0, y2)
if shZZ
aZZ.l.get(0).set_xy2(x2, y2)

iH = aZZ.d.get(2) == 1 ? 2 : 1
iL = aZZ.d.get(2) == -1 ? 2 : 1

switch
// MSS Bullish
close > aZZ.y.get(iH) and aZZ.d.get(iH) == 1 and MSS.dir < 1 and per =>

Ex = aZZ.x.get(iH -1), Ey = aZZ.y.get(iH -1)


Dx = aZZ.x.get(iH ), Dy = aZZ.y.get(iH ), DyMx = mx[n - Dx]
Cx = aZZ.x.get(iH +1), Cy = aZZ.y.get(iH +1)
Bx = aZZ.x.get(iH +2), By = aZZ.y.get(iH +2), ByMx = mx[n - Bx]
Ax = aZZ.x.get(iH +3), Ay = aZZ.y.get(iH +3), AyMn = mn[n - Ax]
_y = math.max(ByMx, DyMx)
mid = AyMn + ((_y - AyMn) / 2) // 50% fib A- min(B, D)
isOK = Breaker ? Ay < Cy and Ay < Ey and Ey < mid : true

float green1prT = na
float green1prB = na
float avg = na

if Ey < Cy and Cx != Dx and isOK


// latest HH to 1 HH further -> search first green bar
for i = n - Dx to n - Cx
if close[i] > open[i]
// reset previous swing box's
BB.PDa_box1.set_lefttop(na, na), BB.PDaLine1.set_xy1(na,
na), BB.PDaLab_1.set_xy(na, na)
BB.PDa_box2.set_lefttop(na, na), BB.PDaLine2.set_xy1(na,
na), BB.PDaLab_2.set_xy(na, na)

green1idx = n - i
green1prT := BreakerCandleOnlyBody ? mx[i] : high[i]
green1prB := BreakerCandleOnlyBody ? mn[i] : low [i]
if BreakerCandle_2Last
if close[i +1] > open[i +1]
green2prT = BreakerCandleOnlyBody ? mx[i +1] :
high[i +1]
green2prB = BreakerCandleOnlyBody ? mn[i +1] : low
[i +1]
if green2prT > green1prT or green2prB < green1prB
green1idx -= 1
green1prT := math.max(green1prT, green2prT)
green1prB := math.min(green1prB, green2prB)

// VOLUMETRIC ORDER BLOCKS +


avg := math.avg(green1prB, green1prT)
while BB.aLabels.size() > 0
BB.aLabels.pop().delete()
BB.PDa_boxA.delete(), BB.PDa_boxB.delete(), BB.dir := 1
BB.BB_boxA.set_left (green1idx)
BB.BB_boxA.set_top (green1prT)
BB.BB_boxA.set_right ( n )
BB.BB_boxA.set_bottom (green1prB)
BB.BB_boxA.set_bgcolor(cBBplusA )

BB.BB_boxB.set_left ( n )
BB.BB_boxB.set_top (green1prT)
BB.BB_boxB.set_right ( n + 8)
BB.BB_boxB.set_bottom (green1prB)
BB.BB_boxB.set_bgcolor(cBBplusB )
BB.BB_boxB.set_text('+BB')
BB.BB_boxB.set_text_color(cBBplusB.notransp())
BB.BB_boxB.set_text_valign(text.align_bottom)

BB.BB_line.set_xy1(n, avg), BB.BB_line.set_xy2(n , avg)

// Previous swings
cnt = 0, hh1 = high
for c = 0 to sz -2
getX = aZZ.x.get(c)
getY = aZZ.y.get(c)
if getY > hh1 and aZZ.d.get(c) == 1 and showSPD
getY2 = (high[n - getX] - mn[n - getX]) / 4

break

signals.set(BBplus, true)
alert('+BB', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, cBBplusB.notransp(),
_arrowup, size.large))

break
MSS.dir := 1

// MSS Bearish
close < aZZ.y.get(iL) and aZZ.d.get(iL) == -1 and MSS.dir > -1 and per =>
Ex = aZZ.x.get(iL -1), Ey = aZZ.y.get(iL -1)
Dx = aZZ.x.get(iL ), Dy = aZZ.y.get(iL ), DyMn = mn[n - Dx]
Cx = aZZ.x.get(iL +1), Cy = aZZ.y.get(iL +1)
Bx = aZZ.x.get(iL +2), By = aZZ.y.get(iL +2), ByMn = mn[n - Bx]
Ax = aZZ.x.get(iL +3), Ay = aZZ.y.get(iL +3), AyMx = mx[n - Ax]
_y = math.min(ByMn, DyMn)
//_x = _y == ByMn ? Bx : Dx
mid = AyMx - ((AyMx - _y) / 2) // 50% fib A- min(B, D)
isOK = Breaker ? Ay > Cy and Ay > Ey and Ey > mid : true
//
float red_1_prT = na
float red_1_prB = na
float avg = na
if Ey > Cy and Cx != Dx and isOK
// latest LL to LL further -> search first red bar
for i = n - Dx to n - Cx
if close[i] < open[i]
// reset previous swing box's
BB.PDa_box1.set_lefttop(na, na), BB.PDaLine1.set_xy1(na,
na), BB.PDaLab_1.set_xy(na, na)
BB.PDa_box2.set_lefttop(na, na), BB.PDaLine2.set_xy1(na,
na), BB.PDaLab_2.set_xy(na, na)

red_1_idx = n - i
red_1_prT := BreakerCandleOnlyBody ? mx[i] : high[i]
red_1_prB := BreakerCandleOnlyBody ? mn[i] : low [i]
if BreakerCandle_2Last
if close[i +1] < open[i +1]
red_2_prT = BreakerCandleOnlyBody ? mx[i +1] :
high[i +1]
red_2_prB = BreakerCandleOnlyBody ? mn[i +1] : low
[i +1]
if red_2_prT > red_1_prT or red_2_prB < red_1_prB
red_1_idx -= 1
red_1_prT := math.max(red_1_prT, red_2_prT)
red_1_prB := math.min(red_1_prB, red_2_prB)

// VOLUMETRIC ORDER BLOCKS -


avg := math.avg(red_1_prB, red_1_prT)
while BB.aLabels.size() > 0
BB.aLabels.pop().delete()
BB.PDa_boxA.delete(), BB.PDa_boxB.delete(), BB.dir := -1
BB.BB_boxA.set_left (red_1_idx)
BB.BB_boxA.set_top (red_1_prT)
BB.BB_boxA.set_right ( n )
BB.BB_boxA.set_bottom (red_1_prB)
BB.BB_boxA.set_bgcolor(cBB_minA )

BB.BB_boxB.set_left (n)
BB.BB_boxB.set_top (red_1_prT)
BB.BB_boxB.set_right ( n + 8)
BB.BB_boxB.set_bottom (red_1_prB)
BB.BB_boxB.set_bgcolor(cBB_minB )
BB.BB_boxB.set_text('-BB')
BB.BB_boxB.set_text_color(cBB_minB.notransp())
BB.BB_boxB.set_text_valign(text.align_top)

BB.BB_line.set_xy1(n, avg), BB.BB_line.set_xy2(n , avg)

// Previous swings
cnt = 0, ll1 = low
for c = 0 to sz -2
getX = aZZ.x.get(c)
getY = aZZ.y.get(c)
if getY < ll1 and aZZ.d.get(c) == -1 and showSPD
getY2 = (mx[n - getX] - low[n - getX]) / 4

break

signals.set(BB_min, true)
alert('-BB', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high,
cBB_minB.notransp(), _arrowdn, size.large))

break

MSS.dir := -1
if barstate.isfirst
var table errorBox = table.new(position.bottom_right, 1, 1, bgcolor =
color.new(#363a45, 100))
table.cell(errorBox, 0, 0, "© God Slayer", text_color = color.gray,
text_halign = text.align_center, text_size = size.normal)

//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
draw(len, tpCss)

lft = BB.BB_boxB.get_left ()

avg = BB.BB_line.get_y2 ()
l_1 = BB.line_1.get_y2 ()
l_2 = BB.line_2.get_y2 ()
TP1 = BB.TP1_line.get_y2 ()
TP2 = BB.TP2_line.get_y2 ()
TP3 = BB.TP3_line.get_y2 ()

switch BB.dir
1 =>
if not BB.Mitigated
if close < btm
BB.Mitigated := true
signals.set(BB_endBl, true)
alert('+BB Mitigated', alert.freq_once_per_bar_close)

BB.aLabels.unshift(createLab('u', low, color.yellow, _c))


BB.BB_boxB.set_right(n)
BB.BB_line.set_x2 (n)
else
BB.BB_boxB.set_right(n + 8)
BB.BB_line.set_x2 (n + 8)

BB.TP1_line.set_x2 (n)
BB.TP2_line.set_x2 (n)
BB.TP3_line.set_x2 (n)

if n > BB.BB_boxB.get_left()
if not BB.Broken
if BB.scalp
if not BB.TP1_hit and open < TP1 and high > TP1
BB.TP1_hit := true
signals.set(tpUP1, true)
alert('TP UP 1', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP1, #ff00dd, _c))
if not BB.TP2_hit and open < TP2 and high > TP2
BB.TP2_hit := true
signals.set(tpUP2, true)
alert('TP UP 2', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP2, #ff00dd, _c))
if not BB.TP3_hit and open < TP3 and high > TP3
BB.TP3_hit := true
signals.set(tpUP3, true)
alert('TP UP 3', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP3, #ff00dd, _c))
switch
open > avg and open < top and close > top =>
BB.TP1_hit := false
BB.TP2_hit := false
BB.TP3_hit := false
BB.scalp := true
signals.set(signUP, true)
alert('signal UP', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, color.lime,
_arrowup, size.normal))
close < avg and close > btm =>
BB.Broken := true
BB.scalp := false
signals.set(cnclUP, true)
alert('cancel UP', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, color.orange,
_x))
else
// reset
if not tillFirstBreak and close > top
BB.Broken := false
BB.scalp := true
signals.set(BBplus, true)
alert('+BB (R)', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('u', low, color.blue, 'R',
size.normal))

if not BB.Broken_1
BB.line_1.set_x2(n)
if close < l_1
BB.Broken_1 := true
signals.set(LL1break, true)
alert('LL 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))
if not BB.Broken_2
BB.line_2.set_x2(n)
if close < l_2
BB.Broken_2 := true
signals.set(LL2break, true)
alert('LL 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))

if not BB.PDbroken1
BB.PDa_box1.set_right(n)
BB.PDaLine1.set_x2 (n)
if close > BB.PDa_box1.get_top() and n > BB.PDa_box1.get_left()
BB.PDbroken1 := true
signals.set(SW1breakUP, true)
alert('Swing UP 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))
if not BB.PDbroken2
BB.PDa_box2.set_right(n)
BB.PDaLine2.set_x2 (n)
if close > BB.PDa_box2.get_top() and n > BB.PDa_box2.get_left()
BB.PDbroken2 := true
signals.set(SW2breakUP, true)
alert('Swing UP 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))

-1 =>
if not BB.Mitigated
if close > top
BB.Mitigated := true
signals.set(BB_endBr, true)
alert('-BB Mitigated', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('d', high, cBB_minB.notransp(),
_c))
BB.BB_boxB.set_right(n)
BB.BB_line.set_x2 (n)
else
BB.BB_boxB.set_right(n + 8)
BB.BB_line.set_x2 (n + 8)

BB.TP1_line.set_x2 (n)
BB.TP2_line.set_x2 (n)
BB.TP3_line.set_x2 (n)

if n > BB.BB_boxB.get_left()
if not BB.Broken
if BB.scalp
if not BB.TP1_hit and open > TP1 and low < TP1
BB.TP1_hit := true
signals.set(tpDN1, true)
alert('TP DN 1', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP1, #ff00dd, _c))
if not BB.TP2_hit and open > TP2 and low < TP2
BB.TP2_hit := true
signals.set(tpDN2, true)
alert('TP DN 2', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP2, #ff00dd, _c))
if not BB.TP3_hit and open > TP3 and low < TP3
BB.TP3_hit := true
signals.set(tpDN3, true)
alert('TP DN 3', alert.freq_once_per_bar)
BB.aLabels.unshift(createLab('c', TP3, #ff00dd, _c))
switch
open < avg and open > btm and close < btm =>
BB.TP1_hit := false
BB.TP2_hit := false
BB.TP3_hit := false
BB.scalp := true
signals.set(signDN, true)
alert('signal DN', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high, color.orange,
_arrowdn, size.normal))
close > avg and close < top =>
BB.Broken := true
BB.scalp := false
signals.set(cnclDN, true)
alert('cancel DN', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high, color.red ,
_x))
else
// reset
if not tillFirstBreak and close < btm
BB.Broken := false
BB.scalp := true
signals.set(BB_min, true)
alert('-BB (R)', alert.freq_once_per_bar_close)
BB.aLabels.unshift(createLab('d', high, color.blue, 'R',
size.normal))

if not BB.Broken_1
BB.line_1.set_x2(n)
if close > l_1
BB.Broken_1 := true
signals.set(HH1break, true)
alert('HH 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))
if not BB.Broken_2
BB.line_2.set_x2(n)
if close > l_2
BB.Broken_2 := true
signals.set(HH2break, true)
alert('HH 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', high, #c00000, _c))

if not BB.PDbroken1
BB.PDa_box1.set_right(n)
BB.PDaLine1.set_x2 (n)
if close < BB.PDa_box1.get_bottom() and n > BB.PDa_box1.get_left()
BB.PDbroken1 := true
signals.set(SW1breakDN, true)
alert('Swing DN 1 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))
if not BB.PDbroken2
BB.PDa_box2.set_right(n)
BB.PDaLine2.set_x2 (n)
if close < BB.PDa_box2.get_bottom() and n > BB.PDa_box2.get_left()
BB.PDbroken2 := true
signals.set(SW2breakDN, true)
alert('Swing DN 2 break', alert.freq_once_per_bar_close)
if showBreaks
BB.aLabels.unshift(createLab('c', low, #c00000, _c))

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

pvhh = ta.pivothigh(pvllen, 0)
pvll = ta.pivotlow(pvllen, 0)

f_get_candle(_index) =>
[open[_index], high[_index], low[_index], close[_index], bar_index[_index]]

f_sfp() =>
[so, sh, sl, sc, si] = f_get_candle(0)

// High SFP
hc1 = pvhh
maxp = high[1]
hc2 = false
hx = 0
hy = 0.0
for i=1 to lookback
[co, ch, cl, cc, ci] = f_get_candle(i)
if ch >= sh
break
if ch < sh and ch > math.max(so, sc) and pvhh[bar_index - ci] and ch > maxp
hc2 := true
hx := bar_index[i]
hy := ch
if ch > maxp
maxp := ch

hcs = hc1 and hc2

// Low SFP
lc1 = pvll
minp = low[1]
lc2 = false
lx = 0
ly = 0.0
for i=2 to lookback
[co, ch, cl, cc, ci] = f_get_candle(i)
if cl < sl
break
if sl < cl and math.min(so, sc) > cl and pvll[bar_index - ci] and cl < minp
lc2 := true
lx := bar_index[i]
ly := cl
if cl < minp
minp := cl

lcs = lc1 and lc2

[hcs, hx, hy, lcs, lx, ly]

[hsfp, hx, hy, lsfp, lx, ly] = f_sfp()

if show_sfp and hsfp


line.new(hx, hy, bar_index + 1, hy, color=#f23645)
alert("High SFP Detected!", alert.freq_once_per_bar)
plotshape(hsfp ? high : na, "High SFP", style=shape.triangledown,
location=location.abovebar, color=#f23645, text="SFP", textcolor=#f23645,
size=size.tiny)

if show_sfp and lsfp


line.new(lx, ly, bar_index + 1, ly, color=#089981)
alert("Low SFP Detected!", alert.freq_once_per_bar)
plotshape(lsfp ? low : na, "Low SFP", style=shape.triangleup,
location=location.belowbar, color=#089981, text="SFP", textcolor=#089981,
size=size.tiny)

//-----------------------------------------------------------------------------}
//Enable/Disable alerts
//-----------------------------------------------------------------------------{

anyalert = "Any Alert ()"


// Internal Bullish
bool i_bull_bos = input.bool(false, "I - Bullish BOS ", inline = '3', group
= anyalert)
bool i_bull_choch = input.bool(false, "I - Bullish CHoCH ", inline = '1', group
= anyalert)
bool i_bull_chochp = input.bool(false, "I - Bullish CHoCH+ ", inline = '2', group
= anyalert)

// Swing Bullish
bool s_bull_bos = input.bool(false, "S - Bullish BOS", inline = '6', group =
anyalert)
bool s_bull_choch = input.bool(false, "S - Bullish CHoCH", inline = '4', group =
anyalert)
bool s_bull_chochp = input.bool(false, "S - Bullish CHoCH+", inline = '5', group =
anyalert)

// Internal Bearish
bool i_bear_bos = input.bool(false, "I - Bearish BOS ", inline = '3', group =
anyalert)
bool i_bear_choch = input.bool(false, "I - Bearish CHoCH ", inline = '1', group =
anyalert)
bool i_bear_chochp = input.bool(false, "I - Bearish CHoCH+ ", inline = '2', group
= anyalert)

// Swing Bearish
bool s_bear_bos = input.bool(false, "S - Bearish BOS", inline = '6', group =
anyalert)
bool s_bear_choch = input.bool(false, "S - Bearish CHoCH", inline = '4', group =
anyalert)
bool s_bear_chochp = input.bool(false, "S - Bearish CHoCH+", inline = '5', group =
anyalert)

bool showEQL = input.bool(false, "Show EQL", group = anyalert, inline = '7')


bool showEQH = input.bool(false, "Show EQH", group = anyalert, inline = '7')
// Boolean values for Bullish Order Block alerts
bool bl_alert_ob = input.bool(false, "Bullish Order Block Alert", inline
= '8', group = anyalert)
bool bl_alert_swingob = input.bool(false, "Bullish Swing Order Block Alert",
inline = '9', group = anyalert)
bool bl_alert_obtouch = input.bool(false, "Candle Entering in a Bullish Order
Block Alert", inline = '10', group = anyalert)

// Boolean values for Bearish Order Block alerts


bool br_alert_ob = input.bool(false, "Bearish Order Block Alert", inline
= '8', group = anyalert)
bool br_alert_swingob = input.bool(false, "Bearish Swing Order Block Alert",
inline = '9', group = anyalert)
bool br_alert_obtouch = input.bool(false, "Candle Entering in a Bearish Order
Block Alert", inline = '10', group = anyalert)

// New alerts boolean values


bool bb_plus_alert = input.bool(false, "+BB Alert", inline = '11', group =
anyalert)
bool signal_up_alert = input.bool(false, "Signal UP Alert", inline = '12', group
= anyalert)
bool bb_end_bl_alert = input.bool(false, "+BB Mitigated Alert", inline = '13',
group = anyalert)

bool bb_min_alert = input.bool(false, "-BB Alert", inline = '11', group =


anyalert)
bool signal_dn_alert = input.bool(false, "Signal DN Alert", inline = '12', group
= anyalert)
bool bb_end_br_alert = input.bool(false, "-BB Mitigated Alert", inline = '13',
group = anyalert)

bool bl_alert_zone = input.bool(false, "Accumulation Zone Alert", inline = '14',


group = anyalert)
bool br_alert_zone = input.bool(false, "Distribution Zone Alert", inline = '14',
group = anyalert)
//-----------------------------------------------------------------------------}
// Alerts
//-----------------------------------------------------------------------------{

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

// 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)
or(signals.get(BBplus ) or signals.get(signUP ) or signals.get(tpUP1 ) or
signals.get(tpUP2 ) or signals.get(tpUP3 ) or signals.get(cnclUP ) or
signals.get(BB_endBl ) or signals.get(LL1break ) or signals.get(LL2break ) or
signals.get(SW1breakUP) or signals.get(SW2breakUP) or signals.get(BB_min ) or
signals.get(signDN ) or signals.get(tpDN1 ) or signals.get(tpDN2 ) or
signals.get(tpDN3 ) or signals.get(cnclDN ) or signals.get(BB_endBr ) or
signals.get(HH1break ) or signals.get(HH2break ) or signals.get(SW1breakDN) or
signals.get(SW2breakDN) or (bl_alert_ob and blalert.ob) or (bl_alert_swingob and
blalert.swingob) or(bl_alert_obtouch and blalert.obtouch) or(br_alert_obtouch and
bralert.obtouch) or(br_alert_ob and bralert.ob) or(br_alert_swingob and
bralert.swingob or (bl_alert_zone and blalert.zone) or (br_alert_zone and
bralert.zone)))

// Implementing the AnyALert() Function


alertcondition(anyAlertCondition, title ="Any Alert()", message="Price Action
Toolkit Alert ()")

You might also like