0% found this document useful (0 votes)
408 views22 pages

Swing Killer

Uploaded by

vashugautam97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
408 views22 pages

Swing Killer

Uploaded by

vashugautam97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//THIS INDICATOR IS MADE BY ARIJIT FOR PRIVATE USE

//@version=5
indicator("SWING KILLER 2.1", overlay = 1)

// Inputs
src =close
p = 200
atr_p = [Link](53,"ATR period",1,100)
mult = [Link](2.8,"ATR Multiplier",1,10,0.1)
mode = [Link]("Type A", "Signal mode", options = ["Type A", "Type B"], group
= "Mode")
use_ema_smoother = [Link]("No", "Smooth source with EMA?", options = ["Yes",
"No"], group = "Source")
src_ema_period = input(3, "EMA Smoother period", group = "Source")
color_bars = input(true, "Color bars?", group = "Addons")
show_tl = false
signals_view = [Link]("All", "Signals to show", options = ["All", "Buy/Sell",
"Strong", "None"], group = "Signal's Addon")
signals_shape = [Link]("Labels", "Signal's shape", options = ["Labels",
"Arrows"], group = "Signal's Addon")
buy_col = input([Link], "Buy colour", group = "Signal's Addon", inline = "BS")
sell_col = input([Link], "Sell colour", group = "Signal's Addon", inline = "BS")

// Calculations
src := use_ema_smoother == "Yes" ? [Link](src, src_ema_period) : src // Source;

h = [Link](src, p) // Highest of src p-bars back;


l = [Link](src, p) // Lowest of src p-bars back.
d = h - l

ls = "" // Tracker of last signal

m = (h + l) / 2 // Initial trend line;


m := bar_index > p ? m[1] : m

atr = [Link](atr_p)[1] // ATR;


epsilon = mult * atr // Epsilon is a mathematical variable used in many different
theorems in order to simplify work with mathematical object. Here it used as
sensitivity measure.

change_up = (mode == "Type B" ? [Link](src, m + epsilon) : [Link](src, m +


epsilon)) or src > m + epsilon // If price breaks trend line + epsilon (so called
higher band), then it is time to update the value of a trend line;
change_down = (mode == "Type B" ? [Link](src, m - epsilon) : [Link](src, m
- epsilon)) or src < m - epsilon // If price breaks trend line - epsilon (so called
higher band), then it is time to update the value of a trend line.
sb = open < l + d / 8 and open >= l
ss = open > h - d / 8 and open <= h
super_buy = sb or sb[1] or sb[2] or sb[3] or sb[4]
super_sell = ss or ss[1] or ss[2] or ss[3] or ss[4]

m := (change_up or change_down) and m != m[1] ? m : change_up ? m + epsilon :


change_down ? m - epsilon : nz(m[1], m) // Updating the trend line.

ls := change_up ? "B" : change_down ? "S" : ls[1] // Last signal. Helps avoid


multiple labels in a row with the same signal;
colour = ls == "B" ? buy_col : sell_col // Colour of the trend line.
buy_shape = signals_shape == "Labels" ? [Link] : [Link]
sell_shape = signals_shape == "Labels" ? [Link] : [Link]

// Plottings

// Signals with label shape


plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view ==
"Buy/Sell") and change_up and ls[1] != "B" and not super_buy, "BUY signal" ,
color = colour, style = buy_shape , location = [Link], size =
[Link], text = "BUY", textcolor = [Link]) // Plotting the BUY
signal;
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view ==
"Buy/Sell") and change_down and ls[1] != "S" and not super_sell, "SELL signal" ,
color = colour, style = sell_shape, size = [Link], text = "SELL", textcolor =
[Link]) // Plotting the SELL signal.
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view ==
"Strong") and change_up and ls[1] != "B" and super_buy, "SUPER BUY signal" ,
color = colour, style = buy_shape , location = [Link], size =
[Link], text = "SUPER", textcolor = [Link]) // Plotting the SUPER BUY
signal;
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view ==
"Strong") and change_down and ls[1] != "S" and super_sell, "SUPER SELL signal" ,
color = colour, style = sell_shape, size = [Link], text = "SUPER", textcolor =
[Link]) // Plotting the SUPER SELL signal.

