EzAlgo_V9
EzAlgo_V9
EzAlgo_V9
// User Input
showReversal = input(true, "Buy/Sell", group="REVERSAL INDICATORS", inline =
'rev1', tooltip = "use ONLY in confluence with any of the price action tools listed
below")
colorBuy = input.color(#00dbff99, '', group="REVERSAL INDICATORS", inline=
'rev1')
colorSell = input.color(#e91e6399, '', group="REVERSAL INDICATORS", inline=
'rev1')
obos = input(true, "O.S/O.B", group="REVERSAL INDICATORS", inline =
'rev2', tooltip = "Oversold/Overbought Conditions. Bigger Reversals usually happen
after these conditions, however a market can stay in these conditions for a long
time. Oversold & Overbought is not a reversal signal in itself however when used in
confluence with S/R and other momentum signals can be powerful")
colorOs = input.color(#00dbff48, '', group="REVERSAL INDICATORS", inline=
'rev2')
colorOb = input.color(#e91e6348, '', group="REVERSAL INDICATORS", inline=
'rev2')
showRibbon = input(true, "Trend Ribbon", group="REVERSAL INDICATORS",
tooltip = "Change in Ribbon Color signals a shift in trend. Best used in trending
markets to spot early signs of reversals")
uptrend = input(#00dbff66, "Uptrend", group="REVERSAL INDICATORS")
downtrend = input(#e91e6366, "Downtrend", group="REVERSAL INDICATORS")
showRevBands = input(false, "Reversal Bands", group="REVERSAL INDICATORS",
tooltip = "Plots the average upper and lower bounds of price movement. Price could
see a reversal when it approaches these boundaries. Use in confluence with other
Support & Resistance")
colorupperband = input(#e91e6333, "Upper Bands", group="REVERSAL INDICATORS")
colorlowerband = input(#00dbff33, "Lower Bands", group="REVERSAL INDICATORS")
showEmas = input(false, "Moving Average S/R", group="SUPPORT &
RESISTANCE", tooltip = "Three powerful Moving Averages. Price tends to respect
these MAs making them invaluable as they act as S/R & help in identifying trend
shifts")
colorEma1 = input(#eaeaea40, "Moving Average 1", group="SUPPORT &
RESISTANCE")
colorEma2 = input(#00dbff40, "Moving Average 2", group="SUPPORT &
RESISTANCE")
colorEma3 = input(#e91e6340, "Moving Average 3", group="SUPPORT &
RESISTANCE")
currentTF = input.bool(false, title = "Liquidity Levels", group="SUPPORT &
RESISTANCE", tooltip = "Zones of high volume activity before price moves in one
direction. Price usually comes back to these levels to 'sweep' the liquidity by
triggering stop losses to gather the fuel to propel itself back into the opposite
direction. If price is approaching down to a liquidity zone, it tends to go
slightly below the zone before quickly reversing back to the upside and vice versa
for a bearish move. A common zone where swing failure pattern occurs. However it is
highly risky to place limit orders at these zones as the price may not respect it
at all and pass through with no resistance. Use ONLY in confluence with other S/R
tools")
lowLineColorHTF = input.color(#efd09e50, "Bullish", group="SUPPORT & RESISTANCE")
highLineColorHTF = input.color(#ff7f5050, "Bearish", group="SUPPORT & RESISTANCE")
htfTF = input.timeframe("240", title = "Timeframe", group="SUPPORT &
RESISTANCE")
show_fvg = input(false, 'Fair Value Gaps', group="SUPPORT & RESISTANCE",
tooltip = "Fair Value Gaps occur when a Price leaves a specific level where there's
less trading activity seen and only has a one-directional price movement. Typically
these occur during aggressive trends where the the orders of the market makers do
not get filled. Similar to order blocks price tends to re visit these zones at a
later time")
i_mtfbearishfvgcolor = input.color(#226f54, "Bullish", group="SUPPORT &
RESISTANCE")
i_mtfbullishfvgcolor = input.color(#f1abb9, "Bearish", group="SUPPORT &
RESISTANCE")
i_tf = input.timeframe("240", "Timeframe", group="SUPPORT &
RESISTANCE")
autofib = input(true, "Auto Golden Pocket", group="SUPPORT & RESISTANCE",
tooltip = "The 0.5 and 0.618-65 Fibonacci Ratio often acts as a balancing point in
the market. Finding consecutive candle closes above the 0.5-0.65 is a sign of
strength, and finding consecutive candle closes under the 0.5-0.65 is a sign of
weakness")
colorAll = input.color(#D1B000, "Color", group="SUPPORT & RESISTANCE")
timeframe = input.timeframe(defval = '240', group="SUPPORT & RESISTANCE")
showVP = input(true, "Volume Profile", group="SUPPORT & RESISTANCE",
tooltip = "Volume profile scans a range of price action by looking back at previous
price action to determine the level at which the highest Volume has been traded.
This level is called the Point of Control which acts as a magnet attracting the
price. When tested from the underside it can be a strong resistance and when tested
from above it can be a strong support")
vp_bar_color = input(defval=color.new(color.gray, 60), title='Volume Bars')
vp_poc_color = input(defval=#eaeaea, title='Point of Control')
showms = input(false,title="ChoCH & BoS", group = "MARKET STRUCTURE",
tooltip = "Change of character means, the market has changed its trend or order
flow over a period of time. “Break of Structure” is used to describe a significant
price movement that surpasses a crucial level of support or resistance on a
chart.")
bosColor1 = input.color(#0097a7 , 'Bullish', group = "MARKET STRUCTURE")
bosColor2 = input.color(#c2185b , 'Bearish', group = "MARKET STRUCTURE")
showGann = input(false, 'Gann Swing (One Bar Key Pivot Points)', group =
"MARKET STRUCTURE", tooltip = "The core technique used by the legendary trader W.D
Gann. A simple yet powerful tool that tracks the 'swing' of the price, clearly
showing the key pivot points. An excellent tool to track market structure,
breakouts, swing failure patterns & setting stop losses. A close above a key swing
high is considered bullish and close below a key swing low is bearish")
colorGann = input(#ff7f50, 'Swing Line', group = "MARKET STRUCTURE")
showDashboard = input(true, "Enable", group = "TREND DASHBOARD")
tableTextColor = input(color.white, "Text", group = "TREND DASHBOARD")
tableBgColor = input(#13172232, "Background", group = "TREND DASHBOARD")
// Functions
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
securityNoRep(sym, res, src) => request.security(sym, res, src, barmerge.gaps_off,
barmerge.lookahead_on)
f_chartTfInMinutes() =>
float _resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
f_kc(src, len, sensitivity) =>
basis = ta.sma(src, len)
span = ta.atr(len)
[basis + span * sensitivity, basis - span * sensitivity]
// Get components
source = close
smrng1 = smoothrng(source, 27, 1.5)
smrng = (smrng1)
filt = rngfilt(source, smrng)
up = 0.0, up := filt > filt[1] ? nz(up[1]) + 1 : filt < filt[1] ? 0 :
nz(up[1])
dn = 0.0, dn := filt < filt[1] ? nz(dn[1]) + 1 : filt > filt[1] ? 0 :
nz(dn[1])
bullCond = bool(na), bullCond := source > filt and source > source[1] and up > 0
or source > filt and source < source[1] and up > 0
bearCond = bool(na), bearCond := source < filt and source < source[1] and dn > 0
or source < filt and source > source[1] and dn > 0
lastCond = 0, lastCond := bullCond ? 1 : bearCond ? -1 : lastCond[1]
bull = bullCond and lastCond[1] == -1
bear = bearCond and lastCond[1] == 1
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
ribbon1 = ta.ema(hlc3, 8)
ribbon2 = ta.ema(hlc3, 13)
rsi = ta.rsi(hlc3, 21)
rsiOb = rsi > 70 and rsi > ta.ema(rsi, 13)
rsiOs = rsi < 30 and rsi < ta.ema(rsi, 13)
ema1 = ta.ema(hlc3, 21)
ema2 = ta.ema(hlc3, 34)
ema3 = ta.ema(hlc3, 55)
ema = ta.ema(hlc3, 21)
emaBull = close > ema
// Colors
cyan = #00dbff, cyan30 = color.new(cyan, 70)
pink = #e91e63, pink30 = color.new(pink, 70)
// Plot
plotshape(showReversal and ta.crossover(wt1, wt2) and wt2 <= -55, "Reversal Buy" ,
shape.labelup, location.belowbar, color = colorBuy, size=size.small)
plotshape(showReversal and ta.crossunder(wt1, wt2) and wt2 >= 55, "Reversal Sell",
shape.labeldown, location.abovebar, color = colorSell, size=size.small)
plotshape(showReversal and rsiOs, "Oversold" , shape.diamond, location.belowbar,
color = colorOs, size=size.tiny)
plotshape(showReversal and rsiOb, "Overbought", shape.diamond, location.abovebar,
color = colorOb, size=size.tiny)
plot(showEmas ? ema1 : na, "Moving Average 1", colorEma1, 2)
plot(showEmas ? ema2 : na, "Moving Average 2", colorEma2, 2)
plot(showEmas ? ema3 : na, "Moving Average 3", colorEma3, 2)
var dashboard_loc = position.top_right
var dashboard_size = size.small
var dashboard = showDashboard ? table.new(dashboard_loc, 3, 15, tableBgColor,
#000000, 2, tableBgColor, 1) : na
dashboard_cell(column, row, txt, signal=false) => table.cell(dashboard, column,
row, txt, 0, 0, signal ? #000000 : tableTextColor, text_size=dashboard_size)
dashboard_cell_bg(column, row, col) => table.cell_set_bgcolor(dashboard, column,
row)
if barstate.islast and showDashboard
dashboard_cell(0, 0, "Timeframe")
dashboard_cell(0, 1, "Chart")
dashboard_cell(0, 2, "5 min")
dashboard_cell(0, 3, "15 min")
dashboard_cell(0, 4, "30 min")
dashboard_cell(0, 5, "1H")
dashboard_cell(0, 6, "4H")
dashboard_cell(0, 7, "Daily")
dashboard_cell(1, 0, "Bias")
dashboard_cell(1, 1, emaBull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 1,
emaBull)
dashboard_cell(1, 2, TF5Bull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 2,
TF5Bull)
dashboard_cell(1, 3, TF15Bull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 3,
TF15Bull)
dashboard_cell(1, 4, TF30Bull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 4,
TF30Bull)
dashboard_cell(1, 5, TF60Bull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 5,
TF60Bull)
dashboard_cell(1, 6, TF240Bull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 6,
TF240Bull)
dashboard_cell(1, 7, TFDBull ? "🟢" : "🔴", true), dashboard_cell_bg(1, 7,
TFDBull)
dashboard_cell(2, 0, "Strength")
dashboard_cell(2, 1, adxstrong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 1,
adxstrong)
dashboard_cell(2, 2, TF5Strong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 2,
TF5Strong)
dashboard_cell(2, 3, TF15Strong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 3,
TF15Strong)
dashboard_cell(2, 4, TF30Strong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 4,
TF30Strong)
dashboard_cell(2, 5, TF60Strong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 5,
TF60Strong)
dashboard_cell(2, 6, TF240Strong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 6,
TF240Strong)
dashboard_cell(2, 7, TFDStrong ? "🚀🚀" : "🚀", true), dashboard_cell_bg(2, 7,
TFDStrong)
// Alerts
alert01 = ta.crossover(wt1, wt2) and wt2 <= -55
alert02 = ta.crossunder(wt1, wt2) and wt2 >= 55
alerts(sym) =>
if alert01 or alert02
alert_text = alert01 ? "Buy Signal" : alert02 ? "Sell Signal" : "Buy Signal
, Sell Signal"
alert(alert_text, alert.freq_once_per_bar_close)
alerts(syminfo.tickerid)
alertcondition(alert01, "Buy Alert", "Buy Signal, TimeFrame={{interval}}")
alertcondition(alert02, "Sell Alert", "Sell Signal, TimeFrame={{interval}}")
find_loc(strength) =>
ret = array.size(sr_strength)
for i = ret > 0 ? array.size(sr_strength) - 1 : na to 0 by 1
if strength <= array.get(sr_strength, i)
break
ret := i
ret
ret
if ph or pl
//because of new calculation, remove old S/R levels
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
//find S/R zones
for x = 0 to array.size(pivotvals) - 1 by 1
[hi, lo, strength] = get_sr_vals(x)
if check_sr(hi, lo, strength)
loc = find_loc(strength)
// if strength is in first levels sr then insert it to the arrays
if loc < levels and strength >= min_strength
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
// keep size of the arrays = 5
if array.size(sr_strength) > levels
array.pop(sr_strength)
array.pop(sr_up_level)
array.pop(sr_dn_level)
for x = 1 to 10 by 1
line.delete(array.get(sr_lines, x))
label.delete(array.get(sr_labels, x))
label.delete(array.get(timef_labels, x))
f_crossed_over() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if close[1] <= mid and close > mid
ret := true
ret
ret
f_crossed_under() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if close[1] >= mid and close < mid
ret := true
ret
ret
styleGann = line.style_solid
var arrayXGann = array.new_int(5,time)
var arrayYGann = array.new_float(5,close)
var arrayLineGann = array.new_line()
int drawLineGann = 0
_high = request.security(syminfo.tickerid,"",high,lookahead=barmerge.lookahead_on)
_low = request.security(syminfo.tickerid,"",low,lookahead=barmerge.lookahead_on)
_close =
request.security(syminfo.tickerid,"",close,lookahead=barmerge.lookahead_on)
_open = request.security(syminfo.tickerid,"",open,lookahead=barmerge.lookahead_on)
highPrev = _high
lowPrev = _low
// drawLineGann
drawLineGann := 0
if(_high[0] > highPrev[1] and _low[0] > lowPrev[1])
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(_high[0] > array.get(arrayYGann,0))
if(_high[0] <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high[0])
drawLineGann := 2
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
drawLineGann := 1
else if(_high[0] < highPrev[1] and _low[0] < lowPrev[1])
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
drawLineGann := 1
else
if(_low[0] < array.get(arrayYGann,0))
if(_low[0] >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low[0])
drawLineGann := 2
else if((_high[0] >= highPrev[1] and _low[0] < lowPrev[1]) or (_high[0] >
highPrev[1] and _low[0] <= lowPrev[1]))
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(_high[0] >= array.get(arrayYGann,0) and array.get(arrayYGann,1) <=
_low[0])
if(_high[0] <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high[0])
drawLineGann := 2
else if(_high[0] >= array.get(arrayYGann,0) and array.get(arrayYGann,1) >=
_low[0])
if(_close < _open)
if(_high[0] <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
drawLineGann := 3
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
drawLineGann := 4
else if(array.get(arrayYGann,0) < array.get(arrayYGann,1))
if(_low[0] <= array.get(arrayYGann,0) and _high[0] <=
array.get(arrayYGann,1))
if(_low[0] >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low[0])
drawLineGann := 2
else if(_low[0] <= array.get(arrayYGann,0) and _high[0] >=
array.get(arrayYGann,1))
if(_close > _open)
if(_low[0] >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
drawLineGann := 3
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
drawLineGann := 4
else
if(array.get(arrayYGann,0) >= low)
array.set(arrayXGann, 0, time)
drawLineGann := 2
if(showGann and timeframe.in_seconds())
if(drawLineGann == 2)
if(array.size(arrayLineGann) >0)
line.set_xy2(array.get(arrayLineGann,0),array.get(arrayXGann,0),array.get(arrayYGan
n,0))
else
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time,width = 1,style=line.style_solid))
else if(drawLineGann == 1)
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time,width = 1,style=line.style_solid))
else if(drawLineGann == 3)
if(array.size(arrayLineGann) >0)
line.set_xy2(array.get(arrayLineGann,0),array.get(arrayXGann,1),array.get(arrayYGan
n,1))
else
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,2),array.get(arrayYGann,2
),array.get(arrayXGann,1),array.get(arrayYGann,1), color = colorGann,xloc =
xloc.bar_time,width = 1,style=line.style_solid))
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time,width = 1,style=line.style_solid))
else if(drawLineGann == 4)
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,2),array.get(arrayYGann,2
),array.get(arrayXGann,1),array.get(arrayYGann,1), color = colorGann,xloc =
xloc.bar_time,width = 1,style=line.style_solid))
array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time,width = 1,style=line.style_solid))
getMultiTfPivots()=>
float ab = ta.pivothigh(2, 2)
float cd = ta.pivotlow(2, 2)
phBIndexS = ab ? time[2] : na
plBIndexS = cd ? time[2] : na
// Special case: where high & low detected at the same time.
if not na(pivothigh) and not na(pivotlow)
lastPivotP := isHighLast ? cd : ab
curPivotP := isHighLast ? ab : cd
lastPivotBi := isHighLast ? plBIndexS : phBIndexS
curPivotBi := isHighLast ? phBIndexS : plBIndexS
// All cases
else
isHighLast := not na(pivothigh) ? true : not na(pivotlow) ? false :
isHighLast
labelOffset = 3
if autofib
line.delete(fib0500Line)
label.delete(fib0500Label)
fib0500Line := line.new(barLastUpdate, fib0500, time, fib0500,
xloc=xloc.bar_time, color=colorAll, width=1)
fib0500Label := label.new(x=bar_index + labelOffset, y = fib0500,
xloc=xloc.bar_index, text=str.tostring(0.5), style=label.style_none,
size=size.small, textcolor=colorAll, textalign=text.align_center)
if autofib
line.delete(fib0618Line)
label.delete(fib0618Label)
fib0618Line := line.new(barLastUpdate, fib0618, time, fib0618,
xloc=xloc.bar_time, color=colorAll, width=1)
fib0618Label := label.new(x=bar_index + labelOffset, y = fib0618,
xloc=xloc.bar_index, text=str.tostring(0.618), style=label.style_none,
size=size.small, textcolor=colorAll, textalign=text.align_center)
if autofib
line.delete(fib0650Line)
label.delete(fib0650Label)
fib0650Line := line.new(barLastUpdate, fib0650, time, fib0650,
xloc=xloc.bar_time, color=colorAll, width=1)
fib0650Label := label.new(x=bar_index + labelOffset, y = fib0650,
xloc=xloc.bar_index, text=str.tostring(0.650), style=label.style_none,
size=size.small, textcolor=colorAll, textalign=text.align_center)
// VARIABLES //
if barstate.islast
float vp_HL = (vp_HH - vp_LL) / vp_N_BARS
for j = 1 to vp_N_BARS + 1 by 1
array.set(vp_a_P, j - 1, vp_LL + vp_HL * j)
for i = 0 to 233 - 1 by 1
int Dc = 0
array.fill(vp_a_D, 0.0)
for j = 0 to vp_N_BARS - 1 by 1
float Pj = array.get(vp_a_P, j)
if low[i] < Pj and high[i] > Pj
float Dj = array.get(vp_a_D, j)
float dDj = Dj + nz(volume[i])
array.set(vp_a_D, j, dDj)
Dc += 1
Dc
for j = 0 to vp_N_BARS - 1 by 1
float Vj = array.get(vp_a_V, j)
float Dj = array.get(vp_a_D, j)
float dVj = Vj + (Dc > 0 ? Dj / Dc : 0.0)
array.set(vp_a_V, j, dVj)
vp_Vmax := array.max(vp_a_V)
vp_VmaxId := array.indexof(vp_a_V, vp_Vmax)
for j = 0 to vp_N_BARS - 1 by 1
float Vj = array.get(vp_a_V, j)
int Aj = math.round(30 * Vj / vp_Vmax)
array.set(vp_a_W, j, Aj)
// PLOTTING //
f_setup_bar(n) =>
x1 = vp_VmaxId == n ? math.max(time[233], vp_first) : timenow +
math.round(vp_change * (60 - array.get(vp_a_W, n)))
ys = array.get(vp_a_P, n)
line.new(x1=x1, y1=ys, x2=vp_x_loc, y2=ys, xloc=xloc.bar_time,
extend=extend.none, color=vp_VmaxId == n ? vp_poc_color : vp_bar_color,
style=line.style_solid, width=1)
//----------------------------------------}
//Order Blocks
//----------------------------------------{
v_buy = #00dbff4d
v_sell = #e91e634d
timeframe1=' : '
show_iob = 'All'=='All' or 'All'=='Internal'
show_ob = 'All'=='All' or 'All'=='External'
ob_showlast = 5
iob_showlast = 5
styleSMC = 'Colored'
v_lookback= 10
ob_loockback=10
timediff=(time[1]-time[101])/100
//----------------------------------------}
//Liquidity Levels
//----------------------------------------{
_highLineStyleHTF = "Solid"
highLineStyleHTF = _highLineStyleHTF=="Solid" ? line.style_solid :
_highLineStyleHTF=="Dashed" ? line.style_dashed : line.style_dotted
box_width = 2.5
lineWidthHTF=2
highBoxBorderColorHTF = color.new(highLineColorHTF,90)
lowBoxBorderColorHTF = color.new(lowLineColorHTF,90)
displayStyle_liq = "Boxes"
//----------------------------------------}
//Fair Value Gaps (FVG)
//----------------------------------------{
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
swingSize = 8
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
color transparent = #ffffff00
length = 50
is_newbar(res) =>
t = time(res)
not na(t) and (na(t[1]) or t > t[1])
//Swings detection/measurements
calculate_swing_points(length)=>
var prev = 0
prev := high[length] > ta.highest(length) ? 0 : low[length] < ta.lowest(length)
? 1 : prev[1]
t = prev == 0 and prev[1] != 0 ? high[length] : 0
b = prev == 1 and prev[1] != 1 ? low[length] : 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 bullishgapholder_fill = array.new_box(0)
var bearishgapholder_fill = array.new_box(0)
var bullish_high_holder = array.new_line(0)
var bearish_high_holder = array.new_line(0)
var bullish_low_holder = array.new_line(0)
var bearish_low_holder = array.new_line(0)
var bullishmidholder = array.new_line(0)
var bearishmidholder = array.new_line(0)
var bullishlabelholder = array.new_label(0)
var bearishlabelholder = array.new_label(0)
var transparentcolor = color.new(color.white,100)
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(smcclose,smchigh,_highp2,smclow,_lowp2,smcopen,_bar,_htf)=>
gap=0
thold_ = (ta.highest(smchigh,300) - ta.lowest(smclow,300)) * math.max(1.5, 0.1)
/ 100.
if smcopen > smcclose // red
if _lowp2>smchigh
if not(true) or math.abs(_lowp2 -smchigh) > thold_
upperlimit = smchigh
lowerlimit = _lowp2
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 smclow>_highp2
if not(true) or math.abs(smclow - _highp2) > thold_
upperlimit = smclow
lowerlimit = _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(smchigh,smclow)=>
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)
delete_fvg_func(currentgap,currentgap_fill,i,bearishgapholder,bearishgapholder_fill
,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder)
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_)
n=bar_index
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
//--------------------------------------------------------------- Liquidity
Levels
//---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------
// --
highLineColor = highLineColorHTF
lowLineColor = lowLineColorHTF
highBoxBgColor = highLineColorHTF
highBoxBorderColor = highBoxBorderColorHTF
lowBoxBgColor = lowLineColorHTF
lowBoxBorderColor = lowBoxBorderColorHTF
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, smcopen, smchigh, smclow, smcclose] = request.security(syminfo.tickerid,
htfTF, [time, open, high, low, close])
// Pivots
pivotHighHTF = ta.pivothigh(smchigh, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
pivotLowHTF = ta.pivotlow(smclow, 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],smchigh[dis],_time[+1],smchigh[dis],color = highLineColorHTF,
style=highLineStyleHTF, xloc=xloc.bar_time, width = lineWidthHTF))
else
y1 = smchigh[dis]-thold_liq
array.push(highBoxArrayHTF,
box.new(_time[dis],smchigh[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],smclow[dis],_time[+1],smclow[dis],color = lowLineColorHTF,
style=highLineStyleHTF, xloc=xloc.bar_time, width = lineWidthHTF))
else
y1 = smclow[dis]+thold_liq
array.push(lowBoxArrayHTF,
box.new(_time[dis],smclow[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 := n-length
if high_ms
crossed_up := true
y_up := high_ms
x_up := n - length
if int_low_ms
internal_dn_broke := true
internal_y_dn := int_low_ms
internal_x_dn := n - swingSize
if int_high_ms
internal_up_broke := true
internal_y_up := int_high_ms
internal_x_up := n - 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)
//-----------------------------------------------------------------------------}