PROTECTED SOURCE SCRIPT

聪明钱指标

58
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) creativecommons.org/licenses/by-nc-sa/4.0/
// © robin_3910

//version=5
indicator("聪明钱指标", "聪明钱指标"
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)
//-----------------------------------------------------------------------------{
//Constants
//-----------------------------------------------------------------------------{
color TRANSP_CSS = #ffffff00

//Tooltips
string MODE_TOOLTIP = '允许显示历史结构或仅显示最近的结构'
string STYLE_TOOLTIP = '指示器颜色主题'
string COLOR_CANDLES_TOOLTIP = '显示附加蜡烛,其颜色反映结构检测到的当前趋势'
string SHOW_INTERNAL = '显示内部市场结构'
string CONFLUENCE_FILTER = '过滤非重要的内部结构突破'
string SHOW_SWING = '显示波动市场结构'
string SHOW_SWING_POINTS = '在图表上将摆动点显示为标签'
string SHOW_SWHL_POINTS = '突出显示图表上最近的强弱高点/低点'
string INTERNAL_OB = '在图表上显示内部订单块\n\n要在图表上显示的内部订单块数量'
string SWING_OB = '在图表上显示摆动订单块\n\n要在图表上显示的内部摆动块数量'
string FILTER_OB = '用于过滤掉不稳定订单块的方法\n\n当可用数据量较少时,建议使用累积均值范围方法'
string SHOW_EQHL = '在图表上显示相等的高点和相等的低点'
string EQHL_BARS = '用于确认相等高点和相等低点的柱数'
string EQHL_THRESHOLD = '用于检测相等高点和低点的范围 (0, 1) 内的灵敏度阈值\n\n较低的值将返回较少但更相关的结果'
string SHOW_FVG = '在图表上显示公允价值差距'
string AUTO_FVG = '过滤掉不显着的公允价值差距'
string FVG_TF = '公允价值缺口时间范围'
string EXTEND_FVG = '确定在图表上扩展公允价值缺口框的数量'
string PED_ZONES = '在图表上显示溢价、折价和均衡区域'

// dailyHighAndLowLength = input.int(2, title = "近x日线高低点")
//-----------------------------------------------------------------------------{
//Settings
//-----------------------------------------------------------------------------{
//General
//----------------------------------------{
// mode = input.string('历史'
// , options = ['历史', '现在']
// , group = '聪明的金钱概念'
// ,tooltip = MODE_TOOLTIP)
mode = "historical"

// style = input.string('彩色'
// , options = ['彩色', '单色']
// , group = '聪明的金钱概念'
// ,tooltip = STYLE_TOOLTIP)
style = "Colored"

// show_trend = input(false, '彩色K线'
// , group = '聪明的金钱概念'
// , tooltip = COLOR_CANDLES_TOOLTIP)
show_trend = false


//----------------------------------------}
//Internal Structure
//----------------------------------------{
// show_internals = input(true, '显示内部结构'
// , group = '实时内部结构'
// ,tooltip= SHOW_INTERNAL)
show_internals = false

// show_ibull = input.string('全部', '看涨结构'
// , options = ['全部', 'BOS', 'CHoCH']
// , inline = 'ibull'
// , group = '实时内部结构')
show_ibull = "All"

// swing_ibull_css = input(#089981,''
// , inline = 'ibull'
// , group = '实时内部结构')
swing_ibull_css = color.rgb(8, 153, 80)
// bear结构体
// show_ibear = input.string('全部', '看跌结构'
// , options = ['全部', 'BOS', 'CHoCH']
// , inline = 'ibear'
// , group = '实时内部结构')
show_ibear = "All"

// swing_ibear_css = input(#f23645,''
// , inline = 'ibear'
// , group = '实时内部结构')
swing_ibear_css = color.rgb(239, 54, 69)

// ifilter_confluence = input(false, '汇流过滤器'
// , group = '实时内部结构'
// ,tooltip= CONFLUENCE_FILTER)
ifilter_confluence = false

// internal_structure_size = input.string('Tiny', '内部标签大小'
// , options = ['Tiny', 'small', 'normal']
// , group = '实时内部结构')
internal_structure_size = "Tiny"

//----------------------------------------}
//Swing Structure
//----------------------------------------{
// show_Structure = input(true, '显示 Swing 结构'
// , group = '实时Swing结构'
// , tooltip = SHOW_SWING)
show_Structure = true

//Bull Structure
// show_bull = input.string('All', '看涨结构'
// , options = ['All', 'BOS', 'CHoCH']
// , inline = 'bull'
// , group = '实时Swing结构')
show_bull = "All"

