Professional Documents
Culture Documents
1116
1116
st = input(false, title='ShowTrend')
upTrend = ma(type3, close, MA3) >= ma(type4, close, MA4)
downTrend = ma(type3, close, MA3) < ma(type4, close, MA4)
t1 = ma(type1, close, MA1)
t2 = ma(type2, close, MA2)
t3 = ma(type3, close, MA3)
t4 = ma(type4, close, MA4)
t11 = plot(show_Emas ? t1 : na, color=color.new(#3b78eb, 0), linewidth=1,
title='MA1')
t22 = plot(show_Emas ? t2 : na, color=color.new(#B45F04, 0), linewidth=2,
title='MA2')
t33 = plot(show_Emas ? t3 : na, color=st and upTrend ? color.lime : st and
downTrend ? color.red : #b83d27, linewidth=1, title='MA3')
t44 = plot(show_Emas ? t4 : na, color=st and upTrend ? color.lime : st and
downTrend ? color.red : #b83d27, linewidth=3, title='MA4')
////////////////////////
showhbs = input(false, title='------ Show heikin BuySell -----')
EMAlength = input(55, 'EMA LENGTH?')
srch = ohlc4
haOpen = 0.0
haOpen := (srch + nz(haOpen[1])) / 2
haC = (ohlc4 + nz(haOpen) + math.max(high, nz(haOpen)) + math.min(low, nz(haOpen)))
/ 4
EMA1 = ta.ema(haC, EMAlength)
EMA2 = ta.ema(EMA1, EMAlength)
EMA3 = ta.ema(EMA2, EMAlength)
TMA1 = 3 * EMA1 - 3 * EMA2 + EMA3
EMA4 = ta.ema(TMA1, EMAlength)
EMA5 = ta.ema(EMA4, EMAlength)
EMA6 = ta.ema(EMA5, EMAlength)
TMA2 = 3 * EMA4 - 3 * EMA5 + EMA6
IPEK = TMA1 - TMA2
YASIN = TMA1 + IPEK
EMA7 = ta.ema(hlc3, EMAlength)
EMA8 = ta.ema(EMA7, EMAlength)
EMA9 = ta.ema(EMA8, EMAlength)
TMA3 = 3 * EMA7 - 3 * EMA8 + EMA9
EMA10 = ta.ema(TMA3, EMAlength)
EMA11 = ta.ema(EMA10, EMAlength)
EMA12 = ta.ema(EMA11, EMAlength)
TMA4 = 3 * EMA10 - 3 * EMA11 + EMA12
IPEK1 = TMA3 - TMA4
YASIN1 = TMA3 + IPEK1
mavi = YASIN1
kirmizi = YASIN
last_signal = 0
long_final = longCond and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1)
short_final = shortCond and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)
/////////PARABOLIC SAR
show_ps = input(false, title='----------Show Parabolic SAR---------')
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, 'Max Value')
out = ta.sar(start, increment, maximum)
plot(show_ps ? out : na, 'ParabolicSAR', style=plot.style_cross,
color=color.new(#2962FF, 0))
///// END PARABOLIC SAR
nvim = ta.ema(ta.nvi, m)
nvimax = ta.highest(nvim, longitudNVI)
nvimin = ta.lowest(nvim, longitudNVI)
azul = (ta.nvi - nvim) * 100 / (nvimax - nvimin)
// Bands Calculation
basisK = ta.sma(tprice, boLength) //Find the 20-day moving average average (n1 +
n2 ... + n20)/20
devK = mult * ta.stdev(tprice, boLength) //Find the standard deviation of the 20-
days
upperK = basisK + devK //Upper Band = 20-day Moving Average + (2 x standard
deviation of the 20-days)
lowerK = basisK - devK //Lower Band = 20-day Moving Average - (2 x standard
deviation of the 20-days)
OB1 = (upperK + lowerK) / 2.0
OB2 = upperK - lowerK
////BOLLINGER BANDS
////////////////////
show_BB = input(false, title='--------- Show Bollinger ---------')
lengthB = input.int(20, minval=1)
srcB = input(close, title='Source')
//mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(srcB, lengthB)
dev = mult * ta.stdev(srcB, lengthB)
upper = basis + dev
lower = basis - dev
offsetB = input.int(0, 'Offset', minval=-500, maxval=500)
plot(show_BB ? basis : na, 'Basis', color=color.new(#919191, 0), offset=offsetB)
p1 = plot(show_BB ? upper : na, 'Upper', color=color.new(#ff0059, 0),
offset=offsetB)
p2 = plot(show_BB ? lower : na, 'Lower', color=color.new(#ff0059, 0),
offset=offsetB)
fill(p1, p2, title='Background', color=color.rgb(255, 205, 222, 95))
//////////////////
//// ICHIMOKU
///////////////////////////
//Input
show_ich = input(false, title='--------Show Ichimoku---------')
tenkanIN = input.int(9, minval=1, title='Tenkan')
kijunIN = input.int(26, minval=1, title='Kijun')
spanBIN = input.int(52, minval=1, title='Span B')
chikouIN = input.int(26, minval=1, title='Chikou')
srcI = input(close, title='Source')
//Setting
donchian(len) =>
math.avg(ta.lowest(len), ta.highest(len))
tenkan = donchian(tenkanIN)
kijun = donchian(kijunIN)
spanA = math.avg(tenkan, kijun)
spanB = donchian(spanBIN)
chikou = srcI
offset = -chikouIN
//Drawing
plot(show_ich ? tenkan : na, title='Tenkan', color=color.new(Color10, 0))
plot(show_ich ? kijun : na, title='Kijun', color=color.new(Color20, 0))
plot(show_ich ? srcI : na, offset=-chikouIN + 1, title='Chikou',
color=color.new(Color00, 0), linewidth=2)
kumoA = plot(show_ich ? spanA : na, offset=chikouIN - 1, title='Span A', color=na)
kumoB = plot(show_ich ? spanB : na, offset=chikouIN - 1, title='Span B', color=na)
fill(kumoA, kumoB, title='Kumo', color=show_ich ? colorKumo : na, transp=75)
version = 'v3.0'
int mbp = 1000
colorTip = ':\n ' + beName + ' - bearish FVG color\n ' + buName + ' - bullish
FVG color'
fvg_be_shared = input.color(color.new(#ff2525, 80), 'Shared Colors: ' + beName +
'/' + buName, group = FvgCat, inline = '0')
fvg_bu_shared = input.color(color.new(color.green, 80), '/', group = FvgCat, inline
= '0', tooltip = 'Shared Colors' + colorTip)
eo_None = 'None'
eo_ByFilledBar = 'Filling Candle'
custColorName = 'Cust Colors'
onTip = 'Shows/Hides chosen TF'
custColorTip = custColorName + colorTip
extendTip = extendName + ':\n ' + eo_Unextended + ' - shows fixed FVG area\n '
+ eo_BySceen + ' - extends FVG area all the way to the right\n ' + eo_ByLastBar +
' - extends FVG area to the last bar\n\nEnables/Disables custom colors\n\n' +
custColorTip
filledName = 'Filled'
fvg_f = input.bool(false, filledName, group = CurrentCat, inline = '0')
fvg_cc = input.bool(false, customColorName, group = CurrentCat, inline = '0')
fvg_f_bec = chooseColor2(fvg_cc, fvg_bec, input.color(defFvgColor, '', group =
CurrentCat, inline = '0'))
fvg_f_buc = chooseColor2(fvg_cc, fvg_buc, input.color(defFvgColor2, '/', group =
CurrentCat, inline = '0', tooltip = filledName + ' - shows/hides filled area\n\n' +
custColorTip))
//fvg_f = input.bool(false, 'filled', group = CurrentCat, inline = '0')
ff_FilledFVGsBack = 'Max Fills'
ff_FVGsBack = 'Last Unfilled'
fTip = 'From:\n ' + ff_FVGsBack + ' - shows filled FVGs by the first unfilled
FVG\n ' + ff_FilledFVGsBack + ' - sets max filled FVGs to show\n\nMax fills, used
when ' + ff_FilledFVGsBack+ ' option is chosen\n\nTo:\n ' + eo_ByFilledBar + '-
filled area is clipped by filling bar\n ' + eo_Unextended + ' - show fixed FVG
area\n\n'
fvg_ff = input.string(ff_FVGsBack, 'From', options = [ff_FVGsBack,
ff_FilledFVGsBack], group = CurrentCat, inline = '2')
fvg_fmax = input.int(10, '', minval = 1, maxval = 250, group = CurrentCat, inline =
'2')
fvg_ft = input.string(eo_ByFilledBar, 'To', options = [eo_ByFilledBar,
eo_Unextended], group = CurrentCat, inline = '2', tooltip = fTip)
labelName = 'Name'
timeframeTip = onTip + '\n\nTimeframe to display'
labelsTip = UWName + ' - additonal bars for the unextended area\n\n' + labelName +
' - displays the time frame name\n\nAdds extra text data to the label'
maxBars = mbp - 1
if maxBars >= bar_index
maxBars := bar_index - 1
//}
createTextLabel(tf) =>
r = tf
if str.contains(tf, 'M') or str.contains(tf, 'D') or str.contains(tf, 'Y') or
str.contains(tf, 'W') or str.contains(tf, 's')
r := tf
else
s = timeframe.in_seconds(tf)
s /= 60
if s / 60 >= 1
r := str.tostring(s / 60) + 'H'
else
r := tf + 'm'
r
FindLtfImb(tf, on, be_col, bu_col, max, extend, uw, showlabel, labeltxt) =>
wrongltf = not on or timeframe.in_seconds(tf) >=
timeframe.in_seconds(timeframe.period)
ts = request.security_lower_tf(syminfo.tickerid, wrongltf ? timeframe.period :
tf, time)
hs = request.security_lower_tf(syminfo.tickerid, wrongltf ? timeframe.period :
tf, high)
ls = request.security_lower_tf(syminfo.tickerid, wrongltf ? timeframe.period :
tf, low)
for j = 0 to max - 1
s = array.size(ts[j])
if (maxHighs == 0 and maxLows == 0) or s == 0
break
for i = 0 to s - 1
if not na(nl)
l := nl
h := nh
t := nt
nl := array.get(ls[j], s - 1 - i)
nh := array.get(hs[j], s - 1 - i)
nt := array.get(ts[j], s - 1 - i)
if na(t0)
t0 := nt
if na(t)
continue
left = bar_index - j
right = extend == eo_ByLastBar ? bar_index + uw : bar_index - j +
uw
if maxLows > 0
//if l < ml and h > ml
if nh < ml
lowImb = box.new(left, ml, right, nh, border_color =
fvg_borders ? bu_col : na, bgcolor = bu_col, extend = extend == eo_BySceen ?
extend.right : extend.none)
array.push(imbLows, lowImb)
if showlabel
array.push(labels, createLabel(right, (ml + nh) / 2,
txt, color.new(bu_col, color.t(bu_col) / 2), extend))
maxLows -= 1
if ml > nh and nh < l//for the gap
ml := nh
if na(ml) or l < ml
ml := l
if maxHighs > 0
//if l < mh and h > mh
if nl > mh
highImb = box.new(left, nl, right, mh, border_color =
fvg_borders ? be_col : na, bgcolor = be_col, extend = extend == eo_BySceen ?
extend.right : extend.none)
array.push(imbHighs, highImb)
if showlabel
array.push(labels, createLabel(right, (nl + mh) / 2,
txt, color.new(be_col, color.t(be_col) / 2), extend))
maxHighs -= 1
if mh < nl and nl > h
mh := nl
if na(mh) or mh < h
mh := h
if maxHighs <= 0 and maxLows <= 0
break
FindHtfImb(tf, on, be_col, bu_col, max, extend, uw, showlabel, labeltxt) =>
wronghtf = not on or timeframe.in_seconds(tf) <=
timeframe.in_seconds(timeframe.period)
[ts, hs, ls] = request.security(syminfo.tickerid, wronghtf ? timeframe.period :
tf, [time, high, low], barmerge.gaps_off, barmerge.lookahead_on)
left = bar_index - nj + 1
right = extend == eo_ByLastBar ? bar_index + uw : bar_index - cj + uw
if maxLows > 0
if nh < ml
lowImb = box.new(left, ml, right, nh, border_color =
fvg_borders ? bu_col : na, bgcolor = bu_col, extend = extend == eo_BySceen ?
extend.right : extend.none)
array.push(imbLows, lowImb)
if showlabel
array.push(labels, createLabel(right, (ml + nh) / 2, txt,
color.new(bu_col, color.t(bu_col) / 2), extend))
maxLows -= 1
if ml > nh and nh < l//for the gap
ml := nh
if l < ml
ml := l
if maxHighs > 0
if nl > mh
highImb = box.new(left, nl, right, mh, border_color =
fvg_borders ? be_col : na, bgcolor = be_col, extend = extend == eo_BySceen ?
extend.right : extend.none)
array.push(imbHighs, highImb)
if showlabel
array.push(labels, createLabel(right, (nl + mh) / 2, txt,
color.new(be_col, color.t(be_col) / 2), extend))
maxHighs -= 1
if mh < nl and nl > h
mh := nl
if mh < h
mh := h
if barstate.islast
while array.size(imbLows) > 0
box.delete(array.pop(imbLows))
while array.size(imbHighs) > 0
box.delete(array.pop(imbHighs))
while array.size(labels) > 0
label.delete(array.pop(labels))
//
-----------------------------------------------------------------------------------
----------- //
// Consecutively Increasing Volume / Price
----------------------------------------------------- //
//
-----------------------------------------------------------------------------------
----------- //
// Definitions
----------------------------------------------------------------------------------
//
nzVolume = nz(volume)
risingVol = nzVolume >= nzVolume[1]
x2 = timenow + 7 * math.round(ta.change(time))
var startBarIndexX = 0
if time == chart.left_visible_bar_time and vpLookbackRange == 'Visible Range'
startBarIndexX := bar_index
f_drawLineX(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width) =>
var id = line.new(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width)
line.set_xy1(id, _x1, _y1)
line.set_xy2(id, _x2, _y2)
line.set_color(id, _color)
f_getHighLow() =>
var htf_h = 0., var htf_l = 0.
[htf_h, htf_l]
if bullCandle[barIndex]
array.set(volumeStorageB, level, array.get(volumeStorageB,
level) + nzVolume[barIndex] * ((barPriceHigh[barIndex] - barPriceLow[barIndex]) ==
0 ? 1 : priceStep / (barPriceHigh[barIndex] - barPriceLow[barIndex])) )
level += 1
levelAbovePoc := pocLevel
levelBelowPoc := pocLevel
volumeAbovePoc = 0.
if levelAbovePoc < profileLevels - 1
volumeAbovePoc := array.get(volumeStorage, levelAbovePoc + 1)
volumeBelowPoc = 0.
if levelBelowPoc > 0
volumeBelowPoc := array.get(volumeStorage, levelBelowPoc - 1)
if priceLevels
f_drawLabelX(volumeProfile ? bar_index + horizontalOffset + 50 : bar_index
+ 7, priceHighest, str.tostring(priceHighest, format.mintick), xloc.bar_index,
yloc.price, labelColor, label.style_label_down, labelColor, size.normal,
text.align_left, 'Profile High - during last ' + str.tostring(lookbackLength) + '
bars\n %' + str.tostring((priceHighest - priceLowest) / priceLowest * 100, '#.##')
+ ' higher than the Profile Low')
f_drawLabelX(volumeProfile ? bar_index + horizontalOffset + 50 : bar_index
+ 7, priceLowest , str.tostring(priceLowest , format.mintick), xloc.bar_index,
yloc.price, labelColor, label.style_label_up , labelColor, size.normal,
text.align_left, 'Profile Low - during last ' + str.tostring(lookbackLength) + '
bars\n %' + str.tostring((priceHighest - priceLowest) / priceHighest * 100, '#.##')
+ ' lower than the Profile High')
f_drawLabelX(volumeProfile ? bar_index + horizontalOffset + 57 : bar_index
+ 13, priceLowest + (levelAbovePoc + 1.00) * priceStep, str.tostring(priceLowest +
(levelAbovePoc + 1.00) * priceStep, format.mintick), xloc.bar_index, yloc.price,
valueAreaHigh ? labelColor : #00000000, label.style_label_left, valueAreaHigh ?
labelColor : #00000000, size.normal, text.align_left, 'Value Area High Price')
f_drawLabelX(volumeProfile ? bar_index + horizontalOffset + 57 : bar_index
+ 13, priceLowest + (pocLevel + 0.50) * priceStep, str.tostring(priceLowest +
(pocLevel + 0.50) * priceStep, format.mintick), xloc.bar_index, yloc.price,
pointOfControl ? labelColor : #00000000, label.style_label_left, pointOfControl ?
labelColor : #00000000, size.normal, text.align_left, 'Point Of Control Price')
f_drawLabelX(volumeProfile ? bar_index + horizontalOffset + 57 : bar_index
+ 13, priceLowest + (levelBelowPoc + 0.00) * priceStep, str.tostring(priceLowest +
(levelBelowPoc + 0.00) * priceStep, format.mintick), xloc.bar_index, yloc.price,
valueAreaLow ? labelColor : #00000000, label.style_label_left, valueAreaLow ?
labelColor : #00000000, size.normal, text.align_left, 'Value Area Low Price')
if volumeProfile
array.push(a_profile, box.new(bar_index - lookbackLength + 1, priceLowest,
bar_index + horizontalOffset + 50, priceHighest, color.new(color.gray, 37), 1,
line.style_dotted, bgcolor=#00000000 ))
//------------------------SMART MONEY
-----------------------------------------------------
show_SMC = input(false, title='--------- Show SMART MONEY ---------')
color TRANSP_CSS = #ffffff00
//Tooltips
string MODE_TOOLTIP = 'Allows to display historical Structure or only the
recent ones'
string STYLE_TOOLTIP = 'Indicator color theme'
string COLOR_CANDLES_TOOLTIP = 'Display additional candles with a color reflecting
the current trend detected by structure'
string SHOW_INTERNAL = 'Display internal market structure'
string CONFLUENCE_FILTER = 'Filter non significant internal structure
breakouts'
string SHOW_SWING = 'Display swing market Structure'
string SHOW_SWING_POINTS = 'Display swing point as labels on the chart'
string SHOW_SWHL_POINTS = 'Highlight most recent strong and weak high/low
points on the chart'
string INTERNAL_OB = 'Display internal order blocks on the chart\n\
nNumber of internal order blocks to display on the chart'
string SWING_OB = 'Display swing order blocks on the chart\n\nNumber
of internal swing blocks to display on the chart'
string FILTER_OB = 'Method used to filter out volatile order blocks \n\
nIt is recommended to use the cumulative mean range method when a low amount of
data is available'
string SHOW_EQHL = 'Display equal highs and equal lows on the chart'
string EQHL_BARS = 'Number of bars used to confirm equal highs and
equal lows'
string EQHL_THRESHOLD = 'Sensitivity threshold in a range (0, 1) used for
the detection of equal highs & lows\n\nLower values will return fewer but more
pertinent results'
string SHOW_FVG = 'Display fair values gaps on the chart'
string AUTO_FVG = 'Filter out non significant fair value gaps'
string FVG_TF = 'Fair value gaps timeframe'
string EXTEND_FVG = 'Determine how many bars to extend the Fair Value
Gap boxes on chart'
string PED_ZONES = 'Display premium, discount, and equilibrium zones on
chart'
//-----------------------------------------------------------------------------{
//Settings
//-----------------------------------------------------------------------------{
//General
//----------------------------------------{
mode = input.string('Historical'
, options = ['Historical', 'Present']
, group = 'Smart Money Concepts'
, tooltip = MODE_TOOLTIP)
style = input.string('Colored'
, options = ['Colored', 'Monochrome']
, group = 'Smart Money Concepts'
, tooltip = STYLE_TOOLTIP)
//----------------------------------------}
//Internal Structure
//----------------------------------------{
show_internals = input(true, 'Show Internal Structure'
, group = 'Real Time Internal Structure'
, tooltip = SHOW_INTERNAL)
//Bear Structure
show_ibear = input.string('All', 'Bearish Structure'
, options = ['All', 'BOS', 'CHoCH']
, inline = 'ibear'
, group = 'Real Time Internal Structure')
//----------------------------------------}
//Swing Structure
//----------------------------------------{
show_Structure = input(true, 'Show Swing Structure'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWING)
//Bull Structure
show_bull = input.string('All', 'Bullish Structure'
, options = ['All', 'BOS', 'CHoCH']
, inline = 'bull'
, group = 'Real Time Swing Structure')
swing_bull_css = input(#089981, ''
, inline = 'bull'
, group = 'Real Time Swing Structure')
//Bear Structure
show_bear = input.string('All', 'Bearish Structure'
, options = ['All', 'BOS', 'CHoCH']
, inline = 'bear'
, group = 'Real Time Swing Structure')
//Swings
show_swings = input(false, 'Show Swings Points'
, inline = 'swings'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWING_POINTS)
//----------------------------------------}
//Order Blocks
//----------------------------------------{
show_iob = input(true, 'Internal Order Blocks'
, inline = 'iob'
, group = 'Order Blocks'
, tooltip = INTERNAL_OB)
//----------------------------------------}
//EQH/EQL
//----------------------------------------{
show_eq = input(true, 'Equal High/Low'
, group = 'EQH/EQL'
, tooltip = SHOW_EQHL)
//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
show_fvg = input(false, 'Fair Value Gaps'
, group = 'Fair Value Gaps'
, tooltip = SHOW_FVG)
//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
show_pdhl = input(false, 'Daily'
, inline = 'daily'
, group = 'Highs & Lows MTF')
//Weekly
show_pwhl = input(false, 'Weekly'
, inline = 'weekly'
, group = 'Highs & Lows MTF')
//Monthly
show_pmhl = input(false, 'Monthly'
, inline = 'monthly'
, group = 'Highs & Lows MTF')
//----------------------------------------}
//Premium/Discount zones
//----------------------------------------{
show_sd = input(false, 'Premium/Discount Zones'
, group = 'Premium & Discount Zones'
, tooltip = PED_ZONES)
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
atr = ta.atr(200)
cmean_range = ta.cum(high - low) / n
if mode == 'Present'
line.delete(structure_line[1])
label.delete(structure_lbl[1])
//Swings detection/measurements
swings(len)=>
var os = 0
upper = ta.highest(len)
lower = ta.lowest(len)
[top, btm]
//Search for highest/lowest high within the structure interval and get range
if use_max and show_SMC
for i = 1 to (n - loc)-1
if (high[i] - low[i]) < ob_threshold[i] * 2
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
else
for i = 1 to (n - loc)-1
if (high[i] - low[i]) < ob_threshold[i] * 2
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
array.unshift(target_top, max)
array.unshift(target_btm, min)
array.unshift(target_left, time[idx])
array.unshift(target_type, use_max ? -1 : 1)
color css = na
box.set_bgcolor(get_box, css)
else
if style == 'Monochrome'
css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) :
color.new(#5d606b, 80)
else
css := array.get(target_type, i) == 1 ? ibull_ob_css : ibear_ob_css
box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)
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)
//High
line.set_xy1(high_line, hx, hy)
line.set_xy2(high_line, ext, hy)
//Low
line.set_xy1(low_line, lx, ly)
line.set_xy2(low_line, ext, ly)
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
var trend = 0, var itrend = 0
//Alerts
bull_choch_alert = false
bull_bos_alert = false
bear_choch_alert = false
bear_bos_alert = false
bull_ichoch_alert = false
bull_ibos_alert = false
bear_ichoch_alert = false
bear_ibos_alert = false
bull_iob_break = false
bear_iob_break = false
bull_ob_break = false
bear_ob_break = false
eqh_alert = false
eql_alert = false
//Structure colors
var bull_css = style == 'Monochrome' ? #b2b5be
: swing_bull_css
//Labels size
var internal_structure_lbl_size = internal_structure_size == 'Tiny'
? size.tiny
: internal_structure_size == 'Small'
? size.small
: size.normal
//Swings
[top, btm] = swings(length)
//-----------------------------------------------------------------------------}
//Pivot High
//-----------------------------------------------------------------------------{
var line extend_top = na
if show_swings
top_lbl = label.new(n-length, top, txt_top
, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = swing_structure_lbl_size)
if mode == 'Present'
label.delete(top_lbl[1])
top_y := top
top_x := n - length
trail_up := top
trail_up_x := n - length
itop_y := itop
itop_x := n - 5
//Trailing maximum
trail_up := math.max(high, trail_up)
trail_up_x := trail_up == high ? n : trail_up_x
label.set_x(extend_top_lbl, n + 20)
label.set_y(extend_top_lbl, trail_up)
label.set_text(extend_top_lbl, trend < 0 ? 'Strong High' : 'Weak High')
//-----------------------------------------------------------------------------}
//Pivot Low
//-----------------------------------------------------------------------------{
var line extend_btm = na
if show_swings
btm_lbl = label.new(n - length, btm, txt_btm
, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = swing_structure_lbl_size)
if mode == 'Present'
label.delete(btm_lbl[1])
btm_y := btm
btm_x := n-length
trail_dn := btm
trail_dn_x := n-length
ibtm_y := ibtm
ibtm_x := n - 5
//Trailing minimum
trail_dn := math.min(low, trail_dn)
trail_dn_x := trail_dn == low ? n : trail_dn_x
label.set_x(extend_btm_lbl, n + 20)
label.set_y(extend_btm_lbl, trail_dn)
label.set_text(extend_btm_lbl, trend > 0 ? 'Strong Low' : 'Weak Low')
//-----------------------------------------------------------------------------}
//Order Blocks Arrays
//-----------------------------------------------------------------------------{
var iob_top = array.new_float(0)
var iob_btm = array.new_float(0)
var iob_left = array.new_int(0)
var iob_type = array.new_int(0)
//-----------------------------------------------------------------------------}
//Pivot High BOS/CHoCH
//-----------------------------------------------------------------------------{
//Filtering
var bull_concordant = true
if itrend < 0
choch := true
bull_ichoch_alert := true
else
bull_ibos_alert := true
if show_internals
if show_ibull == 'All' or (show_ibull == 'BOS' and not choch) or
(show_ibull == 'CHoCH' and choch)
display_Structure(itop_x, itop_y, txt, ibull_css, true, true,
internal_structure_lbl_size)
itop_cross := false
itrend := 1
if trend < 0
choch := true
bull_choch_alert := true
else
bull_bos_alert := true
txt = choch ? 'CHoCH' : 'BOS'
if show_Structure
if show_bull == 'All' or (show_bull == 'BOS' and not choch) or (show_bull
== 'CHoCH' and choch)
display_Structure(top_x, top_y, txt, bull_css, false, true,
swing_structure_lbl_size)
//Order Block
if show_ob
ob_coord(false, top_x, ob_top, ob_btm, ob_left, ob_type)
top_cross := false
trend := 1
//-----------------------------------------------------------------------------}
//Pivot Low BOS/CHoCH
//-----------------------------------------------------------------------------{
var bear_concordant = true
if itrend > 0
choch := true
bear_ichoch_alert := true
else
bear_ibos_alert := true
if show_internals
if show_ibear == 'All' or (show_ibear == 'BOS' and not choch) or
(show_ibear == 'CHoCH' and choch)
display_Structure(ibtm_x, ibtm_y, txt, ibear_css, true, false,
internal_structure_lbl_size)
ibtm_cross := false
itrend := -1
if trend > 0
choch := true
bear_choch_alert := true
else
bear_bos_alert := true
txt = choch ? 'CHoCH' : 'BOS'
if show_Structure
if show_bear == 'All' or (show_bear == 'BOS' and not choch) or (show_bear
== 'CHoCH' and choch)
display_Structure(btm_x, btm_y, txt, bear_css, false, false,
swing_structure_lbl_size)
//Order Block
if show_ob
ob_coord(true, btm_x, ob_top, ob_btm, ob_left, ob_type)
btm_cross := false
trend := -1
//-----------------------------------------------------------------------------}
//Order Blocks
//-----------------------------------------------------------------------------{
//Set order blocks
var iob_boxes = array.new_box(0)
var ob_boxes = array.new_box(0)
//-----------------------------------------------------------------------------}
//EQH/EQL
//-----------------------------------------------------------------------------{
var eq_prev_top = 0.
var eq_top_x = 0
var eq_prev_btm = 0.
var eq_btm_x = 0
if bool(eq_top)
max = math.max(eq_top, eq_prev_top)
min = math.min(eq_top, eq_prev_top)
if mode == 'Present'
line.delete(eqh_line[1])
label.delete(eqh_lbl[1])
eqh_alert := true
eq_prev_top := eq_top
eq_top_x := n-eq_len
if bool(eq_btm)
max = math.max(eq_btm, eq_prev_btm)
min = math.min(eq_btm, eq_prev_btm)
eql_alert := true
if mode == 'Present'
line.delete(eql_line[1])
label.delete(eql_lbl[1])
eq_prev_btm := eq_btm
eq_btm_x := n-eq_len
//-----------------------------------------------------------------------------}
//Fair Value Gaps
//-----------------------------------------------------------------------------{
var bullish_fvg_max = array.new_box(0)
var bullish_fvg_min = array.new_box(0)
float bullish_fvg_avg = na
float bearish_fvg_avg = na
bullish_fvg_cnd = false
bearish_fvg_cnd = false
change_tf = timeframe.change(fvg_tf)
//FVG conditions
bullish_fvg_cnd := src_l > src_h2
and src_c1 > src_h2
and delta_per > threshold
and change_tf
if bearish_fvg_cnd
array.unshift(bearish_fvg_max, box.new(n-1, src_h, n + fvg_extend,
math.avg(src_h, src_l2)
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css))
for bx in bullish_fvg_min
if low < box.get_bottom(bx)
box.delete(bx)
box.delete(array.get(bullish_fvg_max, array.indexof(bullish_fvg_min,
bx)))
for bx in bearish_fvg_max
if high > box.get_top(bx)
box.delete(bx)
box.delete(array.get(bearish_fvg_min, array.indexof(bearish_fvg_max,
bx)))
//-----------------------------------------------------------------------------}
//Previous day/week high/lows
//-----------------------------------------------------------------------------{
//Daily high/low
[pdh, pdl] = request.security(syminfo.tickerid, 'D', hl()
, lookahead = barmerge.lookahead_on)
//Weekly high/low
[pwh, pwl] = request.security(syminfo.tickerid, 'W', hl()
, lookahead = barmerge.lookahead_on)
//Monthly high/low
[pmh, pml] = request.security(syminfo.tickerid, 'M', hl()
, lookahead = barmerge.lookahead_on)
//Display Daily
if show_pdhl
phl(pdh, pdl, 'D', pdhl_css)
//Display Weekly
if show_pwhl and show_SMC
phl(pwh, pwl, 'W', pwhl_css)
//Display Monthly
if show_pmhl and show_SMC
phl(pmh, pml, 'M', pmhl_css)
//-----------------------------------------------------------------------------}
//Premium/Discount/Equilibrium zones
//-----------------------------------------------------------------------------{
var premium = box.new(na, na, na, na
, bgcolor = color.new(premium_css, 80)
, border_color = na)
label.set_xy(eq_lbl, n, avg)
//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
//Internal Structure
alertcondition(bull_ibos_alert, 'Internal Bullish BOS', 'Internal Bullish BOS
formed')
alertcondition(bull_ichoch_alert, 'Internal Bullish CHoCH', 'Internal Bullish CHoCH
formed')
//Swing Structure
alertcondition(bull_bos_alert, 'Bullish BOS', 'Internal Bullish BOS formed')
alertcondition(bull_choch_alert, 'Bullish CHoCH', 'Internal Bullish CHoCH formed')
//order Blocks
alertcondition(bull_iob_break, 'Bullish Internal OB Breakout', 'Price broke bullish
internal OB')
alertcondition(bear_iob_break, 'Bearish Internal OB Breakout', 'Price broke bearish
internal OB')
//EQH/EQL
alertcondition(eqh_alert, 'Equal Highs', 'Equal highs detected')
alertcondition(eql_alert, 'Equal Lows', 'Equal lows detected')
//FVG
alertcondition(bullish_fvg_cnd, 'Bullish FVG', 'Bullish FVG formed')
alertcondition(bearish_fvg_cnd, 'Bearish FVG', 'Bearish FVG formed')
//-----------------------------------------------------------------------------}
////////////////////////////////////
///////DIVERGENCIAS/////////////////
////////////////////////////////////
show_DIV = input(false, title='--------- Show DIVERGENCIAS ---------')
prd = input.int(defval=5, title='Pivot Period', minval=1, maxval=50)
source = input.string(defval='Close', title='Source for Pivot Points',
options=['Close', 'High/Low'])
searchdiv = input.string(defval='Regular', title='Divergence Type',
options=['Regular', 'Hidden', 'Regular/Hidden'])
showindis = input.string(defval='Full', title='Show Indicator Names',
options=['Full', 'First Letter', 'Don\'t Show'])
showlimit = input.int(1, title='Minimum Number of Divergence', minval=1, maxval=11)
maxpp = input.int(defval=10, title='Maximum Pivot Points to Check', minval=1,
maxval=20)
maxbars = input.int(defval=100, title='Maximum Bars to Check', minval=30,
maxval=200)
shownum = input(defval=true, title='Show Divergence Number')
showlast = input(defval=false, title='Show Only Last Divergence')
dontconfirm = input(defval=false, title='Don\'t Wait for Confirmation')
showlines = input(defval=true, title='Show Divergence Lines')
showpivot = input(defval=false, title='Show Pivot Points')
calcmacd = input(defval=true, title='MACD')
calcmacda = input(defval=true, title='MACD Histogram')
calcrsi = input(defval=true, title='RSI')
calcstoc = input(defval=true, title='Stochastic')
calccci = input(defval=true, title='CCI')
calcmom = input(defval=true, title='Momentum')
calcobv = input(defval=true, title='OBV')
calcvwmacd = input(true, title='VWmacd')
calccmf = input(true, title='Chaikin Money Flow')
calcmfi = input(true, title='Money Flow Index')
calcext = input(false, title='Check External Indicator')
externalindi = input(defval=close, title='External Indicator')
pos_reg_div_col = input(defval=color.yellow, title='Positive Regular Divergence')
neg_reg_div_col = input(defval=color.navy, title='Negative Regular Divergence')
pos_hid_div_col = input(defval=color.lime, title='Positive Hidden Divergence')
neg_hid_div_col = input(defval=color.red, title='Negative Hidden Divergence')
pos_div_text_col = input(defval=color.black, title='Positive Divergence Text
Color')
neg_div_text_col = input(defval=color.white, title='Negative Divergence Text
Color')
reg_div_l_style_ = input.string(defval='Solid', title='Regular Divergence Line
Style', options=['Solid', 'Dashed', 'Dotted'])
hid_div_l_style_ = input.string(defval='Dashed', title='Hdden Divergence Line
Style', options=['Solid', 'Dashed', 'Dotted'])
reg_div_l_width = input.int(defval=2, title='Regular Divergence Line Width',
minval=1, maxval=5)
hid_div_l_width = input.int(defval=1, title='Hidden Divergence Line Width',
minval=1, maxval=5)
showmas = input.bool(defval=false, title='Show MAs 50 & 200', inline='ma12')
cma1col = input.color(defval=color.lime, title='', inline='ma12')
cma2col = input.color(defval=color.red, title='', inline='ma12')
plot(showmas ? ta.sma(close, 50) : na, color=showmas ? cma1col : na)
plot(showmas ? ta.sma(close, 200) : na, color=showmas ? cma2col : na)
// set line styles
var reg_div_l_style = reg_div_l_style_ == 'Solid' ? line.style_solid :
reg_div_l_style_ == 'Dashed' ? line.style_dashed : line.style_dotted
var hid_div_l_style = hid_div_l_style_ == 'Solid' ? line.style_solid :
hid_div_l_style_ == 'Dashed' ? line.style_dashed : line.style_dotted
// get indicators
rsi = ta.rsi(close, 14) // RSI
[macd, signal, deltamacd] = ta.macd(close, 12, 26, 9) // MACD
moment = ta.mom(close, 10) // Momentum
cci = ta.cci(close, 10) // CCI
Obv = ta.obv // OBV
stk = ta.sma(ta.stoch(close, high, low, 14), 3) // Stoch
maFast = ta.vwma(close, 12) // volume weighted macd
maSlow = ta.vwma(close, 26)
vwmacd = maFast - maSlow
Cmfm = (close - low - (high - close)) / (high - low) // Chaikin money flow
Cmfv = Cmfm * volume
cmf = ta.sma(Cmfv, 21) / ta.sma(volume, 21)
Mfi = ta.mfi(close, 14) // Moneyt Flow Index
if arrived
divlen := len
break
divlen
if arrived
divlen := len
break
divlen
// check minimum number of divergence, if less than showlimit then delete all
divergence
total_div = 0
for x = 0 to array.size(all_divergences) - 1 by 1
total_div += math.round(math.sign(array.get(all_divergences, x)))
total_div
delete_old_neg_div_lines() =>
if array.size(neg_div_lines) > 0
for j = 0 to array.size(neg_div_lines) - 1 by 1
line.delete(array.get(neg_div_lines, j))
array.clear(neg_div_lines)
delete_old_pos_div_labels() =>
if array.size(pos_div_labels) > 0
for j = 0 to array.size(pos_div_labels) - 1 by 1
label.delete(array.get(pos_div_labels, j))
array.clear(pos_div_labels)
delete_old_neg_div_labels() =>
if array.size(neg_div_labels) > 0
for j = 0 to array.size(neg_div_labels) - 1 by 1
label.delete(array.get(neg_div_labels, j))
array.clear(neg_div_labels)
// delete last creted lines and labels until we met new PH/PV
delete_last_pos_div_lines_label(n) =>
if n > 0 and array.size(pos_div_lines) >= n
asz = array.size(pos_div_lines)
for j = 1 to n by 1
line.delete(array.get(pos_div_lines, asz - j))
array.pop(pos_div_lines)
if array.size(pos_div_labels) > 0
label.delete(array.get(pos_div_labels, array.size(pos_div_labels) - 1))
array.pop(pos_div_labels)
delete_last_neg_div_lines_label(n) =>
if n > 0 and array.size(neg_div_lines) >= n
asz = array.size(neg_div_lines)
for j = 1 to n by 1
line.delete(array.get(neg_div_lines, asz - j))
array.pop(neg_div_lines)
if array.size(neg_div_labels) > 0
label.delete(array.get(neg_div_labels, array.size(neg_div_labels) - 1))
array.pop(neg_div_labels)
if divergence_text_bottom != ''
if showlast
delete_old_pos_div_labels()
array.push(pos_div_labels, label.new(x=bar_index, y=math.min(low, low[1]),
text=divergence_text_bottom, color=bottom_label_col, textcolor=pos_div_text_col,
style=label.style_label_up))
alertcondition(pos_reg_div_detected, title='Positive Regular Divergence Detected',
message='Positive Regular Divergence Detected')
alertcondition(neg_reg_div_detected, title='Negative Regular Divergence Detected',
message='Negative Regular Divergence Detected')
alertcondition(pos_hid_div_detected, title='Positive Hidden Divergence Detected',
message='Positive Hidden Divergence Detected')
alertcondition(neg_hid_div_detected, title='Negative Hidden Divergence Detected',
message='Negative Hidden Divergence Detected')
alertcondition(pos_reg_div_detected or pos_hid_div_detected, title='Positive
Divergence Detected', message='Positive Divergence Detected')
alertcondition(neg_reg_div_detected or neg_hid_div_detected, title='Negative
Divergence Detected', message='Negative Divergence Detected')
//Style
showTop2 = input(true, 'Swing High' , inline = 'top', group =
'Style')
topCss2 = input(color.red, '' , inline = 'top', group =
'Style')
toparea2Css2 = input(color.new(color.red, 50), 'area2', inline = 'top', group =
'Style')
[count, vol]
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
//Pivot high
var float ph_top = na
var float ph_btm = na
var bool ph_crossed = na
var ph_x1 = 0
var box ph_bx = box.new(na,na,na,na
, bgcolor = color.new(toparea2Css2, 80)
, border_color = na)
//Pivot low
var float pl_top = na
var float pl_btm = na
var bool pl_crossed = na
var pl_x1 = 0
var box pl_bx = box.new(na,na,na,na
, bgcolor = color.new(btmarea2Css2, 80)
, border_color = na)
//-----------------------------------------------------------------------------}
//Display pivot high levels/blocks
//-----------------------------------------------------------------------------{
ph2 = ta.pivothigh(length2, length2)
//Get ph2 counts
[ph_count, ph_vol] = get_counts(ph2, ph_top, ph_btm)
ph_x1 := n2 - length2
ph_crossed := false
if ph_crossed
box.set_right(ph_bx, ph_x1)
else
box.set_right(ph_bx, n2+3)
//-----------------------------------------------------------------------------}
//Display pivot low levels/blocks
//-----------------------------------------------------------------------------{
pl2 = ta.pivotlow(length2, length2)
pl_x1 := n2 - length2
pl_crossed := false
if pl_crossed
box.set_right(pl_bx, pl_x1)
else
box.set_right(pl_bx, n2+3)
//-----------------------------------------------------------------------------}