Master Pattern Babak
Master Pattern Babak
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Babak
//@version=5
indicator("Master Pattern [Babak]", "Babak - Master Pattern Indicator", overlay =
true, max_boxes_count = 50000, max_lines_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(3, 'Contraction Detection Lookback', minval = 1)
liqLength = input.int(20, 'Liquidity Levels', minval = 1)
//Style
bullCss = input.color(color.teal, 'Bullish Pattern', inline = 'bull', group =
'Pattern Style')
showBullBox = input(true, 'Area', inline = 'bull', group = 'Pattern Style')
showBullLvl = input(true, 'Line', inline = 'bull', group = 'Pattern Style')
//Liquidity Style
showLiq = input(true, 'Show Liquidity Levels', group = 'Liquidity')
bullLiqCss = input.color(color.teal, 'Upper Liquidity', group = 'Liquidity')
bearLiqCss = input.color(color.red, 'Lower Liquidity', group = 'Liquidity')
//-----------------------------------------------------------------------------}
//UDT
//-----------------------------------------------------------------------------{
type mp
box area
line avg
bool breakup
bool breakdn
//-----------------------------------------------------------------------------}
//Detect contraction
//-----------------------------------------------------------------------------{
var phy = 0., var phx = 0, var pht = 0.
var ply = 0., var plx = 0, var plt = 0.
n = bar_index
ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)
if ph
pht := math.sign(ph - phy)
phy := ph
if pl
plt := math.sign(pl - ply)
ply := pl
//-----------------------------------------------------------------------------}
//Set pattern
//-----------------------------------------------------------------------------{
var mp master = mp.new()
if isbull or isbear
css = isbull ? bullCss : bearCss
master.avg.set_x2(n-length)
top := na
btm := na
//-----------------------------------------------------------------------------}
//Liquidity levels
//-----------------------------------------------------------------------------{
var line liqup = na, var liqup_reach = false
var line liqdn = na, var liqdn_reach = false
//-----------------------------------------------------------------------------}