// swing_bull_css = input(#089981, ''
// , inline = 'bull'
// , group = '实时Swing结构')
swing_bull_css = color.rgb(7, 153, 129)

//Bear Structure
// show_bear = input.string('All', '看跌结构'
// , options = ['All', 'BOS', 'CHoCH']
// , inline = 'bear'
// , group = '实时Swing结构')
show_bear = "All"

// swing_bear_css = input(#f23645, ''
// , inline = 'bear'
// , group = '实时Swing结构')
swing_bear_css = color.rgb(242, 54, 69)

// swing_structure_size = input.string('Small', 'Swing 标签大小'
// , options = ['Tiny', 'Small', 'Normal']
// , group = '实时Swing结构')
swing_structure_size = "Small"

//Swings
// show_swings = input(false, '展示 Swings 枢轴点'
// , inline = 'swings'
// , group = '实时Swing结构'
// , tooltip = SHOW_SWING_POINTS)
show_swings = true

// length = input.int(50, ''
// , minval = 10
// , inline = 'swings'
// , group = '实时Swing结构')
length = 50

// show_hl_swings = input(true, '展示 强弱、高低点'
// , group = '实时Swing结构'
// , tooltip = SHOW_SWHL_POINTS)
show_hl_swings = true

//----------------------------------------}
//Order Blocks
//----------------------------------------{
// show_iob = input(true, '内部结构订单块'
// , inline = 'iob'
// , group = '订单块'
// , tooltip = INTERNAL_OB)
show_iob = true

// iob_showlast = input.int(5, ''
// , minval = 1
// , inline = 'iob'
// , group = '订单块')
iob_showlast = 5

// show_ob = input(false, 'Swing订单块'
// , inline = 'ob'
// , group = '订单块'
// , tooltip = SWING_OB)
show_ob = false

// ob_showlast = input.int(5, ''
// , minval = 1
// , inline = 'ob'
// , group = '订单块')
ob_showlast = 5

// ob_filter = input.string('Atr', '订单块过滤'
// , options = ['Atr', 'Cumulative Mean Range']
// , group = '订单块'
// , tooltip = FILTER_OB)
ob_filter = "Atr"

// ibull_ob_css = input.color(color.new(#3179f5, 80), 'Internal Bullish OB'
// , group = '订单块')
ibull_ob_css = color.rgb(49, 123, 248, 52)

// ibear_ob_css = input.color(color.new(#f77c80, 80), 'Internal Bearish OB'
// , group = '订单块')
ibear_ob_css = color.rgb(248, 125, 128,50)

// bull_ob_css = input.color(color.new(#1848cc, 80), 'Bullish OB'
// , group = '订单块')
bull_ob_css = color.rgb(27, 75, 207, 52)

// bear_ob_css = input.color(color.new(#b22833, 80), 'Bearish OB'
// , group = '订单块')
bear_ob_css = color.rgb(178, 40, 51,50)

//----------------------------------------}
//EQH/EQL
//----------------------------------------{
// show_eq = input(true, '双顶/双底'
// , group = 'EQH/EQL'
// , tooltip = SHOW_EQHL)
show_eq = true

// eq_len = input.int(3, 'Bars 确认'
// , minval = 1
// , group = 'EQH/EQL'
// , tooltip = EQHL_BARS)
eq_len = 3

// eq_threshold = input.float(0.1, '阈值'
// , minval = 0
// , maxval = 0.5
// , step = 0.1
// , group = 'EQH/EQL'
// , tooltip = EQHL_THRESHOLD)
eq_threshold = 0.1

// eq_size = input.string('Tiny', '标签大小'
// , options = ['Tiny', 'Small', 'Normal']
// , group = 'EQH/EQL')
eq_size = 'Tiny'

//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
// show_fvg = input(false, '公允价值区域'
// , group = 'Fair Value Gaps'
// , tooltip = SHOW_FVG)
show_fvg = true

// fvg_auto = input(true, "自动阈值区"
// , group = 'Fair Value Gaps'
// , tooltip = AUTO_FVG)
fvg_auto = true

// fvg_tf = input.timeframe('', "时间区间"
// , group = 'Fair Value Gaps'
// , tooltip = FVG_TF)
fvg_tf = ''

