Indicator Simple Algo v5 For TradingView
Indicator Simple Algo v5 For TradingView
0
at https://mozilla.org/MPL/2.0/
// Join us https://t.me/simpleforextools
//@version=5
indicator("Order Blocks & Breaker Blocks + Support & Resistance Dynamic+ Reversal
finder", overlay = true
, max_lines_count = 500
, max_labels_count = 500
, max_boxes_count = 500, max_bars_back=5000)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(10, 'Swing Lookback' , minval = 3)
showBull = input.int(3, 'Show Last Bullish OB', minval = 0)
showBear = input.int(3, 'Show Last Bearish OB', minval = 0)
useBody = input(false, 'Use Candle Body')
//Style
bullCss = input(color.new(#2157f3, 80), 'Bullish OB' , inline = 'bullcss',
group = 'Style')
bullBreakCss = input(color.new(#ff1100, 80), 'Bullish Break', inline = 'bullcss',
group = 'Style')
//-----------------------------------------------------------------------------}
//UDT's
//-----------------------------------------------------------------------------{
type ob
float top = na
float btm = na
int loc = bar_index
bool breaker = false
int break_loc = na
type swing
float y = na
int x = na
bool crossed = false
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
swings(len)=>
var os = 0
var swing top = swing.new(na, na)
var swing btm = swing.new(na, na)
upper = ta.highest(len)
lower = ta.lowest(len)
if os == 1 and os[1] != 1
btm := swing.new(low[length], bar_index[length])
[top, btm]
//-----------------------------------------------------------------------------}
//Detect Swings
//-----------------------------------------------------------------------------{
n = bar_index
//-----------------------------------------------------------------------------}
//Bullish OB
//-----------------------------------------------------------------------------{
var bullish_ob = array.new<ob>(0)
bull_break_conf = 0
for i = 1 to (n - top.x)-1
minima := math.min(min[i], minima)
maxima := minima == min[i] ? max[i] : maxima
loc := minima == min[i] ? time[i] : loc
if bullish_ob.size() > 0
for i = bullish_ob.size()-1 to 0
element = bullish_ob.get(i)
if not element.breaker
if math.min(close, open) < element.btm
element.breaker := true
element.break_loc := time
else
if close > element.top
bullish_ob.remove(i)
else if i < showBull and top.y < element.top and top.y > element.btm
bull_break_conf := 1
//Set label
if bull_break_conf > bull_break_conf[1] and showLabels
label.new(top.x, top.y, '?', color = na
, textcolor = bearCss.notransp()
, style = label.style_label_down
, size = size.tiny)
//-----------------------------------------------------------------------------}
//Bearish OB
//-----------------------------------------------------------------------------{
var bearish_ob = array.new<ob>(0)
bear_break_conf = 0
minima = min[1]
maxima = max[1]
loc = time[1]
for i = 1 to (n - btm.x)-1
maxima := math.max(max[i], maxima)
minima := maxima == max[i] ? min[i] : minima
loc := maxima == max[i] ? time[i] : loc
if bearish_ob.size() > 0
for i = bearish_ob.size()-1 to 0
element = bearish_ob.get(i)
if not element.breaker
if math.max(close, open) > element.top
element.breaker := true
element.break_loc := time
else
if close < element.btm
bearish_ob.remove(i)
else if i < showBear and btm.y > element.btm and btm.y < element.top
bear_break_conf := 1
//Set label
if bear_break_conf > bear_break_conf[1] and showLabels
label.new(btm.x, btm.y, '?', color = na
, textcolor = bullCss.notransp()
, style = label.style_label_up
, size = size.tiny)
//-----------------------------------------------------------------------------}
//Set Order Blocks
//-----------------------------------------------------------------------------{
for bx in box.all
bx.delete()
for l in line.all
l.delete()
if barstate.islast
//Bullish
if showBull > 0
for i = 0 to math.min(showBull-1, bullish_ob.size())
get_ob = bullish_ob.get(i)
get_ob.display(bullCss, bullBreakCss)
//Bearish
if showBear > 0
for i = 0 to math.min(showBear-1, bearish_ob.size())
get_ob = bearish_ob.get(i)
get_ob.display(bearCss, bearBreakCss)
//-----------------------------------------------------------------------------}
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
mult = input.float(8., 'Multiplicative Factor', minval = 0, step = .5)
atrLen = input.int(50, 'ATR Length', minval = 0)
extLast = input.int(4, 'Extend Last', minval = 0)
//Style
supCss = input.color(#089981, 'Support ', inline = 'sup', group = 'Style')
supAreaCss = input(color.new(#089981, 80), 'Areas', inline = 'sup', group =
'Style')
//-----------------------------------------------------------------------------}
//UDT
//-----------------------------------------------------------------------------{
type sr
float y
float area
int x
bool support
//-----------------------------------------------------------------------------}
//Calculation
//-----------------------------------------------------------------------------{
var records = array.new<sr>(0)
var float avg = close
var hold_atr = 0.
var os1 = 0
n1 = bar_index
breakout_atr = nz(ta.atr(atrLen)) * mult
if close == avg
if os1 == 1
records.unshift(sr.new(lower_sup, upper_sup, time, true))
else
records.unshift(sr.new(upper_res, lower_res, time, false))
//-----------------------------------------------------------------------------}
//Extensions
//-----------------------------------------------------------------------------{
var lines = array.new<line>(0)
var boxes = array.new<box>(0)
if extArea
boxes.push(box.new(na,na,na,na,na, xloc = xloc.bar_time))
if extLvls
get_line = lines.get(i)
get_line.set_xy1(get_sr.x, get_sr.y)
get_line.set_xy2(time, get_sr.y)
get_line.set_color(get_sr.support ? supCss : resCss)
if extArea
get_box = boxes.get(i)
get_box.set_lefttop(get_sr.x, get_sr.area)
get_box.set_rightbottom(time, get_sr.y)
get_box.set_bgcolor(get_sr.support ? supAreaCss : resAreaCss)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Plot supports
plot_upper_sup = plot(upper_sup, 'Upper Support', na
, style = plot.style_linebr)
plot_lower_sup = plot(lower_sup, 'Lower Support', close == avg ? na : supCss
, style = plot.style_linebr)
//Plot resistances
plot_upper_res = plot(upper_res, 'Upper Resistance', close == avg ? na : resCss
, style = plot.style_linebr)
plot_lower_res = plot(lower_res, 'Lower Resistance', na
, style = plot.style_linebr)
//Fills
fill(plot_upper_sup, plot_lower_sup, supAreaCss, 'Support Area')
fill(plot_upper_res, plot_lower_res, resAreaCss, 'Resistance Area')
//-----------------------------------------------------------------------------}
//---Reversal Finder
//
stable_candle = math.abs(close - open) / ta.tr > stability
rsi = ta.rsi(close, 14)
bullish_engulfing = close[1] < open[1] and close > open and close > open[1]
rsi_below_50 = rsi < rsiindex
decrease_over_5 = close < close[candledelta]
bearish_engulfing = close[1] > open[1] and close < open and close < open[1]
rsi_above_50 = rsi > rsiindex
increase_over_5 = close > close[candledelta]
buylbl = #898d94
selllbl = #089981
txtcl = #ffffff
//=============================================================================
// INDICATOR 11 - Trend Confidence
//============================================================================
// CCI
// ADX
lenadx = 14
lensig = 14
limadx = 18
ADX_up = ta.change(high)
ADX_down = -ta.change(low)
trur = ta.rma(ta.tr, lenadx)
plus = fixnan(100 * ta.rma(ADX_up > ADX_down and ADX_up > 0 ? ADX_up : 0, lenadx) /
trur)
minus = fixnan(100 * ta.rma(ADX_down > ADX_up and ADX_down > 0 ? ADX_down : 0,
lenadx) / trur)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
macol = adx > limadx and plus > minus ? #898d94 : adx > limadx and plus < minus ?
#089981 : color.black
//Acumulation/Distribution
RSI_Dist = ta.rsi(close, 14)
ACC_Long = RSI_Dist < 40
ACC_Short = RSI_Dist > 60
// MFI
lengthrvi = 10
srcrvi = close
lenrvi = 14
stddev = ta.stdev(srcrvi, lengthrvi)
upperrvi = ta.ema(ta.change(srcrvi) <= 0 ? 0 : stddev, lenrvi)
lowerrvi = ta.ema(ta.change(srcrvi) > 0 ? 0 : stddev, lenrvi)
rvi = upperrvi / (upperrvi + lowerrvi) * 100
Long_Signal_Strength = 0
Short_Signal_Strength = 0
if entry_long
if TM_Long
Long_Signal_Strength += 1
if ADX_Long
Long_Signal_Strength += 1
if ACC_Long
Long_Signal_Strength += 1
if MFI_Long
Long_Signal_Strength += 1
if MOML_Long
Long_Signal_Strength += 1
if entry_short
if TM_Short
Short_Signal_Strength += 1
if ADX_Short
Short_Signal_Strength += 1
if ACC_Short
Short_Signal_Strength += 1
if MFI_Short
Short_Signal_Strength += 1
if MOML_Short
Short_Signal_Strength += 1
//Plot Buy/Sell Signals on chart
// Support Resistance
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//
RSI2rsx = 0
if RSI2incrementer_both
RSI2rsx := nz(RSI2rsx[1], 0) + RSI2incrementer_both
RSI2rsx
else
RSI2rsx = 0
RSI2rsx
///////////////////////////////////////////////////////
RSI2rsu = 0
if RSI2incrementer_up
RSI2rsu := nz(RSI2rsu[1], 0) + RSI2incrementer_up
RSI2rsu
else
RSI2rsu = 0
RSI2rsu
RSI2ResistanceZoneHigh = fixnan(RSI2rssH)
RSI2ResistanceZoneLow = fixnan(RSI2rssL)
////////////////////////////////////////////////////////
RSI2rsd = 0
if RSI2incrementer_down
RSI2rsd := nz(RSI2rsd[1], 0) + RSI2incrementer_down
RSI2rsd
else
RSI2rsd = 0
RSI2rsd
RSI2SupportZoneHigh = fixnan(RSI2rsrH)
RSI2SupportZoneLow = fixnan(RSI2rsrL)
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//
i_tf_ob = mode == true ? HTF_auto : HTF_manual
// Dashboard
bullish = #898d94
bearish = #089981
// Dashboard
gr_dashboard = "DASHBOARD SETTINGS"
showDash = input(true, "Dashboard", group = gr_dashboard)
dashLoc = input.string('Bottom Right', 'Location', options = ['Top Right', 'Bottom
Right', 'Bottom Left'], group = gr_dashboard)
textSize = input.string('Normal', 'Size', options = ['Tiny', 'Small', 'Normal'],
group = gr_dashboard)
// # ========================================================================= #
// DASHBOARD
// # ========================================================================= #
// Predicted Reversal
predictedreversal = Long_Signal_Strength > Short_Signal_Strength ? 0 :
Short_Signal_Strength > Long_Signal_Strength ? 1 : Short_Signal_Strength ==
Long_Signal_Strength ? 2 : na
predictedtext = predictedreversal == 0 ? 'â–²' : predictedreversal == 1 ? 'â–¼' :
predictedreversal == 2 ? 'Undetected' : 'Undetected'
predictedtextcolor = predictedtext == 'â–²' ? #898d94 : predictedtext == 'â–¼' ?
#089981 : color.white
predictedtext2 = Long_Signal_Strength > Short_Signal_Strength ?
Long_Signal_Strength : Short_Signal_Strength > Long_Signal_Strength ?
Short_Signal_Strength : na
//Short_Signal_Strength
//Long_Signal_Strength
// Volume Function
vollength = 20
buyThreshold = 0.7
sellThreshold = -0.7
volumeRatio = volume / ta.sma(volume, vollength)
volatilength = 20
lowVolatilityThreshold = 0.5
highVolatilityThreshold = 1.5
// Drawing Dashboard
var table_position = dashLoc == 'Bottom Left' ? position.bottom_left
: dashLoc == 'Top Right' ? position.top_right
: position.bottom_right
var tb = table.new(table_position, 8, 8
, bgcolor = #1e222d
, border_color = #373a46
, border_width = 1
, frame_color = #373a46
, frame_width = 1)
if showDash
if barstate.isfirst
tb.cell(0, 0, "Reversal Finder", text_color = color.white, text_size =
table_size)
tb.merge_cells(0,0,1,0)
if barstate.islast
tb.cell(0, 3, str.tostring(trendIndication) + "Trend Strenght", text_color
= color.white, text_size = table_size, text_halign = text.align_left)
tb.cell(0, 4, "💠Volume", text_color = color.white, text_size =
table_size, text_halign = text.align_left)
tb.cell(0, 5, str.tostring(volatilityIndication) + " Volatility",
text_color = color.white, text_size = table_size, text_halign = text.align_left)
tb.cell(0, 6, str.tostring(trendemote) + " Trend", text_color =
color.white, text_size = table_size, text_halign = text.align_left)
tb.cell(1, 3, str.tostring(trendStrengthPercentage, format.percent),
text_color=textColorstrength, text_size=table_size)
tb.cell(1, 4, str.tostring(volumeSentiment, format.percent), text_color =
textcolorvolu, text_size = table_size)
tb.cell(1, 5, str.tostring(volatilityPercentage, format.percent),
text_color=volatilitycolor, text_size=table_size)
tb.cell(1, 6, str.tostring(trendtext), text_color = textColorstrength,
text_size = table_size)
tb.cell(0, 7, 'Predicted Reversal', text_color = color.white, text_size =
table_size, text_halign = text.align_left)
tb.cell(1, 7, str.tostring(predictedtext) + ' | ' +
str.tostring(predictedtext2), text_color = predictedtextcolor, text_size =
table_size)
//----------------------------------------}
//Order Blocks
//----------------------------------------{
v_buy = #898d944d
v_sell = #71ad724d
timeframe1=' : '
show_iob = 'All'=='All' or 'All'=='Internal' //input(true, 'Internal', inline =
'ob', group = 'Order Blocks')
show_ob = 'All'=='All' or 'All'=='External' //input(false, 'External', inline =
'ob', group = 'Order Blocks')
ob_showlast = 5//input.int(10, 'LookBack', minval = 1, inline = 'ob', group =
'Order Blocks')
iob_showlast = 5//input.int(5, 'LookBack', minval = 1, inline = 'iob', group =
'Order Blocks')
style = 'Colored'
v_lookback= 10
ob_loockback=10
timediff=(time[1]-time[101])/100
//----------------------------------------}
//Liquidity Levels
//----------------------------------------{
currentTF = false
htfTF = ""
_highLineStyleHTF = "Solid"//input.string("Solid", title = "Line Style",
options=["Solid", "Dashed", "Dotted"], group=liquidity_level_group,inline='5')
highLineStyleHTF = _highLineStyleHTF=="Solid" ? line.style_solid :
_highLineStyleHTF=="Dashed" ? line.style_dashed : line.style_dotted
box_width = 2.5//input.float(3.0, title = "Width",
group=liquidity_level_group,inline='5', minval = 1, maxval = 10, step = 0.5)
lineWidthHTF=2
lowLineColorHTF = #00bbf94d
highLineColorHTF = #e91e624d
highBoxBorderColorHTF = color.new(highLineColorHTF,90)
lowBoxBorderColorHTF = color.new(lowLineColorHTF,90)
displayStyle_liq = "Boxes"//'Lines'
//----------------------------------------}
//Fair Value Gaps (FVG
//----------------------------------------{
show_fvg = false
i_tf = ""
i_mtfbearishfvgcolor = #ffffff20
i_mtfbullishfvgcolor = #ffffff20
i_bullishfvgcolor = color.new(color.green,100)
i_bearishfvgcolor = color.new(color.green,90)
i_fillByMid = true
i_deleteonfill = true
i_textColor = color.white
i_mtf = "HTF"
i_tfos = 10
i_mtfos = 50
//----------------------------------------}
//BOS and ChoCH
//----------------------------------------{
// Constants
color CLEAR = color.rgb(0,0,0,100)
// Inputs
showms=false
bosColor1 = #787b86
bosColor2 = #787b86
swingSize = 3
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
color transparent = #ffffff00
length1 = 50
is_newbar(res) =>
t = time(res)
not na(t) and (na(t[1]) or t > t[1])
//Swings detection/measurements
calculate_swing_points(length1)=>
var prev = 0
prev := high[length1] > ta.highest(length) ? 0 : low[length1] <
ta.lowest(length1) ? 1 : prev[1]
t = prev == 0 and prev[1] != 0 ? high[length1] : 0
b = prev == 1 and prev[1] != 1 ? low[length1] : 0
[t, b]
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
//--------------------------------------------------------------- Market
Structure
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
pivot_high_found = ta.pivothigh(high, 10, 10)
pivot_low_found = ta.pivotlow(low, 10, 10)
var float prevHigh_s = na,var float prevLow_s = na,var int prevHighIndex_s = na,var
int prevLowIndex_s = na
bool higher_highs = false, bool lower_highs = false, bool higher_lows = false, bool
lower_lows = false
if not na(pivot_high_found)
if pivot_high_found >= prevHigh_s
higher_highs := true
prevSwing_s := 2
else
lower_highs := true
prevSwing_s := 1
prevHigh_s := pivot_high_found
prevHighIndex_s := bar_index - 10
if not na(pivot_low_found)
if pivot_low_found >= prevLow_s
higher_lows := true
prevSwing_s := -1
else
lower_lows := true
prevSwing_s := -2
prevLow_s := pivot_low_found
prevLowIndex_s := bar_index - 10
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
//--------------------------------------------------------------- Fair Value
Gaps
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
// }
// }
//var keyword can be used to hold data in memory, with pinescript all data is lost
including variables unless the var keyword is used to preserve this data
var bullishgapholder = array.new_box(0)
var bearishgapholder = array.new_box(0)
var fvg_apper=false
var fvg_break=false
fvg_apper:=false
fvg_break:=false
// ———————————————————— Functions {
//function paramaters best declared with '_' this helps defer from variables in the
function scope declaration and elsewhere e.g. close => _close
create_fvg_func(_upperlimit,_lowerlimit,_midlimit,_bar,_boxholder,_boxholder_fill,_
midholder,_highholder,_lowholder,_labelholder,_boxcolor,_mtfboxcolor, _htf)=>
timeholder = str.tostring(i_tf)
offset = i_mtfos
boxbgcolor = _mtfboxcolor
bg_color = color.new(_mtfboxcolor,90)
if _htf == false
timeholder := str.tostring(timeframe.period)
offset := i_tfos
boxbgcolor := _boxcolor
array.push(_boxholder,box.new(_bar,_upperlimit,_bar+
(timediff)*20,_lowerlimit,border_color=true? bg_color : na,bgcolor = true? bg_color
: na, extend = false ? extend.right:extend.none,xloc =
xloc.bar_time,text='',text_color=#787b86,text_halign=text.align_right,text_size=siz
e.small))
array.push(_boxholder_fill,box.new(_bar,_upperlimit,_bar+
(timediff)*20,_lowerlimit,border_color=true? bg_color : na ,bgcolor = true?
bg_color : na, extend = false ? extend.right:extend.none,xloc = xloc.bar_time))
array.push(_midholder,line.new(_bar,(_lowerlimit+_upperlimit)/2.0,_bar+
(timediff)*20,_midlimit,color = #787b86, extend = false ?
extend.right:extend.none,style=line.style_solid,width=1,xloc = xloc.bar_time))
array.push(_lowholder,line.new(_bar,_lowerlimit,_bar+
(timediff)*20,_lowerlimit,color = i_fillByMid?boxbgcolor:na, extend = false ?
extend.right:extend.none,width=1,xloc = xloc.bar_time))
array.push(_highholder,line.new(_bar,_upperlimit,_bar+
(timediff)*20,_upperlimit,color = i_fillByMid?boxbgcolor:na, extend = false ?
extend.right:extend.none,width=1,xloc = xloc.bar_time))
//checks for gap between current candle and 2 previous candle e.g. low of current
candle and high of the candle before last, this is the fair value gap.
check_fvg_func(_close,_high,_highp2,_low,_lowp2,_open,_bar,_htf)=>
gap=0
thold_ = (ta.highest(_high,300) - ta.lowest(_low,300)) * math.max(1.5, 0.1) /
100.
if _open > _close // red
if _lowp2>_high
if not(true) or math.abs(_lowp2 -_high) > thold_
upperlimit = _high//_close - (_close - _lowp2 )
lowerlimit = _lowp2//_close - (_close-_high)
midlimit = lowerlimit + ((upperlimit - lowerlimit) / 2.)
gap:=1
create_fvg_func(upperlimit,lowerlimit,midlimit,_bar,bullishgapholder,bullishgaphold
er_fill,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder,
i_bullishfvgcolor,i_mtfbullishfvgcolor,_htf)
else
if _low>_highp2
if not(true) or math.abs(_low - _highp2) > thold_
upperlimit = _low//_close - (_close-_low)
lowerlimit = _highp2//_close- (_close - _highp2),
midlimit = lowerlimit + ((upperlimit - lowerlimit) / 2.)
gap:=-1
create_fvg_func(upperlimit,lowerlimit,midlimit,_bar,bearishgapholder,bearishgaphold
er_fill,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder,
i_bearishfvgcolor,i_mtfbearishfvgcolor,_htf)
gap
//Used to remove the gap from its relevant array as a result of it being filled.
delete_fvg_func(_currentgap,_currentgap_fill,_i,_boxholder,_boxholder_fill,_midhold
er,_highholder,_lowholder,_labelholder)=>
array.remove(_boxholder,_i)
array.remove(_boxholder_fill,_i)
currentmid=array.get(_midholder,_i)
currenthigh=array.get(_highholder,_i)
currentlow=array.get(_lowholder,_i)
array.remove(_midholder,_i)
array.remove(_highholder,_i)
array.remove(_lowholder,_i)
if i_deleteonfill
line.delete(currentmid)
line.delete(currenthigh)
line.delete(currentlow)
else
line.set_extend(currentmid, extend.none)
line.set_x2(currentmid,time)
line.set_extend(currenthigh, extend.none)
line.set_x2(currenthigh,time)
line.set_extend(currentlow, extend.none)
line.set_x2(currentlow,time)
if i_deleteonfill
box.delete(_currentgap)
box.delete(_currentgap_fill)
else
box.set_extend(_currentgap,extend.none)
box.set_right(_currentgap,time)
//checks if gap has been filled either by 0.5 fill (i_fillByMid) or SHRINKS the gap
to reflect the true value gap left.
validate_fvg_func(_high,_low)=>
fvg_removed=0
if array.size(bullishgapholder) > 0
for i = array.size(bullishgapholder)-1 to 0
currentgap_fill = array.get(bullishgapholder_fill,i)
currentgap = array.get(bullishgapholder,i)
cmid = array.get(bullishmidholder,i)
chigh = array.get(bullish_high_holder,i)
clow = array.get(bullish_low_holder,i)
line.set_x2(cmid,timenow+(timediff)*20)
line.set_x2(chigh,timenow+(timediff)*20)
line.set_x2(clow,timenow+(timediff)*20)
box.set_right(currentgap_fill,timenow+(timediff)*20)
box.set_right(currentgap,timenow+(timediff)*20)
currentmid = array.get(bullishmidholder,i)
currenthigh = array.get(bullish_high_holder,i)
currentlow = array.get(bullish_low_holder,i)
currenttop = box.get_top(currentgap)
delete_fvg_func(currentgap,currentgap_fill,i,bullishgapholder,bullishgapholder_fill
,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder)
if array.size(bearishgapholder) > 0
for i = array.size(bearishgapholder)-1 to 0
currentgap_fill = array.get(bearishgapholder_fill,i)
currentgap = array.get(bearishgapholder,i)
cmid = array.get(bearishmidholder,i)
chigh = array.get(bearish_high_holder,i)
clow = array.get(bearish_low_holder,i)
line.set_x2(cmid,timenow+(timediff)*20)
line.set_x2(chigh,timenow+(timediff)*20)
line.set_x2(clow,timenow+(timediff)*20)
box.set_right(currentgap_fill,timenow+(timediff)*20)
box.set_right(currentgap,timenow+(timediff)*20)
currenttop = box.get_top(currentgap)
currentmid = array.get(bearishmidholder,i)
currenthigh = array.get(bearish_high_holder,i)
currentlow = array.get(bearish_low_holder,i)
fvg_removed
if is_newbar(i_tf)
htfH := high
htfL := low
// }
fvg_gap=0
fvg_removed=validate_fvg_func(high,low)
if array.size(bullishgapholder) > 4
d_box=array.shift(bullishgapholder)
box.delete(d_box)
if array.size(bullishgapholder_fill) > 4
d_box=array.shift(bullishgapholder_fill)
box.delete(d_box)
if array.size(bullishmidholder) > 4
d_line=array.shift(bullishmidholder)
line.delete(d_line)
if array.size(bullish_high_holder) > 4
d_line=array.shift(bullish_high_holder)
line.delete(d_line)
if array.size(bullish_low_holder) > 4
d_line=array.shift(bullish_low_holder)
line.delete(d_line)
if array.size(bearishgapholder) > 4
d_box_=array.shift(bearishgapholder)
box.delete(d_box_)
if array.size(bearishgapholder_fill) > 4
d_box_=array.shift(bearishgapholder_fill)
box.delete(d_box_)
if array.size(bearishmidholder) > 4
d_line_=array.shift(bearishmidholder)
line.delete(d_line_)
if array.size(bearish_high_holder) > 4
d_line_=array.shift(bearish_high_holder)
line.delete(d_line_)
if array.size(bearish_low_holder) > 4
d_line_=array.shift(bearish_low_holder)
line.delete(d_line_)
n2=bar_index
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
//--------------------------------------------------------------- Liquidity
Levels
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
// --
highLineColor = highLineColorHTF//input.color(#1f4ef5, "High Line   ", group
= liquidity_level_group, inline = "1")
lowLineColor = lowLineColorHTF//input.color(#fd441c, "Low Line", group =
liquidity_level_group, inline = "1")
highBoxBgColor = highLineColorHTF//input.color(color.new(#1f4ef5, 80), "High Box
Bg ", group = liquidity_level_group, inline = "2")
highBoxBorderColor = highBoxBorderColorHTF//input.color(color.new(#1f4ef5, 80),
"Box Border", group = liquidity_level_group, inline = "2")
lowBoxBgColor = lowLineColorHTF//input.color(color.new(#fd441c, 80), "Low Box
Bg  ", group = liquidity_level_group, inline = "3")
lowBoxBorderColor = lowBoxBorderColorHTF//input.color(color.new(#fd441c, 80), "Box
Border", group = liquidity_level_group, inline = "3")
atr_liq = ta.atr(300)
tf_multi(tf) =>
ts = timeframe.in_seconds("")
htfs = timeframe.in_seconds(tf)
htfs/ts
display_limit_line(_array) =>
if array.size(_array) > 6/2
a = array.shift(_array)
line.delete(a)
display_limit_box(_array) =>
if array.size(_array) > 6/2
a = array.shift(_array)
box.delete(a)
extend_line_to_current(lineArray) =>
if array.size(lineArray) > 0
for i = array.size(lineArray) - 1 to 0 by 1
l = array.get(lineArray, i)
timeExt = timenow + ((timediff)*20)
line.set_x2(l, timeExt)
extend_box_to_current(boxArray) =>
if array.size(boxArray) > 0
for i = array.size(boxArray) - 1 to 0 by 1
b = array.get(boxArray, i)
timeExt = timenow + ((timediff)*20)
box.set_right(b, timeExt)
// ----------------------------------------------------
// Higher TimeFrame
// ----------------------------------------------------
// Varibles
// Lines
var highLineArrayHTF = array.new_line()
var lowLineArrayHTF = array.new_line()
// Boxes
var highBoxArrayHTF = array.new_box()
var lowBoxArrayHTF = array.new_box()
// Get HTF
[_time, _open, _high, _low, _close] = request.security(syminfo.tickerid, htfTF,
[time, open, high, low, close])
// Pivots
pivotHighHTF = ta.pivothigh(_high, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
pivotLowHTF = ta.pivotlow(_low, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
if currentTF
timeExt = time+((time[1]-time[2])*10)
dis = 8+tf_multi(htfTF)
if pivotHighHTF
if displayStyle_liq == "Lines"
array.push(highLineArrayHTF,
line.new(_time[dis],_high[dis],_time[+1],_high[dis],color = highLineColorHTF,
style=highLineStyleHTF, xloc=xloc.bar_time, width = lineWidthHTF))
else
y1 = _high[dis]-thold_liq//math.max(_open[dis], _close[dis])
array.push(highBoxArrayHTF,
box.new(_time[dis],_high[dis],_time[+1],y1,bgcolor = highLineColorHTF,
border_color=highBoxBorderColorHTF, xloc=xloc.bar_time, border_style =
highLineStyleHTF, border_width = lineWidthHTF))
if pivotLowHTF
if displayStyle_liq == "Lines"
array.push(lowLineArrayHTF,
line.new(_time[dis],_low[dis],_time[+1],_low[dis],color = lowLineColorHTF,
style=highLineStyleHTF, xloc=xloc.bar_time, width = lineWidthHTF))
else
y1 = _low[dis]+thold_liq//math.min(_open[dis], _close[dis])
array.push(lowBoxArrayHTF,
box.new(_time[dis],_low[dis],_time[+1],y1,bgcolor = lowLineColorHTF,
border_color=lowBoxBorderColorHTF, xloc=xloc.bar_time, border_style =
highLineStyleHTF, border_width = lineWidthHTF))
// ----------------------------------------------------
// Run Functions
// ----------------------------------------------------
highLineAlertHTF = remove_mitigated_lines(highLineArrayHTF, "High")
lowLineAlertHTF = remove_mitigated_lines(lowLineArrayHTF, "Low")
highBoxAlertHTF = remove_mitigated_boxes(highBoxArrayHTF, "High")
lowBoxAlertHTF = remove_mitigated_boxes(lowBoxArrayHTF, "Low")
extend_line_to_current(highLineArrayHTF)
extend_line_to_current(lowLineArrayHTF)
extend_box_to_current(highBoxArrayHTF)
extend_box_to_current(lowBoxArrayHTF)
// Alerts
alertcondition(pivotHighHTF, "High Liquidity Level", "High Liquidity Level Found
Ez-SMC")
alertcondition(pivotLowHTF, "Low Liquidity Level", "Low Liquidity Level Found Ez-
SMC")
swing_bull_css = bosColor1
swing_bear_css = bosColor2
var bullish_col_ChoCH = swing_bull_css
var bearish_col_ChoCH = swing_bear_css
var internal_bullish_col_ChoCH = bosColor1
var internal_bearish_col_ChoCH = bosColor2
[high_ms, low_ms] = calculate_swing_points(length)
n := bar_index
//HL Output function
hl() => [high, low]
var float thold = (ta.highest(300) - ta.lowest(300)) * math.max(0.5, 0.1) / 100.
internal_structure_lbl_size=size.small
[int_high_ms, int_low_ms] = calculate_swing_points(swingSize)
swing_structure_lbl_size=size.small
if low_ms
crossed_down := true
y_dn := low_ms
x_dn := n2-length
if high_ms
crossed_up := true
y_up := high_ms
x_up := n2 - length
if int_low_ms
internal_dn_broke := true
internal_y_dn := int_low_ms
internal_x_dn := n2 - swingSize
if int_high_ms
internal_up_broke := true
internal_y_up := int_high_ms
internal_x_up := n2 - swingSize
bull_ChoCH=false,bull_ChoCH_=false,bull_bos=false,bull_bos_=false,bear_ChoCH=false,
bear_ChoCH_=false,bear_bos=false,bear_bos_=false
if ta.crossover(close, internal_y_up) and internal_up_broke and y_up !=
internal_y_up
bool ChoCH = na
ChoCH := int_t_MS < 0
internal_up_broke := false
int_t_MS := 1
bull_ChoCH:=ChoCH?true:false
bull_bos:=ChoCH?false:true
if showms
Show_MS(internal_x_up, internal_y_up, ChoCH ? 'ChoCH' : 'BOS',
internal_bullish_col_ChoCH, true, true, internal_structure_lbl_size)
if ta.crossunder(close, internal_y_dn) and internal_dn_broke and y_dn !=
internal_y_dn
bool ChoCH = false
ChoCH := int_t_MS > 0
internal_dn_broke := false
int_t_MS := -1
bear_ChoCH:=ChoCH?true:false
bear_bos:=ChoCH?false:true
if showms
Show_MS(internal_x_dn, internal_y_dn, ChoCH ? 'ChoCH' : 'BOS',
internal_bearish_col_ChoCH, true, false, internal_structure_lbl_size)
//-----------------------------------------------------------------------------}
//Order Blocks
//-----------------------------------------------------------------------------{
first_nonzero_digit(n) =>
s = str.tostring(n)
type_obs="none"
valid=false
H=high
L=low
O=open
C=close
V=volume
idx=1
volume_=0.0
b_volume=0
s_volume=0
use_max=false
min = 99999999.
max = 0.
if valid
ind=0
thold_ = (ta.highest(300) - ta.lowest(300)) * (3/2.) / 100.
volume_:=V
//Search for highest/lowest high within the structure interval and get
range
if use_max
max:=H//[idx]
min_1=L//[idx]//H[1]-math.min(open[1],close[1])>ob_threshold
min:=math.max(min_1,max-thold_)
else
max_1=H//[idx]//math.max(open[idx],close[idx])
min:=L//[idx]
max:=math.min(max_1,min+thold_)
[valid,volume_,b_volume,s_volume,max,min,idx,use_max ? -1 : 1,type_obs]
for i = 0 to size-1
get_box = array.get(boxes, i)
get_line = array.get(lines, i)
max_left=bar_index-750
volume_sum=array.sum(vol)
volume_=array.get(vol, i)>100000000 ? array.get(vol, i)/100000000.:
array.get(vol, i)>1000000 ? array.get(vol, i)/1000000. : array.get(vol, i)/1000.
volume_per=(array.get(vol, i)/volume_sum)*100
unit=array.get(vol, i)>100000000 ?' B': array.get(vol, i)>1000000 ?' M' : '
K'
text_vol=vol_text and perct_text ? tf_text + str.tostring(volume_,'#.##')+
unit + ' ('+ str.tostring(volume_per,'#.##')+'%)' : vol_text and not(perct_text) ?
tf_text + str.tostring(volume_,'#.##')+ unit : not(vol_text) and perct_text ?
tf_text + ' '+ str.tostring(volume_per,'#.##')+'%' : tf_text_2+ ''
if true//max_left<array.get(target_left, i)
box.set_lefttop(get_box, array.get(target_left, i),
array.get(target_top, i))
box.set_rightbottom(get_box,timenow+((timediff)*length_extend_ob) ,
array.get(target_btm, i))
box.set_text(get_box,text_vol)
box.set_text_color(get_box,text_color_ob)
box.set_border_color(get_box,color.gray)
box.set_border_width(get_box,2)
box.set_text_halign(get_box,text.align_right)
box.set_text_valign(get_box,text.align_center)
box.set_text_size(get_box,ob_text_size)
fully_extend=not(vol_text) and not(perct_text) and ob_extend?
extend.right : extend.none
len_ext=not(vol_text) and not(perct_text)?length_extend_ob :
length_extend_ob/2
line.set_extend(get_line,fully_extend)
line.set_style(get_line,line_style_obs)
line.set_xy1(get_line,array.get(target_left, i),array.get(target_top,
i)-(array.get(target_top, i) - array.get(target_btm, i))/2)
line.set_xy2(get_line,time+((timediff)*(len_ext)),array.get(target_top,
i)-(array.get(target_top, i) - array.get(target_btm, i))/2)
if show_line_obs
line.set_color(get_line,color.gray)
if ob_extend
box.set_extend(get_box, extend.right)
color css = na
css := array.get(target_type, i) == 1 ? col_1 : col_2
box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)
box.set_border_color(get_box, css)
time_diff()=>((time[1]-time[101])/100)
//-----------------------------------------------------------------------------}
//Order Blocks Arrays
//-----------------------------------------------------------------------------{
bar_merge=barmerge.gaps_off
look_bars=barmerge.lookahead_on
[valid_ob,volume_,b_volume,s_volume,top_ob,btm_ob,left_ob,type_ob,_type]=request.se
curity(ticker.standard(syminfo.tickerid), i_tf_ob,
ob_found(x_up,bar_index,show_ob,show_iob), bar_merge,look_bars)
tf1_time=request.security(ticker.standard(syminfo.tickerid),i_tf_ob,time_diff(),
bar_merge,look_bars)
if array.size(ob_top)>4// or array.get(ob_left,array.size(ob_left)-1)>bar_index-400
array.pop(ob_top)
array.pop(ob_btm)
array.pop(ob_left)
array.pop(ob_type)
array.pop(ob_buy_vol)
array.pop(ob_sell_vol)
array.pop(ob_vol)
if array.size(ob_top)>1
for index=0 to array.size(ob_top)-1
src1= low
src2= high
up= array.get(ob_btm, index)
dn= array.get(ob_top, index)
// iob_size = array.size(iob_type)
ob_size = array.size(ob_type)
if barstate.islast
if true
for i = 0 to 4-1
array.push(ob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
array.push(ob_boxes_buy, box.new(na,na,na,na, xloc = xloc.bar_time))
array.push(ob_boxes_sell, box.new(na,na,na,na, xloc = xloc.bar_time))
array.push(ob_volume, line.new(na,na,na,na,xloc =
xloc.bar_time,color=color.gray,style=line.style_solid,width = 1))
if ob_size > 1
[deleted_ob,del_index]=remove_ob(ob_top, ob_btm, ob_left, ob_type, 4, false,
ob_size)
if deleted_ob
array.remove(ob_top, del_index)
array.remove(ob_btm, del_index)
array.remove(ob_left, del_index)
array.remove(ob_type, del_index)
array.remove(ob_buy_vol, del_index)
array.remove(ob_sell_vol, del_index)
array.remove(ob_vol, del_index)
// iob_size := array.size(iob_type)
ob_size := array.size(ob_type)
//
===================================================================================
=======