// Signal with arrow shape


plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view ==
"Buy/Sell") and change_up and ls[1] != "B" and not super_buy, "Buy signal" ,
color = colour, style = buy_shape , location = [Link], size = [Link])
// Plotting the BUY signal;
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view ==
"Buy/Sell") and change_down and ls[1] != "S" and not super_sell, "Sell signal" ,
color = colour, style = sell_shape, size = [Link])
// Plotting the SELL signal.
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view ==
"Strong") and change_up and ls[1] != "B" and super_buy, "Super Buy signal" ,
color = colour, style = buy_shape , location = [Link], size = [Link])
// Plotting the STRONG BUY signal;
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view ==
"Strong") and change_down and ls[1] != "S" and super_sell, "Super Sell signal" ,
color = colour, style = sell_shape, size = [Link])
// Plotting the STRONG SELL signal.

// Alerts
alertcondition(change_up and ls[1] != "B", "SWING KILLER BUY", "SWING KILLER BUY
signal were given.") // Buy alert.
alertcondition(change_down and ls[1] != "S", "SWING KILLER SELL", "SWING KILLER
SELL signal were given.") // Sell alert.
alertcondition((change_up and ls[1] != "B") or (change_down and ls[1] != "S"),
"SWING KILLER Signal", "SWING KILLER gave you a signal!")
alertcondition(change_up and ls[1] != "B" and super_buy, "Super BUY signal", "SWING
KILLER gave a Super Buy signal!")
alertcondition(change_down and ls[1] != "S" and super_sell, "Super SELL signal",
"SWING KILLER gave a Super Sell signal!")

import loxx/loxxexpandedsourcetypes/4

greencolor = #2DD204
redcolor = #D2042D

_iT3(src1, per, hot, clean)=>


a = hot
_c1 = -a * a * a
_c2 = 3 * a * a + 3 * a * a * a
_c3 = -6 * a * a - 3 * a - 3 * a * a * a
_c4 = 1 + 3 * a + a * a * a + 3 * a * a

alpha = 0.

if (clean == "T3 New")


alpha := 2.0 / (2.0 + (per - 1.0) / 2.0)
else
alpha := 2.0 / (1.0 + per)

_t30 = src, _t31 = src1


_t32 = src, _t33 = src1
_t34 = src, _t35 = src1

_t30 := nz(_t30[1]) + alpha * (src - nz(_t30[1]))


_t31 := nz(_t31[1]) + alpha * (_t30 - nz(_t31[1]))
_t32 := nz(_t32[1]) + alpha * (_t31 - nz(_t32[1]))
_t33 := nz(_t33[1]) + alpha * (_t32 - nz(_t33[1]))
_t34 := nz(_t34[1]) + alpha * (_t33 - nz(_t34[1]))
_t35 := nz(_t35[1]) + alpha * (_t34 - nz(_t35[1]))
out =
_c1 * _t35 + _c2 * _t34 +
_c3 * _t33 + _c4 * _t32

lev0 = _t30
lev1 = _t31
lev2 = _t32
lev3 = _t33
lev4 = _t34
lev5 = _t35
[lev0, lev1, lev2, lev3, lev4, lev5]

smthtype = [Link]("KILLER", "Heikin-Ashi Better Caculation Type", options =


["AMA", "K4", "KILLER"], group = "Source Settings")

src1in = [Link]("Close", "Source", group= "Source Settings",


options =
["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average",
"Average Median Body", "Trend Biased", "Trend Biased (Extreme)",
"HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA
Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend
Biased (Extreme)",
"HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical",
"HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB
Trend Biased (Extreme)"])

per = 14
t3hot = [Link](.7, "K4 Hot", group= "Basic Settings")
t3swt = [Link]("K4 New", "K4 Type", options = ["K4 New", "K4 Original"],
group = "Basic Settings")

colorbars = [Link](true, "Color bars?", group = "UI Options")


showSigs = [Link](true, "Show signals?", group = "UI Options")

kfl=[Link](0.666, title="* KILLER's Adaptive MA (KAMA) Only - Fast End", group


= "Moving Average Inputs")
ksl=[Link](0.0645, title="* KILLER's Adaptive MA (KAMA) Only - Slow End",
group = "Moving Average Inputs")
amafl = [Link](2, title="* Adaptive Moving Average (AMA) Only - Fast", group =
"Moving Average Inputs")
amasl = [Link](30, title="* Adaptive Moving Average (AMA) Only - Slow", group =
"Moving Average Inputs")

haclose = [Link]([Link]([Link]), [Link],


close)
haopen = [Link]([Link]([Link]), [Link],
open)
hahigh = [Link]([Link]([Link]), [Link],
high)
halow = [Link]([Link]([Link]), [Link],
low)
hamedian = [Link]([Link]([Link]), [Link],
hl2)
hatypical = [Link]([Link]([Link]), [Link],
hlc3)
haweighted = [Link]([Link]([Link]),
[Link], hlcc4)
haaverage = [Link]([Link]([Link]), [Link],
ohlc4)

src1 = switch src1in


"Close" => [Link]()
"Open" => [Link]()
"High" => [Link]()
"Low" => [Link]()
"Median" => [Link]()
"Typical" => [Link]()
"Weighted" => [Link]()
"Average" => [Link]()
"Average Median Body" => [Link]()
"Trend Biased" => [Link]()
"Trend Biased (Extreme)" => [Link]()
"HA Close" => [Link](haclose)
"HA Open" => [Link](haopen)
"HA High" => [Link](hahigh)
"HA Low" => [Link](halow)
"HA Median" => [Link](hamedian)
"HA Typical" => [Link](hatypical)
"HA Weighted" => [Link](haweighted)
"HA Average" => [Link](haaverage)
"HA Average Median Body" => [Link](haclose,
haopen)
"HA Trend Biased" => [Link](haclose, haopen,
hahigh, halow)
"HA Trend Biased (Extreme)" => [Link](haclose,
haopen, hahigh, halow)
"HAB Close" => [Link](smthtype, amafl, amasl, kfl,
ksl)
"HAB Open" => [Link](smthtype, amafl, amasl, kfl,
ksl)
"HAB High" => [Link](smthtype, amafl, amasl, kfl,
ksl)
"HAB Low" => [Link](smthtype, amafl, amasl, kfl, ksl)
"HAB Median" => [Link](smthtype, amafl, amasl,
kfl, ksl)
"HAB Typical" => [Link](smthtype, amafl, amasl,
kfl, ksl)
"HAB Weighted" => [Link](smthtype, amafl, amasl,
kfl, ksl)
"HAB Average" => [Link](smthtype, amafl, amasl,
kfl, ksl)
"HAB Average Median Body" => [Link](smthtype,
amafl, amasl, kfl, ksl)
"HAB Trend Biased" => [Link](smthtype, amafl,
amasl, kfl, ksl)
"HAB Trend Biased (Extreme)" =>
[Link](smthtype, amafl, amasl, kfl, ksl)
=> haclose

[lev0, lev1, lev2, lev3, lev4, lev5] = _iT3(src1, per, t3hot, t3swt)

colorout = lev0 < lev1 and lev0 > lev5 ? [Link] : lev0 > lev5 ? greencolor :
redcolor

pl0 = plot(lev0, "level 0",color=[Link](0, 0, 0, 900), linewidth = 2)


pl1 = plot(lev1, "level 1",color=[Link](0, 0, 0, 900), linewidth = 2)
pl2 = plot(lev2, "level 2",color=[Link](0, 0, 0, 900), linewidth = 2)
pl3 = plot(lev3, "level 3",color=[Link](0, 0, 0, 900), linewidth = 2)
pl4 = plot(lev4, "level 4",color=[Link](0, 0, 0,900), linewidth = 2)
pl5 = plot(lev5, "level 5",color=[Link](0, 0, 0, 900), linewidth = 2)

fill(pl0, pl1, color = [Link](colorout, 55))


fill(pl1, pl2, color = [Link](colorout, 58))
fill(pl2, pl3, color = [Link](colorout, 60))
fill(pl3, pl4, color = [Link](colorout, 62))
fill(pl4, pl5, color = [Link](colorout, 65))

barcolor(colorbars ? colorout : na)

goLong = [Link](lev0, lev5)


goShort = [Link](lev0, lev5)

BB_CONFIG = "BACKTEST: BOLLINGER BANDS"


smaLengthInput = [Link](defval=20, group=BB_CONFIG,
inline="01", title="Length", minval=1)
smaColorInput = [Link](defval=[Link](182, 179, 174, 61),
group=BB_CONFIG, inline="01", title="")
sourceInput = [Link](defval=close, group=BB_CONFIG,
inline="02", title="Source")
bbFactorInput = [Link](defval=0.382, group=BB_CONFIG,
inline="03", title="Factor", minval=0.001, maxval=50, step=0.05)
bbColorInput = [Link](defval=[Link](247, 250, 252, 40),
group=BB_CONFIG, inline="03", title="")
offsetInput = [Link](defval=1, group=BB_CONFIG,
inline="04", title="Offset")

// Bollinger Bands and Simple Moving Average


sma = [Link](sourceInput, smaLengthInput)
bbBackgroundColor = [Link](255, 255, 255, 35)
bbWidth = [Link](sourceInput, smaLengthInput) * bbFactorInput
bbHigh = sma + bbWidth
bbLow = sma - bbWidth
plot(sma, title="SMA", color=smaColorInput, offset=offsetInput)
bbUpper = plot(bbHigh, title="BB High", color=bbColorInput, offset=offsetInput)
bbLower = plot(bbLow, title="BB Low", color=bbColorInput, offset=offsetInput)
fill(bbUpper, bbLower, title="BB Background", color=bbBackgroundColor)

//-----------------------------------------------------------------------------{
//Constants
//-----------------------------------------------------------------------------{
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
//----------------------------------------{
mod = 'Historical'

style = [Link]('Colored'
, options = ['Colored', 'Monochrome']
, group = 'Order Block'
, tooltip = STYLE_TOOLTIP)

show_trend = false
//----------------------------------------}
//Internal Structure
//----------------------------------------{
show_internals = false

show_ibull ='All'

swing_ibull_css = #089981

//Bear Structure
show_ibear = 'All'

swing_ibear_css = #f23645

ifilter_confluence = false

internal_structure_size = 'Tiny'

//----------------------------------------}
//Swing Structure
//----------------------------------------{
show_Structure = true

//Bull Structure
show_bull = 'All'

swing_bull_css = #089981

//Bear Structure
show_bear = 'All'

swing_bear_css = #f23645

swing_structure_size = 'Small'

//Swings
show_swings = false
length = 50

show_hl_swings = false
//----------------------------------------}
//Order Blocks
//----------------------------------------{
show_iob = input(true, 'Internal Order Blocks'
, inline = 'iob'
, group = 'Order Blocks'
, tooltip = INTERNAL_OB)

iob_showlast = [Link](5, ''


, minval = 1
, inline = 'iob'
, group = 'Order Blocks')

show_ob = input(false, 'Swing Order Blocks'


, inline = 'ob'
, group = 'Order Blocks'
, tooltip = SWING_OB)

ob_showlast = [Link](5, ''


, minval = 1
, inline = 'ob'
, group = 'Order Blocks')

ob_filter = [Link]('Atr', 'Order Block Filter'


, options = ['Atr', 'Cumulative Mean Range']
, group = 'Order Blocks'
, tooltip = FILTER_OB)

ibull_ob_css = [Link]([Link](#3179f5, 80), 'Internal Bullish OB'


, group = 'Order Blocks')

ibear_ob_css = [Link]([Link](#f77c80, 80), 'Internal Bearish OB'


, group = 'Order Blocks')

bull_ob_css = [Link]([Link](#1848cc, 80), 'Bullish OB'


, group = 'Order Blocks')

bear_ob_css = [Link]([Link](#b22833, 80), 'Bearish OB'


, group = 'Order Blocks')

//----------------------------------------}
//EQH/EQL
//----------------------------------------{
show_eq = false

eq_len = 3

eq_threshold = 0.1

eq_size = 'Tiny'

//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
show_fvg = false

fvg_auto = false
fvg_tf = ''

bull_fvg_css = [Link](#00ff68, 70)

bear_fvg_css = [Link](#ff0008, 70)

fvg_extend = 1

//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
show_pdhl = input(false, 'Daily'
, inline = 'daily'
, group = 'Highs & Lows MTF')

pdhl_style = [Link]('⎯⎯⎯', ''


, options = ['⎯⎯⎯', '----', '····']
, inline = 'daily'
, group = 'Highs & Lows MTF')

pdhl_css = input(#2157f3, ''


, inline = 'daily'
, group = 'Highs & Lows MTF')

//Weekly
show_pwhl = input(false, 'Weekly'
, inline = 'weekly'
, group = 'Highs & Lows MTF')

pwhl_style = [Link]('⎯⎯⎯', ''


, options = ['⎯⎯⎯', '----', '····']
, inline = 'weekly'
, group = 'Highs & Lows MTF')

pwhl_css = input(#2157f3, ''


, inline = 'weekly'
, group = 'Highs & Lows MTF')

//Monthly
show_pmhl = input(false, 'Monthly'
, inline = 'monthly'
, group = 'Highs & Lows MTF')

pmhl_style = [Link]('⎯⎯⎯', ''


, options = ['⎯⎯⎯', '----', '····']
, inline = 'monthly'
, group = 'Highs & Lows MTF')

pmhl_css = input(#2157f3, ''


, inline = 'monthly'
, group = 'Highs & Lows MTF')

//----------------------------------------}
//Premium/Discount zones
//----------------------------------------{
show_sd = input(false, 'Premium/Discount Zones'
, group = 'Premium & Discount Zones'
, tooltip = PED_ZONES)
premium_css = [Link](#f23645, 'Premium Zone'
, group = 'Premium & Discount Zones')

eq_css = [Link](#b2b5be, 'Equilibrium Zone'


, group = 'Premium & Discount Zones')

discount_css = [Link](#089981, 'Discount Zone'


, group = 'Premium & Discount Zones')

//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index

aatr = [Link](200)
cmean_range = [Link](high - low) / n

//HL Output function


hl() => [high, low]

//Get ohlc values function


get_ohlc()=> [close[1], open[1], high, low, high[2], low[2]]

//Display Structure function


display_Structure(x, y, txt, css, dashed, down, lbl_size)=>
structure_line = [Link](x, y, n, y
, color = css
, style = dashed ? line.style_dashed : line.style_solid)

structure_lbl = [Link](int([Link](x, n)), y, txt


, color = TRANSP_CSS
, textcolor = css
, style = down ? label.style_label_down : label.style_label_up
, size = lbl_size)

if mod == 'Present'
[Link](structure_line[1])
[Link](structure_lbl[1])

//Swings detection/measurements
swings(len)=>
var os = 0

upper = [Link](len)
lower = [Link](len)

os := high[len] > upper ? 0 : low[len] < lower ? 1 : os[1]

top = os == 0 and os[1] != 0 ? high[len] : 0


btm = os == 1 and os[1] != 1 ? low[len] : 0

[top, btm]

//Order block coordinates function


ob_coord(use_max, loc, target_top, target_btm, target_left, target_type)=>
min = 99999999.
max = 0.
idx = 1
ob_threshold = ob_filter == 'Atr' ? aatr : cmean_range

//Search for highest/lowest high within the structure interval and get range
if use_max
for i = 1 to (n - loc)-1
if (high[i] - low[i]) < ob_threshold[i] * 2
max := [Link](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 := [Link](low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx

[Link](target_top, max)
[Link](target_btm, min)
[Link](target_left, time[idx])
[Link](target_type, use_max ? -1 : 1)

//Set order blocks


display_ob(boxes, target_top, target_btm, target_left, target_type, show_last,
swing, size)=>
for i = 0 to [Link](show_last-1, size-1)
get_box = [Link](boxes, i)

box.set_lefttop(get_box, [Link](target_left, i), [Link](target_top,


i))
box.set_rightbottom(get_box, [Link](target_left, i),
[Link](target_btm, i))
box.set_extend(get_box, [Link])

color css = na

if swing
if style == 'Monochrome'
css := [Link](target_type, i) == 1 ? [Link](#b2b5be, 80) :
[Link](#5d606b, 80)
border_css = [Link](target_type, i) == 1 ? #b2b5be : #5d606b
box.set_border_color(get_box, border_css)
else
css := [Link](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 := [Link](target_type, i) == 1 ? [Link](#b2b5be, 80) :
[Link](#5d606b, 80)
else
css := [Link](target_type, i) == 1 ? ibull_ob_css : ibear_ob_css

box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)

//Line Style function


get_line_style(style) =>
out = switch style
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted

//Set line/labels function for previous high/lows


phl(h, l, tf, css)=>
var line high_line = [Link](na,na,na,na
, xloc = xloc.bar_time
, color = css
, style = get_line_style(pdhl_style))

var label high_lbl = [Link](na,na


, xloc = xloc.bar_time
, text = [Link]('P{0}H', tf)
, color = TRANSP_CSS
, textcolor = css
, size = [Link]
, style = label.style_label_left)

var line low_line = [Link](na,na,na,na


, xloc = xloc.bar_time
, color = css
, style = get_line_style(pdhl_style))

var label low_lbl = [Link](na,na


, xloc = xloc.bar_time
, text = [Link]('P{0}L', tf)
, color = TRANSP_CSS
, textcolor = css
, size = [Link]
, style = label.style_label_left)

hy = [Link](h != h[1], h, 1)
hx = [Link](h == high, time, 1)

ly = [Link](l != l[1], l, 1)
lx = [Link](l == low, time, 1)

if [Link]
ext = time + (time - time[1])*20

//High
line.set_xy1(high_line, hx, hy)
line.set_xy2(high_line, ext, hy)

label.set_xy(high_lbl, ext, hy)

//Low
line.set_xy1(low_line, lx, ly)
line.set_xy2(low_line, ext, ly)

label.set_xy(low_lbl, ext, ly)

//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
var trend = 0, var itrend = 0
var top_y = 0., var top_x = 0
var btm_y = 0., var btm_x = 0

var itop_y = 0., var itop_x = 0


var ibtm_y = 0., var ibtm_x = 0

var trail_up = high, var trail_dn = low


var trail_up_x = 0, var trail_dn_x = 0

var top_cross = true, var btm_cross = true


var itop_cross = true, var ibtm_cross = true

var txt_top = '', var txt_btm = ''

//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

var bear_css = style == 'Monochrome' ? #b2b5be


: swing_bear_css

var ibull_css = style == 'Monochrome' ? #b2b5be


: swing_ibull_css

var ibear_css = style == 'Monochrome' ? #b2b5be


: swing_ibear_css

//Labels size
var internal_structure_lbl_size = internal_structure_size == 'Tiny'
? [Link]
: internal_structure_size == 'Small'
? [Link]
: [Link]

var swing_structure_lbl_size = swing_structure_size == 'Tiny'


? [Link]
: swing_structure_size == 'Small'
? [Link]
: [Link]

var eqhl_lbl_size = eq_size == 'Tiny'


? [Link]
: eq_size == 'Small'
? [Link]
: [Link]

//Swings
[top, btm] = swings(length)

[itop, ibtm] = swings(5)

//-----------------------------------------------------------------------------}
//Pivot High
//-----------------------------------------------------------------------------{
var line extend_top = na

var label extend_top_lbl = [Link](na, na


, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = [Link])

if top
top_cross := true
txt_top := top > top_y ? 'HH' : 'LH'

if show_swings
top_lbl = [Link](n-length, top, txt_top
, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = swing_structure_lbl_size)

if mod == 'Present'
[Link](top_lbl[1])

//Extend recent top to last bar


[Link](extend_top[1])
extend_top := [Link](n-length, top, n, top
, color = bear_css)

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 := [Link](high, trail_up)
trail_up_x := trail_up == high ? n : trail_up_x
//Set top extension label/line
if [Link] and show_hl_swings
line.set_xy1(extend_top, trail_up_x, trail_up)
line.set_xy2(extend_top, n + 20, trail_up)

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

var label extend_btm_lbl = [Link](na, na


, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = [Link])

if btm
btm_cross := true
txt_btm := btm < btm_y ? 'LL' : 'HL'

if show_swings
btm_lbl = [Link](n - length, btm, txt_btm
, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = swing_structure_lbl_size)

if mod == 'Present'
[Link](btm_lbl[1])

//Extend recent btm to last bar


[Link](extend_btm[1])
extend_btm := [Link](n - length, btm, n, btm
, color = bull_css)

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 := [Link](low, trail_dn)
trail_dn_x := trail_dn == low ? n : trail_dn_x

//Set btm extension label/line


if [Link] and show_hl_swings
line.set_xy1(extend_btm, trail_dn_x, trail_dn)
line.set_xy2(extend_btm, n + 20, trail_dn)

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)

var ob_top = array.new_float(0)


var ob_btm = array.new_float(0)
var ob_left = array.new_int(0)
var ob_type = array.new_int(0)

//-----------------------------------------------------------------------------}
//Pivot High BOS/CHoCH
//-----------------------------------------------------------------------------{
//Filtering
var bull_concordant = true

if ifilter_confluence
bull_concordant := high - [Link](close, open) > [Link](close, open - low)

//Detect internal bullish Structure


if [Link](close, itop_y) and itop_cross and top_y != itop_y and
bull_concordant
bool choch = na

if itrend < 0
choch := true
bull_ichoch_alert := true
else
bull_ibos_alert := true

txt = choch ? '' : ''

if show_internals
if show_ibull == 'All' or (show_ibull == '' and not choch) or (show_ibull
== '' and choch)
display_Structure(itop_x, itop_y, txt, ibull_css, true, true,
internal_structure_lbl_size)

itop_cross := false
itrend := 1

//Internal Order Block


if show_iob
ob_coord(false, itop_x, iob_top, iob_btm, iob_left, iob_type)

//Detect bullish Structure


if [Link](close, top_y) and top_cross
bool choch = na

if trend < 0
choch := true
bull_choch_alert := true
else
bull_bos_alert := true

txt = choch ? '' : ''

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 ifilter_confluence
bear_concordant := high - [Link](close, open) < [Link](close, open - low)

//Detect internal bearish Structure


if [Link](close, ibtm_y) and ibtm_cross and btm_y != ibtm_y and
bear_concordant
bool choch = false

if itrend > 0
choch := true
bear_ichoch_alert := true
else
bear_ibos_alert := true

txt = choch ? '' : ''

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

//Internal Order Block


if show_iob
ob_coord(true, ibtm_x, iob_top, iob_btm, iob_left, iob_type)

//Detect bearish Structure


if [Link](close, btm_y) and btm_cross
bool choch = na

if trend > 0
choch := true
bear_choch_alert := true
else
bear_bos_alert := true

txt = choch ? '' : ''

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)

//Delete internal order blocks box coordinates if top/bottom is broken


for element in iob_type
index = [Link](iob_type, element)

if close < [Link](iob_btm, index) and element == 1


[Link](iob_top, index)
[Link](iob_btm, index)
[Link](iob_left, index)
[Link](iob_type, index)
bull_iob_break := true

else if close > [Link](iob_top, index) and element == -1


[Link](iob_top, index)
[Link](iob_btm, index)
[Link](iob_left, index)
[Link](iob_type, index)
bear_iob_break := true

//Delete internal order blocks box coordinates if top/bottom is broken


for element in ob_type
index = [Link](ob_type, element)

if close < [Link](ob_btm, index) and element == 1


[Link](ob_top, index)
[Link](ob_btm, index)
[Link](ob_left, index)
[Link](ob_type, index)
bull_ob_break := true

else if close > [Link](ob_top, index) and element == -1


[Link](ob_top, index)
[Link](ob_btm, index)
[Link](ob_left, index)
[Link](ob_type, index)
bear_ob_break := true

iob_size = [Link](iob_type)
ob_size = [Link](ob_type)

if [Link]
if show_iob
for i = 0 to iob_showlast-1
[Link](iob_boxes, [Link](na,na,na,na, xloc = xloc.bar_time))
if show_ob
for i = 0 to ob_showlast-1
[Link](ob_boxes, [Link](na,na,na,na, xloc = xloc.bar_time))

if iob_size > 0
if [Link]
display_ob(iob_boxes, iob_top, iob_btm, iob_left, iob_type, iob_showlast,
false, iob_size)

if ob_size > 0
if [Link]
display_ob(ob_boxes, ob_top, ob_btm, ob_left, ob_type, ob_showlast, true,
ob_size)

//-----------------------------------------------------------------------------}

//-----------------------------------------------------------------------------}
//Fair Value Gaps
//-----------------------------------------------------------------------------{
var bullish_fvg_max = array.new_box(0)
var bullish_fvg_min = array.new_box(0)

var bearish_fvg_max = array.new_box(0)


var bearish_fvg_min = array.new_box(0)

float bullish_fvg_avg = na
float bearish_fvg_avg = na

bullish_fvg_cnd = false
bearish_fvg_cnd = false

[src_c1, src_o1, src_h, src_l, src_h2, src_l2] =


[Link]([Link], fvg_tf, get_ohlc())

if show_fvg
delta_per = (src_c1 - src_o1) / src_o1 * 100

change_tf = [Link](fvg_tf)

threshold = fvg_auto ? [Link]([Link](change_tf ? delta_per : 0)) / n * 2


: 0

//FVG conditions
bullish_fvg_cnd := src_l > src_h2
and src_c1 > src_h2
and delta_per > threshold
and change_tf
bearish_fvg_cnd := src_h < src_l2
and src_c1 < src_l2
and -delta_per > threshold
and change_tf

//FVG Areas
if bullish_fvg_cnd
[Link](bullish_fvg_max, [Link](n-1, src_l, n + fvg_extend,
[Link](src_l, src_h2)
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css))

[Link](bullish_fvg_min, [Link](n-1, [Link](src_l, src_h2), n +


fvg_extend, src_h2
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css))

if bearish_fvg_cnd
[Link](bearish_fvg_max, [Link](n-1, src_h, n + fvg_extend,
[Link](src_h, src_l2)
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css))

[Link](bearish_fvg_min, [Link](n-1, [Link](src_h, src_l2), n +


fvg_extend, src_l2
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css))

for bx in bullish_fvg_min
if low < box.get_bottom(bx)
[Link](bx)
[Link]([Link](bullish_fvg_max, [Link](bullish_fvg_min,
bx)))

for bx in bearish_fvg_max
if high > box.get_top(bx)
[Link](bx)
[Link]([Link](bearish_fvg_min, [Link](bearish_fvg_max,
bx)))

//-----------------------------------------------------------------------------}
//Previous day/week high/lows
//-----------------------------------------------------------------------------{
//Daily high/low
[pdh, pdl] = [Link]([Link], 'D', hl()
, lookahead = barmerge.lookahead_on)

//Weekly high/low
[pwh, pwl] = [Link]([Link], 'W', hl()
, lookahead = barmerge.lookahead_on)

//Monthly high/low
[pmh, pml] = [Link]([Link], '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 = [Link](na, na, na, na
, bgcolor = [Link](premium_css, 80)
, border_color = na)

var premium_lbl = [Link](na, na


, text = 'Premium'
, color = TRANSP_CSS
, textcolor = premium_css
, style = label.style_label_down
, size = [Link])

var eq = [Link](na, na, na, na


, bgcolor = [Link](120, 123, 134, 80)
, border_color = na)

var eq_lbl = [Link](na, na


, text = 'Equilibrium'
, color = TRANSP_CSS
, textcolor = eq_css
, style = label.style_label_left
, size = [Link])

var discount = [Link](na, na, na, na


, bgcolor = [Link](discount_css, 80)
, border_color = na)

var discount_lbl = [Link](na, na


, text = 'Discount'
, color = TRANSP_CSS
, textcolor = discount_css
, style = label.style_label_up
, size = [Link])

//Show Premium/Discount Areas


if [Link] and show_sd
avg = [Link](trail_up, trail_dn)

box.set_lefttop(premium, [Link](top_x, btm_x), trail_up)


box.set_rightbottom(premium, n, .95 * trail_up + .05 * trail_dn)

label.set_xy(premium_lbl, int([Link]([Link](top_x, btm_x), n)), trail_up)

box.set_lefttop(eq, [Link](top_x, btm_x), .525 * trail_up + .475*trail_dn)


box.set_rightbottom(eq, n, .525 * trail_dn + .475 * trail_up)

label.set_xy(eq_lbl, n, avg)
box.set_lefttop(discount, [Link](top_x, btm_x), .95 * trail_dn + .05 *
trail_up)
box.set_rightbottom(discount, n, trail_dn)
label.set_xy(discount_lbl, int([Link]([Link](top_x, btm_x), n)), trail_dn)

You might also like