// bull_fvg_css = input.color(color.new(#00ff68, 70), 'Bullish FVG'
// , group = 'Fair Value Gaps')
bull_fvg_css = color.new(#00ff68, 70)

// bear_fvg_css = input.color(color.new(#ff0008, 70), 'Bearish FVG'
// , group = 'Fair Value Gaps')
bear_fvg_css = color.new(#ff0008, 70)

// fvg_extend = input.int(1, "Extend FVG"
// , minval = 0
// , group = 'Fair Value Gaps'
// , tooltip = EXTEND_FVG)
fvg_extend = 1

//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
// show_pdhl = input(false, '日'
// , inline = 'daily'
// , group = '高低点展示')
show_pdhl = true

// pdhl_style = input.string('⎯⎯⎯', ''
// , options = ['⎯⎯⎯', '----', '····']
// , inline = 'daily'
// , group = '高低点展示')
pdhl_style = "----"

// pdhl_css = input(#2157f3, ''
// , inline = 'daily'
// , group = '高低点展示')
pdhl_css = color.rgb(34, 86, 244)

//Weekly
// show_pwhl = input(false, '周'
// , inline = 'weekly'
// , group = '高低点展示')
show_pwhl = true

// pwhl_style = input.string('⎯⎯⎯', ''
// , options = ['⎯⎯⎯', '----', '····']
// , inline = 'weekly'
// , group = '高低点展示')
pwhl_style = '····'

// pwhl_css = input(#2157f3, ''
// , inline = 'weekly'
// , group = '高低点展示')
pwhl_css = color.rgb(35, 87, 244)
//Monthly
// show_pmhl = input(false, '月'
// , inline = 'monthly'
// , group = '高低点展示')
show_pmhl = true

// pmhl_style = input.string('⎯⎯⎯', ''
// , options = ['⎯⎯⎯', '----', '····']
// , inline = 'monthly'
// , group = '高低点展示')
pmhl_style = '⎯⎯⎯'
pmhl_css = color.rgb(30, 84, 243)
// pmhl_css = input(#2157f3, ''
// , inline = 'monthly'
// , group = '高低点展示')

//----------------------------------------}
//Premium/Discount zones
//----------------------------------------{
// show_sd = input(false, '溢价折扣区'
// , group = '溢价折扣区'
// , tooltip = PED_ZONES)
show_sd = true
premium_css = color.rgb(241, 55, 70, 50)
// premium_css = input.color(#f23645, '溢价区'
// , group = '溢价折扣区')
eq_css = color.rgb(175, 178, 187, 50)
// eq_css = input.color(#b2b5be, '中间区域'
// , group = '溢价折扣区')
discount_css = color.rgb(8, 151, 127, 50)
// discount_css = input.color(#089981, '折扣区'
// , group = '溢价折扣区')

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

atr = ta.atr(200)
cmean_range = ta.cum(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 = line.new(x, y, n, y
, color = css
, style = dashed ? line.style_dashed : line.style_solid)

structure_lbl = label.new(int(math.avg(x, n)), y, txt
, color = TRANSP_CSS
, textcolor = css
, style = down ? label.style_label_down : label.style_label_up
, size = lbl_size)

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)

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' ? atr : 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 - low) < ob_threshold * 2
max := math.max(high, max)
min := max == high ? low : min
idx := max == high ? i : idx
else
for i = 1 to (n - loc)-1
if (high - low) < ob_threshold * 2
min := math.min(low, min)
max := min == low ? high : max
idx := min == low ? 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)

//Set order blocks
display_ob(boxes, target_top, target_btm, target_left, target_type, show_last, swing, size)=>
for i = 0 to math.min(show_last-1, size-1)
get_box = array.get(boxes, i)

box.set_lefttop(get_box, array.get(target_left, i), array.get(target_top, i))
box.set_rightbottom(get_box, array.get(target_left, i), array.get(target_btm, i))
box.set_extend(get_box, extend.right)

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)

//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 = line.new(na,na,na,na
, xloc = xloc.bar_time
, color = css
, style = get_line_style(pdhl_style))

var label high_lbl = label.new(na,na
, xloc = xloc.bar_time
, text = str.format('{0}H', tf)
, color = TRANSP_CSS
, textcolor = css
, size = size.small
, style = label.style_label_left)

var line low_line = line.new(na,na,na,na
, xloc = xloc.bar_time
, color = css
, style = get_line_style(pdhl_style))

var label low_lbl = label.new(na,na
, xloc = xloc.bar_time
, text = str.format('{0}L', tf)
, color = TRANSP_CSS
, textcolor = css
, size = size.small
, style = label.style_label_left)

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)

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'
? size.tiny
: internal_structure_size == 'Small'
? size.small
: size.normal

var swing_structure_lbl_size = swing_structure_size == 'Tiny'
? size.tiny
: swing_structure_size == 'Small'
? size.small
: size.normal

