Elite Algo + TP + Smart Money
Elite Algo + TP + Smart Money
explicit_plot_zorder=true, max_labels_count=500)
// Get user input
sensitivity = input.int(defval=6, title="Sensitivity", minval=1,
maxval=20)
//@version=5
keltner_length = 10
atrPeriod = 10
factor = 3.5
Barcolloring = input.string("Version 1", options=["Version 1",
"Version 2"], title="Bar Coloring")
tpmode = input.string("Version 1", options=['Version 2', "Version
1",'Close'], title="TP Signals Mode")
showrevsig = input.bool(false, 'Reversal Signals')
show_rev = input.bool(false, 'Reversal Cloud')
show_ha = input.bool(false, 'Trend Tracker')
Show_rangefilter = input.bool(false, 'Trend Catcher')
Show_SuperIchi = input.bool(false, 'SuperIchi')
// Signal Generation
supertrend(_src, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _src + factor * atr
lowerBand = _src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] <
prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] >
prevUpperBand ? upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
// SMA
ocAvg = math.avg(open, close)
sma44 = ta.sma(close, 8)
sma55 = ta.sma(close, 9)
sma99 = ta.sma(close, 13)
psarr = ta.sar(0.02, 0.02, 0.2)
// High Lows
y1 = low - (ta.atr(30) * 2), y1B = low - ta.atr(30)
y2 = high + (ta.atr(30) * 2), y2B = high + ta.atr(30)
// Braid Filter
//-- Inputs
maType = input.string('McGinley', 'Filter', options=['EMA', 'DEMA',
'TEMA', 'WMA', 'VWMA', 'SMA', 'SMMA', 'HMA', 'LSMA', 'Kijun',
'McGinley', 'RMA'])
Period1 = 3
Period2 = 7
Period3 = 20
PipsMinSepPercent = input(80, 'Filter Strength')
//-- Plots
BraidColor = ma01 > ma02 and dif > filter ? color.green : ma02 >
ma01 and dif > filter ? color.red : color.gray
//buy = bull and ma01 > ma02 and dif > filter ? label.new(bar_index,
y1, "▲", xloc.bar_index, yloc.price, #04994b, label.style_label_up,
color.white, size.normal) : na
//sell = bear and ma02 > ma01 and dif > filter ? label.new(bar_index,
y2, "▼", xloc.bar_index, yloc.price, #b4060d, label.style_label_down,
color.white, size.normal) : na
colorsr = 'DARK'
bullcolorr = colorsr == 'DARK' ? color.rgb(0, 255, 8) : #00DBFF
bearcolorr = colorsr == 'DARK' ? color.rgb(255, 0, 0) : #E91E63
TE1 = true
TE2 = true
TE3 = true
//TE4 = input(true, 'TE - 4' , group="Money Moves [Trend Exhaustion]"
, inline = "TEX")
rsiLengthInput = 22
rsiSourceInput = close
maTypeInput = ta.sma(close, 14)
up66 = ta.rma(math.max(ta.change(rsiSourceInput), 0),
rsiLengthInput)
downw = ta.rma(-math.min(ta.change(rsiSourceInput), 0),
rsiLengthInput)
rsi66 = downw == 0 ? 100 : up66 == 0 ? 0 : 100 - (100 / (1 + up66 /
downw))
rsiMA = maTypeInput
// SHORT
short1 = ta.crossunder(rsi66, 70)
//short4 = ta.crossunder(rsi66, 90)
// LONG
plotshape(long1 and showrevsig == true and close < supertrend and
TE1, "GO LONG 1", style=shape.circle,
location=location.belowbar,size=size.tiny, color =
color.new(bullcolorr , 60) , text="▲" , textcolor = bullcolorr , editable
= false)
//plotshape(long4 and ShowTEX, "GO LONG 4", style=shape.circle,
location=location.belowbar,size=size.tiny, color=color.gray, text="4")
// SHORT
plotshape(short1 and showrevsig == true and close > supertrend and
TE1, "GO SHORT 1", style=shape.circle,
location=location.abovebar,size=size.tiny, color =
color.new(bearcolorr , 60) , text="▼" , textcolor = bearcolorr ,
editable = false)
//plotshape(short4 and ShowTEX, "GO SHORT 4", style=shape.circle,
location=location.abovebar,size=size.tiny, color=color.gray, text="4")
// TP Points Script
maj = (tpmode == 'Version 1' ? true : false)
maj_qual = 13
maj_len = 40
min_qual = 5
min_len = 5
minn = false
selll = 0.0
buyy = 0.0
plotshape(selll == 2, style=shape.xcross,location=location.abovebar,
color=color.new(#354996, 0), textcolor=color.new(color.white, 0),
offset=0)
plotshape(buyy == 2, style=shape.xcross,
location=location.belowbar, color=color.new(#354996, 0),
textcolor=color.new(color.white, 0), offset=0)
//-----------------------------------------------------------------------------}
//---Jurik MA
phase = 0
power = 1
e0 = 0.0
e0 := (1 - alpha) * _src + alpha * nz(e0[1])
e1 = 0.0
e1 := (_src - e0) * (1 - beta) + beta * nz(e1[1])
jma = 0.0
e2 = 0.0
e2 := (e0 + phaseRatio * e1 - nz(jma[1])) * math.pow(1 - alpha, 2)
+ math.pow(alpha, 2) * nz(e2[1])
jma := e2 + nz(jma[1])
jma
FC = input.int(defval=5, minval=1, title='FRAMA FC', inline = 'FC',
group = 'FRAMA')
SC = input.int(defval=50, minval=1, title=': SC', inline = 'FC', group =
'FRAMA')
//---FRAMA originale---
frama(source, c) =>
out = 0.0
len1 = c / 2
e = 2.7182818284590452353602874713527
w = math.log(2 / (SC + 1)) / math.log(e) // Natural logarithm
(ln(2/(SC+1))) workaround
H1 = ta.highest(high, len1)
L1 = ta.lowest(low, len1)
N1 = (H1 - L1) / len1
H2 = ta.highest(high, len1)[len1]
L2 = ta.lowest(low, len1)[len1]
N2 = (H2 - L2) / len1
H3 = ta.highest(high, c)
L3 = ta.lowest(low, c)
N3 = (H3 - L3) / c
dimen1 = (math.log(N1 + N2) - math.log(N3)) / math.log(2)
dimen = N1 > 0 and N2 > 0 and N3 > 0 ? dimen1 : nz(dimen1[1])
alpha1 = math.exp(w * (dimen - 1))
oldalpha = alpha1 > 1 ? 1 : alpha1 < 0.01 ? 0.01 : alpha1
oldN = (2 - oldalpha) / oldalpha
N = (SC - FC) * (oldN - 1) / (SC - 1) + FC
alpha_ = 2 / (N + 1)
alpha = alpha_ < 2 / (SC + 1) ? 2 / (SC + 1) : alpha_ > 1 ? 1 : alpha_
out := (1 - alpha) * nz(out[1]) + alpha * source
out
//------FRAMA modificato---------
frama_mod(source, c) =>
float result = 0
int len1 = c / 2
frama_SC = 200
frama_FC = 1
e = 2.7182818284590452353602874713527
w = math.log(2 / (frama_SC + 1)) / math.log(e) // Natural
logarithm (ln(2/(SC+1))) workaround
H1 = ta.highest(high, len1)
L1 = ta.lowest(low, len1)
N1 = (H1 - L1) / len1
H2_ = ta.highest(high, len1)
H2 = H2_[len1]
L2_ = ta.lowest(low, len1)
L2 = L2_[len1]
N2 = (H2 - L2) / len1
H3 = ta.highest(high, c)
L3 = ta.lowest(low, c)
N3 = (H3 - L3) / c
dimen1 = (math.log(N1 + N2) - math.log(N3)) / math.log(2)
dimen = N1 > 0 and N2 > 0 and N3 > 0 ? dimen1 : nz(dimen1[1])
alpha1 = math.exp(w * (dimen - 1))
oldalpha = alpha1 > 1 ? 1 : alpha1 < 0.01 ? 0.01 : alpha1
oldN = (2 - oldalpha) / oldalpha
N = (frama_SC - frama_FC) * (oldN - 1) / (frama_SC - 1) + frama_FC
alpha_ = 2 / (N + 1)
alpha = alpha_ < 2 / (frama_SC + 1) ? 2 / (frama_SC + 1) : alpha_ >
1 ? 1 : alpha_
//frama = 0.0
result := (1 - alpha) * nz(result[1]) + alpha * source
result
//------------------------------------
//---Double exp moving average (DEMA)
calc_dema(source, c) =>
dema1 = ta.ema(source, c)
dema2 = ta.ema(dema1, c)
dExpoMA = 2 * dema1 - dema2
dExpoMA
calc_kama(source, c) =>
kaMA1 = math.abs(ta.change(source, c))
kaufmanVol = math.sum(math.abs(ta.change(source)), c)
kaufmanEff = kaufmanVol != 0 ? kaMA1 / kaufmanVol : 0
kaufmanFast2 = 2 / (kaufmanFast + 1)
kaufmanSlow2 = 2 / (kaufmanSlow + 1)
kaufmanSC = math.pow(kaufmanEff * (kaufmanFast2 -
kaufmanSlow2) + kaufmanSlow2, 2)
kaMA = 0.0
kaMA := kaufmanSC * source + (1 - kaufmanSC) * nz(kaMA[1])
kaMA
// Gain Factor
float kPrev = 1
float k = 1
for i = 0 to 5000 by 1
if err > tolerance
k := v3 * kPrev * (2 - kPrev)
err := kPrev - k
kPrev := k
kPrev
// Ribbion
getMa1(c) =>
switch ma
'sma' => ta.sma(source,c)
'ema' => ta.ema(source,c)
'wma' => ta.wma(source,c)
'vwma' => ta.vwma(source,c)
'rma' => ta.rma(source,c)
'alma' => ta.alma(source,c, 0.85, 6)
'hma' => ta.hma(source,c)
'jma' => calc_jma(source,c, phase, power)
'frama-o' => frama(source, c)
'frama-m' => frama_mod(source, c)
'dema' => calc_dema(source, c)
'tema' => calc_tema(source, c)
'zlema' => calc_zlema(source, c)
'smma' => calc_smma(source, c)
'kma' => calc_kama(source, c)
'tma' => calc_tma(source, c)
'gmma' => calc_gmma(source, c)
'vida' => calc_vida(source, c)
'cma' => calc_cma(source, c)
'rema' => calc_range_ema(source, c)
getMa(c) =>
switch ma2
'sma' => ta.sma(source,c)
'ema' => ta.ema(source,c)
'wma' => ta.wma(source,c)
'vwma' => ta.vwma(source,c)
'rma' => ta.rma(source,c)
'alma' => ta.alma(source,c, 0.85, 6)
'hma' => ta.hma(source,c)
'jma' => calc_jma(source,c, phase, power)
'frama-o' => frama(source, c)
'frama-m' => frama_mod(source, c)
'dema' => calc_dema(source, c)
'tema' => calc_tema(source, c)
'zlema' => calc_zlema(source, c)
'smma' => calc_smma(source, c)
'kma' => calc_kama(source, c)
'tma' => calc_tma(source, c)
'gmma' => calc_gmma(source, c)
'vida' => calc_vida(source, c)
'cma' => calc_cma(source, c)
'rema' => calc_range_ema(source, c)
rib1 = getMa1(rl1)
rib2 = getMa1(rl2)
rib3 = getMa1(rl3)
rib4 = getMa1(rl4)
rib5 = getMa1(rl5)
rib6 = getMa1(rl6)
rib7 = getMa1(rl7)
rib8 = getMa1(rl8)
sma8 = getMa(cl8)
sma7 = getMa(cl7)
sma6 = getMa(cl6)
sma5 = getMa(cl5)
sma4 = getMa(cl4)
sma3 = getMa(cl3)
sma2 = getMa(cl2)
sma1 = getMa(cl1)
// ALERTS {
// } ALERTS
// Bar Coloring
// Input
fastLength = input(title="Fast Length", defval=12)
slowLength = input(title="Slow Length", defval=26)
srrrc = input(title="Source", defval=close)
signalLength = input.int(title="Signal Smoothing", minval = 1,
maxval = 50, defval = 9)
// Data reference
[macd, signal, hist] = ta.macd(srrrc, fastLength, slowLength,
signalLength)
// 4 level of green
greenHigh = #05df09
greenMidHigh = #05df09
greenMidLow = #388E3C
greenLow = #5f3a97
// Yellow
yellowLow = #5f3a97
// 4 level of red
redHigh = #ea0402
redMidHigh = #ea0402
redMidLow = #cc0402
redLow = #5f3a97
// Default color
candleBody = yellowLow
// Ranging trend
if hist > 0
if hist > hist[1] and hist[1] > 0
candleBody := greenLow
if hist < 0
if hist < hist[1] and hist[1] < 0
candleBody := redLow
// Bullish trend
if macd > 0 and hist > 0
candleBody := greenMidLow
// Bearish trend
if macd < 0 and hist < 0
candleBody := redMidLow
// TP Signals
//
z1 = vwap1 + dev
x1 = vwap1 - dev
// PullBack Signals
//inputs
llength = input(50, title='Band Length')
bd1 = input(9, title='Frontrun Band Deviation')
bd2 = input(11, title='Initial Band Deviation')
bd3 = input(14, title='Final Band Deviation')
//logic
rg = kama(ta.tr, llength)
basis = kama(close, llength)
upper1 = basis + rg * bd1
upper2 = basis + rg * bd2
upper3 = basis + rg * bd3
lower1 = basis - rg * bd1
lower2 = basis - rg * bd2
lower3 = basis - rg * bd3
//ploting
pp1 = plot(show_rev ? upper1 : na, transp=100)
pp2 = plot(show_rev ? upper2 : na, transp=100)
pp3 = plot(show_rev ? upper3 : na, transp=100)
pp4 = plot(show_rev ? lower1 : na, transp=100)
pp5 = plot(show_rev ? lower2 : na, transp=100)
pp6 = plot(show_rev ? lower3 : na, transp=100)
fill(pp1, pp2, color=color.new(#57202c, 70))
fill(pp2, pp3, color=color.new(#57202c, 50))
fill(pp4, pp5, color=color.new(#103c3c, 70))
fill(pp5, pp6, color=color.new(#103c3c, 50))
// Dashboard
showDashboard = input(true, "Show Dashboard", group="TREND
DASHBOARD")
locationDashboard = input.string("Middle Right", "Table Location",
["Top Right", "Middle Right", "Bottom Right", "Top Center", "Middle
Center", "Bottom Center", "Top Left", "Middle Left", "Bottom Left"],
group="TREND DASHBOARD")
tableTextColor = input(color.new(#b1b3be, 2), "Table Text Color",
group="TREND DASHBOARD")
tableBgColor = input(color.new(#232534,65), "Table Background
Color", group="TREND DASHBOARD")
sizeDashboard = input.string("Tiny", "Table Size", ["Large",
"Normal", "Small", "Tiny"], group="TREND DASHBOARD")
// Functions
f_chartTfInMinutes() =>
float _resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
// Get components
emae = ta.ema(close, 144)
emaBull = close > emae
equal_tf(res) => str.tonumber(res) == f_chartTfInMinutes()
higher_tf(res) => str.tonumber(res) > f_chartTfInMinutes()
too_small_tf(res) => (timeframe.isweekly and res=="1") or
(timeframe.ismonthly and str.tonumber(res) < 10)
securityNoRep1(sym, res, srce) =>
bool bulle = na
bulle := equal_tf(res) ? srce : bulle
bulle := higher_tf(res) ? request.security(sym, res, srce,
barmerge.gaps_off, barmerge.lookahead_on) : bulle
bull_array = request.security_lower_tf(syminfo.tickerid,
higher_tf(res) ? str.tostring(f_chartTfInMinutes()) : too_small_tf(res) ?
(timeframe.isweekly ? "3" : "10") : res, srce)
if array.size(bull_array) > 1 and not equal_tf(res) and not
higher_tf(res)
bulle := array.pop(bull_array)
array.clear(bull_array)
bulle
TF1Bull = securityNoRep1(syminfo.tickerid, "1" , emaBull)
TF3Bull = securityNoRep1(syminfo.tickerid, "3" , emaBull)
TF5Bull = securityNoRep1(syminfo.tickerid, "5" , emaBull)
TF15Bull = securityNoRep1(syminfo.tickerid, "15" , emaBull)
TF30Bull = securityNoRep1(syminfo.tickerid, "30" , emaBull)
TF60Bull = securityNoRep1(syminfo.tickerid, "60" , emaBull)
TF120Bull = securityNoRep1(syminfo.tickerid, "120" , emaBull)
TF240Bull = securityNoRep1(syminfo.tickerid, "240" , emaBull)
TF480Bull = securityNoRep1(syminfo.tickerid, "480" , emaBull)
TFDBull = securityNoRep1(syminfo.tickerid, "1440", emaBull)
//
// Ha Market Bias //
tf(_res, _exp, gaps_on) =>
gaps_on == 0 ? request.security(syminfo.tickerid, _res, _exp) :
gaps_on == true ? request.security(syminfo.tickerid, _res, _exp,
barmerge.gaps_on, barmerge.lookahead_off) :
request.security(syminfo.tickerid, _res, _exp, barmerge.gaps_off,
barmerge.lookahead_off)
ha_htf = ''
ha_len = 100
ha_len2 = 100
// Calculations {
o = ta.ema(open, ha_len)
c = ta.ema(close, ha_len)
h = ta.ema(high, ha_len)
l = ta.ema(low, ha_len)
haclose = tf(ha_htf, (o + h + l + c) / 4, 0)
xhaopen = tf(ha_htf, (o + c) / 2, 0)
haopen = na(xhaopen[1]) ? (o + c) / 2 : (xhaopen[1] + haclose[1]) / 2
hahigh = math.max(h, math.max(haopen, haclose))
halow = math.min(l, math.min(haopen, haclose))
// Oscillator {
osc_len = 7
sigcolor =
(osc_bias > 0) and (osc_bias >= osc_smooth) ?
color.new(color.lime, 35) :
(osc_bias > 0) and (osc_bias < osc_smooth) ? color.new(color.lime,
75) :
(osc_bias < 0) and (osc_bias <= osc_smooth) ? color.new(color.red,
35) :
(osc_bias < 0) and (osc_bias > osc_smooth) ? color.new(color.red,
75) :
na
// }
// Plots {
p_h = plot(h2, "Bias High", color=color(na), display=display.none,
editable=false)
p_l = plot(l22, "Bias Low", color=color(na), display=display.none,
editable=false)
p_avg = plot(ha_avg, "Bias Avergae", color=color(na),
display=display.none, editable=false)
// Range Filter DW
//---------------------Range
Filter--------------------------------------------------------------------------------------------------------
--------------
//---------------------------------------------------------------------------------------------------------------
--------------------------------------------------
//Inputs
//---------------------------------------------------------------------------------------------------------------
--------------------------------------------------
//Filter Type
f_type = 'Type 2'
//Movement Source
mov_src = 'Close'
//Range Period
rng_per = 14
//---------------------------------------------------------------------------------------------------------------
--------------------------------------------------
//Definitions
//---------------------------------------------------------------------------------------------------------------
--------------------------------------------------
//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0
//Colors
filt_color = upward ? #36db7f : downward ? #be130f : #cccccc
//---------------------------------------------------------------------------------------------------------------
--------------------------------------------------
//Outputs
//---------------------------------------------------------------------------------------------------------------
--------------------------------------------------
//Filter Plot
filt_plot = plot(Show_rangefilter ? filt : na, color=filt_color,
linewidth=3, title='Filter', transp=0)
//Bar Color
// Superlchi + TBO
tenkan_len = 6
tenkan_mult = 2
kijun_len =5
kijun_mult = 3.
spanB_len = 26
spanB_mult = 4.
offsett =0
//------------------------------------------------------------------------------
avg(srcc,length,mult)=>
atr = ta.atr(length)*mult
up = hl2 + atr
dn = hl2 - atr
upper = 0.,lower = 0.
upper := srcc[1] < upper[1] ? math.min(up,upper[1]) : up
lower := srcc[1] > lower[1] ? math.max(dn,lower[1]) : dn
os = 0,max = 0.,min = 0.
os := srcc > upper ? 1 : srcc < lower ? 0 : os[1]
spt = os == 1 ? lower : upper
max := ta.cross(srcc,spt) ? math.max(srcc,max[1]) : os == 1 ?
math.max(srcc,max[1]) : spt
min := ta.cross(srcc,spt) ? math.min(srcc,min[1]) : os == 0 ?
math.min(srcc,min[1]) : spt
math.avg(max,min)
//------------------------------------------------------------------------------
tenkan = avg(close,tenkan_len,tenkan_mult)
kijun = avg(close,kijun_len,kijun_mult)
senkouA = math.avg(kijun,tenkan)
senkouB = avg(close,spanB_len,spanB_mult)
//------------------------------------------------------------------------------
tenkan_css = #2157f3
kijun_css = #ff5d00
cloud_a = color.new(color.teal,80)
cloud_b = color.new(color.red,80)
chikou_css = #7b1fa2
plot(close,'Chikou',chikou_css,offset=-
offsett+1,display=display.none)
//
=========================================================
==============================
// MODULO DE SEÑALES PARA MEGA POWER
//
=========================================================
==============================
signals = input.bool(false, "Buy/Sell Signals?") // SE MUESTRAN
O NO BUY Y SELL SIGNALS
y1signals = low - (ta.atr(30) * 2)
y2signals = high + (ta.atr(30) * 2)
//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(false, '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(false, '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')
//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(false, 'Internal Order Blocks'
, inline = 'iob'
, group = 'Order Blocks'
, tooltip = INTERNAL_OB)
iob_showlast = input.int(5, ''
, minval = 1
, inline = 'iob'
, group = 'Order Blocks')
//----------------------------------------}
//EQH/EQL
//----------------------------------------{
show_eq = input(false, 'Equal High/Low'
, group = 'EQH/EQL'
, tooltip = SHOW_EQHL)
//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
show_fvg = input(true, 'Fair Value Gaps'
, group = 'Fair Value Gaps'
, tooltip = SHOW_FVG)
//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
show_pdhl = input(true, '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')
//-----------------------------------------------------------------------------}
//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]
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
if swing
if style == 'Monochrome'
css := array.get(target_type, i) == 1 ?
color.new(#b2b5be, 80) : color.new(#5d606b, 80)
border_css = array.get(target_type, i) == 1 ? #b2b5be :
#5d606b
box.set_border_color(get_box, border_css)
else
css := array.get(target_type, i) == 1 ? bull_ob_css :
bear_ob_css
box.set_border_color(get_box, css)
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)
if barstate.islast
ext = time + (time - time[1])*20
//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 trend4 = 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)
[itop, ibtm] = swings(5)
//-----------------------------------------------------------------------------}
//Pivot High
//-----------------------------------------------------------------------------{
var line extend_top = na
if top
top_cross := true
txt_top := top > top_y ? 'HH' : 'LH'
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
if itop
itop_cross := true
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, trend4 < 0 ? 'Strong High' : 'Weak
High')
//-----------------------------------------------------------------------------}
//Pivot Low
//-----------------------------------------------------------------------------{
var line extend_btm = na
if btm
btm_cross := true
txt_btm := btm < btm_y ? 'LL' : 'HL'
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
if ibtm
ibtm_cross := true
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, trend4 > 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 ifilter_confluence
bull_concordant := high - math.max(close, open) >
math.min(close, open - low)
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 trend4 < 0
choch := true
bull_choch_alert := true
else
bull_bos_alert := true
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
trend4 := 1
//-----------------------------------------------------------------------------}
//Pivot Low BOS/CHoCH
//-----------------------------------------------------------------------------{
var bear_concordant = true
if ifilter_confluence
bear_concordant := high - math.max(close, open) <
math.min(close, open - low)
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 trend4 > 0
choch := true
bear_choch_alert := true
else
bear_bos_alert := true
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
trend4 := -1
//-----------------------------------------------------------------------------}
//Order Blocks
//-----------------------------------------------------------------------------{
//Set order blocks
var iob_boxes = array.new_box(0)
var ob_boxes = array.new_box(0)
iob_size = array.size(iob_type)
ob_size = array.size(ob_type)
if barstate.isfirst
if show_iob
for i = 0 to iob_showlast-1
array.push(iob_boxes, box.new(na,na,na,na, xloc =
xloc.bar_time))
if show_ob
for i = 0 to ob_showlast-1
array.push(ob_boxes, box.new(na,na,na,na, xloc =
xloc.bar_time))
if iob_size > 0
if barstate.islast
display_ob(iob_boxes, iob_top, iob_btm, iob_left, iob_type,
iob_showlast, false, iob_size)
if ob_size > 0
if barstate.islast
display_ob(ob_boxes, ob_top, ob_btm, ob_left, ob_type,
ob_showlast, true, ob_size)
//-----------------------------------------------------------------------------}
//EQH/EQL
//-----------------------------------------------------------------------------{
var eq_prev_top = 0.
var eq_top_x = 0
var eq_prev_btm = 0.
var eq_btm_x = 0
if show_eq
eq_top = ta.pivothigh(eq_len, eq_len)
eq_btm = ta.pivotlow(eq_len, eq_len)
if eq_top
max = math.max(eq_top, eq_prev_top)
min = math.min(eq_top, eq_prev_top)
eqh_alert := true
eq_prev_top := eq_top
eq_top_x := n-eq_len
if 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
if show_fvg
delta_per = (src_c1 - src_o1) / src_o1 * 100
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
//FVG Areas
if bullish_fvg_cnd
array.unshift(bullish_fvg_max, box.new(n-1, src_l, n +
fvg_extend, math.avg(src_l, src_h2)
, border_color = bull_fvg_css
, bgcolor = bull_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
phl(pwh, pwl, 'W', pwhl_css)
//Display Monthly
if show_pmhl
phl(pmh, pml, 'M', pmhl_css)
//-----------------------------------------------------------------------------}
//Premium/Discount/Equilibrium zones
//-----------------------------------------------------------------------------{
var premium = box.new(na, na, na, na
, bgcolor = color.new(premium_css, 50)
, border_color = na)
label.set_xy(eq_lbl, n, avg)
//-----------------------------------------------------------------------------}
//Trend
//-----------------------------------------------------------------------------{
var color trend_css = na
if show_trend
if style == 'Colored'
trend_css := itrend == 1 ? bull_css : bear_css
else if style == 'Monochrome'
trend_css := itrend == 1 ? #b2b5be : #5d606b