var eqhl_lbl_size = eq_size == 'Tiny'
? size.tiny
: eq_size == 'Small'
? size.small
: size.normal

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

[itop, ibtm] = swings(5)

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

var label extend_top_lbl = label.new(na, na
, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = size.tiny)

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])

//Extend recent top to last bar
line.delete(extend_top[1])
extend_top := line.new(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 := math.max(high, trail_up)
trail_up_x := trail_up == high ? n : trail_up_x

//Set top extension label/line
if barstate.islast 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' : 'Strong High')

//-----------------------------------------------------------------------------}
//Pivot Low
//-----------------------------------------------------------------------------{
var line extend_btm = na

var label extend_btm_lbl = label.new(na, na
, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = size.tiny)

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])

//Extend recent btm to last bar
line.delete(extend_btm[1])
extend_btm := line.new(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 := math.min(low, trail_dn)
trail_dn_x := trail_dn == low ? n : trail_dn_x

//Set btm extension label/line
if barstate.islast 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' : 'Strong 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 - math.max(close, open) > math.min(close, open - low)

//Detect internal bullish Structure
if ta.crossover(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 ? 'CHoCH' : 'BOS'

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

//Internal Order Block
if show_iob
ob_coord(false, itop_x, iob_top, iob_btm, iob_left, iob_type)

//Detect bullish Structure
if ta.crossover(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 ? '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 ifilter_confluence
bear_concordant := high - math.max(close, open) < math.min(close, open - low)

//Detect internal bearish Structure
if ta.crossunder(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 ? 'CHoCH' : 'BOS'

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 ta.crossunder(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 ? '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)

//Delete internal order blocks box coordinates if top/bottom is broken
for element in iob_type
index = array.indexof(iob_type, element)

if close < array.get(iob_btm, index) and element == 1
array.remove(iob_top, index)
array.remove(iob_btm, index)
array.remove(iob_left, index)
array.remove(iob_type, index)
bull_iob_break := true

else if close > array.get(iob_top, index) and element == -1
array.remove(iob_top, index)
array.remove(iob_btm, index)
array.remove(iob_left, index)
array.remove(iob_type, index)
bear_iob_break := true

//Delete internal order blocks box coordinates if top/bottom is broken
for element in ob_type
index = array.indexof(ob_type, element)

if close < array.get(ob_btm, index) and element == 1
array.remove(ob_top, index)
array.remove(ob_btm, index)
array.remove(ob_left, index)
array.remove(ob_type, index)
bull_ob_break := true

else if close > array.get(ob_top, index) and element == -1
array.remove(ob_top, index)
array.remove(ob_btm, index)
array.remove(ob_left, index)
array.remove(ob_type, index)
bear_ob_break := true

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)

if max < min + atr * eq_threshold
eqh_line = line.new(eq_top_x, eq_prev_top, n-eq_len, eq_top
, color = bear_css
, style = line.style_dotted)

eqh_lbl = label.new(int(math.avg(n-eq_len, eq_top_x)), eq_top, 'EQH'
, color = #00000000
, textcolor = bear_css
, style = label.style_label_down
, size = eqhl_lbl_size)

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 eq_btm
max = math.max(eq_btm, eq_prev_btm)
min = math.min(eq_btm, eq_prev_btm)

if min > max - atr * eq_threshold
eql_line = line.new(eq_btm_x, eq_prev_btm, n-eq_len, eq_btm
, color = bull_css
, style = line.style_dotted)

eql_lbl = label.new(int(math.avg(n-eq_len, eq_btm_x)), eq_btm, 'EQL'
, color = #00000000
, textcolor = bull_css
, style = label.style_label_up
, size = eqhl_lbl_size)

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)

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] =
request.security(syminfo.tickerid, fvg_tf, get_ohlc())

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

change_tf = timeframe.change(fvg_tf)

threshold = fvg_auto ? ta.cum(math.abs(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
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))

array.unshift(bullish_fvg_min, box.new(n-1, math.avg(src_l, src_h2), n + fvg_extend, src_h2
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css))

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

array.unshift(bearish_fvg_min, box.new(n-1, math.avg(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)
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, 80)
, border_color = na)

var premium_lbl = label.new(na, na
, text = 'Premium'
, color = TRANSP_CSS
, textcolor = premium_css
, style = label.style_label_down
, size = size.small)

var eq = box.new(na, na, na, na
, bgcolor = color.rgb(120, 123, 134, 80)
, border_color = na)

var eq_lbl = label.new(na, na
, text = 'Equilibrium'
, color = TRANSP_CSS
, textcolor = eq_css
, style = label.style_label_left
, size = size.small)

var discount = box.new(na, na, na, na
, bgcolor = color.new(discount_css, 80)
, border_color = na)

var discount_lbl = label.new(na, na
, text = 'Discount'
, color = TRANSP_CSS
, textcolor = discount_css
, style = label.style_label_up
, size = size.small)

//Show Premium/Discount Areas
if barstate.islast and show_sd
avg = math.avg(trail_up, trail_dn)

box.set_lefttop(premium, math.max(top_x, btm_x), trail_up)
box.set_rightbottom(premium, n, .95 * trail_up + .05 * trail_dn)

label.set_xy(premium_lbl, int(math.avg(math.max(top_x, btm_x), n)), trail_up)

box.set_lefttop(eq, math.max(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, math.max(top_x, btm_x), .95 * trail_dn + .05 * trail_up)
box.set_rightbottom(discount, n, trail_dn)
label.set_xy(discount_lbl, int(math.avg(math.max(top_x, btm_x), n)), trail_dn)

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

plotcandle(open, high, low, close
, color = trend_css
, wickcolor = trend_css
, bordercolor = trend_css
, editable = false)

//-----------------------------------------------------------------------------}
//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')

alertcondition(bear_ibos_alert, 'Internal Bearish BOS', 'Internal Bearish BOS formed')
alertcondition(bear_ichoch_alert, 'Internal Bearish CHoCH', 'Internal Bearish CHoCH formed')

//Swing Structure
alertcondition(bull_bos_alert, 'Bullish BOS', 'Internal Bullish BOS formed')
alertcondition(bull_choch_alert, 'Bullish CHoCH', 'Internal Bullish CHoCH formed')

alertcondition(bear_bos_alert, 'Bearish BOS', 'Bearish BOS formed')
alertcondition(bear_choch_alert, 'Bearish CHoCH', 'Bearish 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')

alertcondition(bull_ob_break, 'Bullish Swing OB Breakout', 'Price broke bullish swing OB')
alertcondition(bear_ob_break, 'Bearish Swing OB Breakout', 'Price broke bearish swing 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')

//-----------------------------------------------------------------------------}
// period = str.tonumber(timeframe.period)
// dailyHigh = request.security(syminfo.tickerid, "1D", ta.highest(dailyHighAndLowLength))
// dailyLow = request.security(syminfo.tickerid, "1D", ta.lowest(dailyHighAndLowLength))
// var line dh_line = na
// var line dl_line = na

// line.delete(dh_line[1])
// line.delete(dl_line[1])

// dh_line := line.new(bar_index, dailyHigh, bar_index + 20, dailyHigh, color = color.purple, style = line.style_dashed, width = 2)
// dl_line := line.new(bar_index, dailyLow, bar_index + 20, dailyLow, color = color.purple, style = line.style_dashed, width = 2)


// line.set_x1(dh_line, bar_index)
// line.set_x2(dh_line, bar_index + 20)
// line.set_y1(dh_line, dailyHigh)
// line.set_y2(dh_line, dailyHigh)


// line.set_x1(dl_line, bar_index)
// line.set_x2(dl_line, bar_index + 20)
// line.set_y1(dl_line, dailyLow)
// line.set_y2(dl_line, dailyLow)
// plot(dailyHigh, color = color.purple)
// plot(dailyLow, color = color.purple)
// var line _line1 = na
// // var line2 = line.new(bar_index - 20, ta.lowest(int(1440 / period)), bar_index + 20, ta.lowest(int(1440 / period)))
// // line.delete(line1)

// // var line1 = line.new(bar_index,0,0,0)
// // var line2 = line.new()

// line.set_x1(_line1, bar_index)
// line.set_x2(_line1, bar_index + 20)
// line.set_y1(_line1, ta.highest(int(1440 / period)))
// line.set_y2(_line1, ta.highest(int(1440 / period)))


// line.set_xloc(line1, time, time + 60 * 60 * 24, xloc.bar_time)
// line.set_color(line2, color.green)
// line.set_width(line2, 5)

// var line1 = line.new(bar_index - 20, ta.highest(int(1440 / period)), bar_index + 20, ta.highest(int(1440 / period)))
// var line2 = line.new(bar_index - 20, ta.lowest(int(1440 / period)), bar_index + 20, ta.lowest(int(1440 / period)))

// line.set_x1(line1, bar_index - 20)


// dailyHigh = request.security(syminfo.tickerid, "1D", ta.highest(1))
// dailyLow = request.security(syminfo.tickerid, "1D", ta.lowest(1))

// plot(dailyHigh, color = color.purple)
// plot(dailyLow, color = color.purple)

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.