Smart money concepts [LuxAlgo]
Forums › ProRealTime English forum › ProBuilder support › Smart money concepts [LuxAlgo]
- This topic has 12 replies, 6 voices, and was last updated 3 weeks ago by Fr7.
-
-
10/07/2023 at 12:40 PM #222137
Hi !
Is it possible to convert this indicator into PRT code, this smart money indicator is free on TradingView and it is most advanced and complete out there.
Here is a link to the TradingView version of this with descriptions etc.
https://www.tradingview.com/script/CnB3fSph-Smart-Money-Concepts-LuxAlgo/
Thanks in advance 🙂
Here is the code.
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo//@version=5
indicator(“Smart Money Concepts [LuxAlgo]”, “Smart Money Concepts [LuxAlgo]”
, 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 = ‘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)show_trend = input(false, ‘Color Candles’
, group = ‘Smart Money Concepts’
, tooltip = COLOR_CANDLES_TOOLTIP)//—————————————-}
//Internal Structure
//—————————————-{
show_internals = input(true, ‘Show Internal Structure’
, group = ‘Real Time Internal Structure’
, tooltip = SHOW_INTERNAL)show_ibull = input.string(‘All’, ‘Bullish Structure’
, options = [‘All’, ‘BOS’, ‘CHoCH’]
, inline = ‘ibull’
, group = ‘Real Time Internal Structure’)swing_ibull_css = input(#089981, ”
, inline = ‘ibull’
, group = ‘Real Time Internal Structure’)//Bear Structure
show_ibear = input.string(‘All’, ‘Bearish Structure’
, options = [‘All’, ‘BOS’, ‘CHoCH’]
, inline = ‘ibear’
, group = ‘Real Time Internal Structure’)swing_ibear_css = input(#f23645, ”
, inline = ‘ibear’
, group = ‘Real Time Internal Structure’)ifilter_confluence = input(false, ‘Confluence Filter’
, group = ‘Real Time Internal Structure’
, tooltip = CONFLUENCE_FILTER)internal_structure_size = input.string(‘Tiny’, ‘Internal Label Size’
, options = [‘Tiny’, ‘Small’, ‘Normal’]
, group = ‘Real Time Internal Structure’)//—————————————-}
//Swing Structure
//—————————————-{
show_Structure = input(true, ‘Show Swing Structure’
, group = ‘Real Time Swing Structure’
, tooltip = SHOW_SWING)//Bull Structure
show_bull = input.string(‘All’, ‘Bullish Structure’
, options = [‘All’, ‘BOS’, ‘CHoCH’]
, inline = ‘bull’
, group = ‘Real Time Swing Structure’)swing_bull_css = input(#089981, ”
, inline = ‘bull’
, group = ‘Real Time Swing Structure’)//Bear Structure
show_bear = input.string(‘All’, ‘Bearish Structure’
, options = [‘All’, ‘BOS’, ‘CHoCH’]
, inline = ‘bear’
, group = ‘Real Time Swing Structure’)swing_bear_css = input(#f23645, ”
, inline = ‘bear’
, group = ‘Real Time Swing Structure’)swing_structure_size = input.string(‘Small’, ‘Swing Label Size’
, options = [‘Tiny’, ‘Small’, ‘Normal’]
, group = ‘Real Time Swing Structure’)//Swings
show_swings = input(false, ‘Show Swings Points’
, inline = ‘swings’
, group = ‘Real Time Swing Structure’
, tooltip = SHOW_SWING_POINTS)length = input.int(50, ”
, minval = 10
, inline = ‘swings’
, group = ‘Real Time Swing Structure’)show_hl_swings = input(true, ‘Show Strong/Weak High/Low’
, group = ‘Real Time Swing Structure’
, tooltip = SHOW_SWHL_POINTS)//—————————————-}
//Order Blocks
//—————————————-{
show_iob = input(true, ‘Internal Order Blocks’
, inline = ‘iob’
, group = ‘Order Blocks’
, tooltip = INTERNAL_OB)iob_showlast = input.int(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 = input.int(5, ”
, minval = 1
, inline = ‘ob’
, group = ‘Order Blocks’)ob_filter = input.string(‘Atr’, ‘Order Block Filter’
, options = [‘Atr’, ‘Cumulative Mean Range’]
, group = ‘Order Blocks’
, tooltip = FILTER_OB)ibull_ob_css = input.color(color.new(#3179f5, 80), ‘Internal Bullish OB’
, group = ‘Order Blocks’)ibear_ob_css = input.color(color.new(#f77c80, 80), ‘Internal Bearish OB’
, group = ‘Order Blocks’)bull_ob_css = input.color(color.new(#1848cc, 80), ‘Bullish OB’
, group = ‘Order Blocks’)bear_ob_css = input.color(color.new(#b22833, 80), ‘Bearish OB’
, group = ‘Order Blocks’)//—————————————-}
//EQH/EQL
//—————————————-{
show_eq = input(true, ‘Equal High/Low’
, group = ‘EQH/EQL’
, tooltip = SHOW_EQHL)eq_len = input.int(3, ‘Bars Confirmation’
, minval = 1
, group = ‘EQH/EQL’
, tooltip = EQHL_BARS)eq_threshold = input.float(0.1, ‘Threshold’
, minval = 0
, maxval = 0.5
, step = 0.1
, group = ‘EQH/EQL’
, tooltip = EQHL_THRESHOLD)eq_size = input.string(‘Tiny’, ‘Label Size’
, options = [‘Tiny’, ‘Small’, ‘Normal’]
, group = ‘EQH/EQL’)//—————————————-}
//Fair Value Gaps
//—————————————-{
show_fvg = input(false, ‘Fair Value Gaps’
, group = ‘Fair Value Gaps’
, tooltip = SHOW_FVG)fvg_auto = input(true, “Auto Threshold”
, group = ‘Fair Value Gaps’
, tooltip = AUTO_FVG)fvg_tf = input.timeframe(”, “Timeframe”
, group = ‘Fair Value Gaps’
, tooltip = FVG_TF)bull_fvg_css = input.color(color.new(#00ff68, 70), ‘Bullish FVG’
, group = ‘Fair Value Gaps’)bear_fvg_css = input.color(color.new(#ff0008, 70), ‘Bearish FVG’
, group = ‘Fair Value Gaps’)fvg_extend = input.int(1, “Extend FVG”
, minval = 0
, group = ‘Fair Value Gaps’
, tooltip = EXTEND_FVG)//—————————————-}
//Previous day/week high/low
//—————————————-{
//Daily
show_pdhl = input(false, ‘Daily’
, inline = ‘daily’
, group = ‘Highs & Lows MTF’)pdhl_style = input.string(‘⎯⎯⎯’, ”
, 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 = input.string(‘⎯⎯⎯’, ”
, 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 = input.string(‘⎯⎯⎯’, ”
, 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 = input.color(#f23645, ‘Premium Zone’
, group = ‘Premium & Discount Zones’)eq_css = input.color(#b2b5be, ‘Equilibrium Zone’
, group = ‘Premium & Discount Zones’)discount_css = input.color(#089981, ‘Discount Zone’
, group = ‘Premium & Discount Zones’)//—————————————————————————–}
//Functions
//—————————————————————————–{
n = bar_indexatr = 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 = 0upper = 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 = 1ob_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[i] – low[i]) < ob_threshold[i] * 2
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
else
for i = 1 to (n – loc)-1
if (high[i] – low[i]) < ob_threshold[i] * 2
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idxarray.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_cssbox.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(‘P{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(‘P{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 = 0var top_y = 0., var top_x = 0
var btm_y = 0., var btm_x = 0var itop_y = 0., var itop_x = 0
var ibtm_y = 0., var ibtm_x = 0var trail_up = high, var trail_dn = low
var trail_up_x = 0, var trail_dn_x = 0var top_cross = true, var btm_cross = true
var itop_cross = true, var ibtm_cross = truevar txt_top = ”, var txt_btm = ”
//Alerts
bull_choch_alert = false
bull_bos_alert = falsebear_choch_alert = false
bear_bos_alert = falsebull_ichoch_alert = false
bull_ibos_alert = falsebear_ichoch_alert = false
bear_ibos_alert = falsebull_iob_break = false
bear_iob_break = falsebull_ob_break = false
bear_ob_break = falseeqh_alert = false
eql_alert = false//Structure colors
var bull_css = style == ‘Monochrome’ ? #b2b5be
: swing_bull_cssvar bear_css = style == ‘Monochrome’ ? #b2b5be
: swing_bear_cssvar ibull_css = style == ‘Monochrome’ ? #b2b5be
: swing_ibull_cssvar 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.normalvar swing_structure_lbl_size = swing_structure_size == ‘Tiny’
? size.tiny
: swing_structure_size == ‘Small’
? size.small
: size.normalvar 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 = navar 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 – lengthtrail_up := top
trail_up_x := n – lengthif itop
itop_cross := trueitop_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’ : ‘Weak High’)//—————————————————————————–}
//Pivot Low
//—————————————————————————–{
var line extend_btm = navar 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-lengthtrail_dn := btm
trail_dn_x := n-lengthif ibtm
ibtm_cross := trueibtm_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’ : ‘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 = trueif 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 = naif itrend < 0
choch := true
bull_ichoch_alert := true
else
bull_ibos_alert := truetxt = 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 = naif trend < 0
choch := true
bull_choch_alert := true
else
bull_bos_alert := truetxt = 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 = trueif 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 = falseif itrend > 0
choch := true
bear_ichoch_alert := true
else
bear_ibos_alert := truetxt = 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 = naif trend > 0
choch := true
bear_choch_alert := true
else
bear_bos_alert := truetxt = 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 := trueelse 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 := trueelse 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 := trueiob_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 = 0var eq_prev_btm = 0.
var eq_btm_x = 0if 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_lenif 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 = nabullish_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 * 100change_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_tfbearish_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 = naif show_trend
if style == ‘Colored’
trend_css := itrend == 1 ? bull_css : bear_css
else if style == ‘Monochrome’
trend_css := itrend == 1 ? #b2b5be : #5d606bplotcandle(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’)//—————————————————————————–}
07/29/2024 at 3:18 PM #235900Hi,
Here you have the code:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470//--------------------------------------------------------------------------------////PRC_Smart Money Concepts//version = 0//29.07.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------------------------------------////-----Inputs---------------------------------------------------------------------//length=50n=barindexshowswings=1showHLswings=1showinternals=1showibull=1//1=all 2=bos 3=CHoCHshowibear=1//1=all 2=bos 3=CHoCHshowStructure=1showbull=1//1=all 2=bos 3=CHoCHshowbear=1//1=all 2=bos 3=CHoCHshowOB=1showiOB=1showlastOB=5ifilterConfluence=0obFilter=1 //1=ATR 0=Cumulative mean Range//--------------------------------------------------------------------------------////--------------------------------------------------------------------------------//atr=averagetruerange[200](close)cmeanrange=summation[max(1,n)](high-low)/n//--------------------------------------------------------------------------------////-----Swings---------------------------------------------------------------------////---Swing lengthos=0upper=highest[length](high)lower=lowest[length](low)if high[length]>upper thenos=0elsif low[length]<lower thenos=1elseos=os[1]endifif os=0 and os[1]<>0 thenmytop=high[length]elsemytop=0endifif os=1 and os[1]<>1 thenmybot=low[length]elsemybot=0endif//---Swing 5os1=0upper1=highest[5](high)lower1=lowest[5](low)if high[5]>upper1 thenos1=0elsif low[5]<lower1 thenos1=1elseos1=os1[1]endifif os1=0 and os1[1]<>0 thenitop=high[5]elseitop=0endifif os1=1 and os1[1]<>1 thenibot=low[5]elseibot=0endif//--------------------------------------------------------------------------------////-----Pivot High-----------------------------------------------------------------//if mytop thentopcross=1if showswings thenif mytop>topy thendrawtext("HH",n-length,mytop+atr*0.5)coloured("red")elsedrawtext("LH",n-length,mytop+atr*0.5)coloured("red")endifendiftopy=mytoptopx=n-lengthtrailup=mytoptrailupx=n-lengthendifif itop thenitopcross=1itopy=itopitopx=n-5endif//Trailing maximuntrailup=max(high,trailup)if trailup=high thentrailupx=nelsetrailupx=trailupxendif//--------------------------------------------------------------------------------////-----Pivot Low------------------------------------------------------------------//if mybot thenbotcross=1if showswings thenif mybot<boty thendrawtext("LL",n-length,mybot-atr*0.5)coloured("green")elsedrawtext("HL",n-length,mybot-atr*0.5)coloured("green")endifendifboty=mybotbotx=n-lengthtraildn=mybottraildnx=n-lengthendifif ibot thenibotcross=1iboty=ibotibotx=n-5endif//Trailing maximuntraildn=min(low,traildn)if traildn=low thentraildnx=nelsetraildnx=traildnxendif//--------------------------------------------------------------------------------////-----Pivot High BOS/CHoCH-------------------------------------------------------//bullConcordant=1if ifilterConfluence thenbullConcordant=high-max(close,open)>min(close,open-low)endif//Detect internal bullish structureif close crosses over itopy and itopcross and topy<>itopy and bullConcordant thenchoch=undefinedif itrend<0 thenchoch=1bullichochalert=1elsebullibosalert=1endifif showinternals thenif showibull=1 or (showibull=2 and not choch) or (showibull=3 and choch) thendrawsegment(itopx,itopy,barindex,itopy)style(dottedline)coloured("green")if choch thendrawtext("CHoCH",(itopx+barindex)/2,itopy+0.25*atr)coloured("green")elsedrawtext("BOS",(itopx+barindex)/2,itopy+0.25*atr)coloured("green")endifendifendifitopcross=0itrend=1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-itopx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=1t=t+1endifendif//Detect bullish Structureif close crosses over topy and topcross thenchoch=undefinedif trend<0 thenchoch=1bullchochalert=1elsebulbosalert=1endifif showStructure thenif showbull=1 or (showbull=2 and not choch) or (showbull=3 and choch) thendrawsegment(topx,topy,barindex,topy)style(line)coloured("green")if choch thendrawtext("CHoCH",(topx+barindex)/2,topy+0.25*atr)coloured("green")elsedrawtext("BOS",(topx+barindex)/2,topy+0.25*atr)coloured("green")endifendifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-topx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=1r=r+1endiftopcross=0trend=1endif//--------------------------------------------------------------------------------////-----Pivot Low BOS/CHoCH--------------------------------------------------------//bearConcordant=1if ifilterConfluence thenbearConcordant=high-max(close,open)<min(close,open-low)endif//Detect internal bearish Structureif close crosses under iboty and ibotcross and boty<>iboty and bearConcordant thenchoch=0if itrend>0 thenchoch=1bearichochalert=1elsebearichochalert=1endifif showinternals thenif showibear=1 or (showibear=2 and not choch) or (showibear=3 and choch) thendrawsegment(ibotx,iboty,barindex,iboty)style(dottedline)coloured("red")if choch thendrawtext("CHoCH",(ibotx+barindex)/2,iboty-0.25*atr)coloured("red")elsedrawtext("BOS",(ibotx+barindex)/2,iboty-0.25*atr)coloured("red")endifendifendifibotcross=0itrend=-1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-ibotx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=-1t=t+1endifendif//Detect Bullish Strcutureif close crosses under boty and botcross thenchoch=undefinedif trend>0 thenchoch=1bearchochalert=1elsebearbosalert=1endifif showStructure thenif showbear=1 or (showbear=2 and not choch) or (showbear=3 and choch) thendrawsegment(botx,boty,n,boty)style(line)coloured("red")if choch thendrawtext("CHoCH",(botx+n)/2,boty+0.25*atr)coloured("red")elsedrawtext("BOS",(botx+n)/2,boty+0.25*atr)coloured("red")endifendifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-botx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=-1r=r+1endifbotcross=0trend=-1endif//--------------------------------------------------------------------------------////-----Order Blocks---------------------------------------------------------------////---Delete internal Order Blocksfor j=t downto 0 doif close < $itargetBot[j] and $itargetType[j]=1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=undefinedelsif close > $itargetTop[j] and $itargetType[j]=-1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=0endifnext//---Delete structural Order Blocksfor j=r downto 0 doif close < $targetBot[j] and $targetType[j]=1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=undefinedelsif close > $targetTop[j] and $targetType[j]=-1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=0endifnext//---Plot Order Blocks if not brokencountiOB=0countOB=0if islastbarupdate then//---Internal Order Blocksfor i=t downto 0 doif $itargetBot[i]=0 thencountiOB=countiOBelsecountiOB=countiOB+1if countiOB = showlastOB thenbreakelseif close > $itargetTop[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("green",0)fillcolor("green",50)elsif close <$itargetBot[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("red",0)fillcolor("red",50)elsedrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("yellow",0)fillcolor("yellow",50)endifendifendifnext//---Structural Order Blocksfor i=r downto 0 doif $targetBot[i]=0 thencountOB=countOBelsecountOB=countOB+1if countOB = showlastOB thenbreakelseif close > $targetTop[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("green",0)fillcolor("green",100)elsif close <$targetBot[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("red",0)fillcolor("red",100)elsedrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("yellow",0)fillcolor("yellow",100)endifendifendifnextendif//--------------------------------------------------------------------------------////-----Top and Bottom extension---------------------------------------------------//if islastbarupdate and showhlswings thendrawsegment(traildnx,traildn,n+20,traildn)coloured("blue")drawsegment(trailupx,trailup,n+20,trailup)coloured("red")if trend>0 thendrawtext("Strong Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Weak High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")elsedrawtext("Weak Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Strong High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")endifendif//--------------------------------------------------------------------------------//return1 user thanked author for this post.
07/30/2024 at 6:30 AM #235907Good morning Iván Thank you for your great work!
The indicator does have errors when it runs for a while, the fonts for Weak High/Low + Strong High overlap. Some bars overlap and become darker. If the time setting is changed everything is fine again and after a few minutes it starts again from the beginning.
07/30/2024 at 8:45 AM #23591407/30/2024 at 9:34 AM #235915Or better if we work just with arrays. Now the code should work fine
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537defparam drawonlastbaronly=true//--------------------------------------------------------------------------------////PRC_Smart Money Concepts//version = 1//29.07.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------------------------------------////-----Inputs---------------------------------------------------------------------//length=50n=barindexshowswings=1showHLswings=1showinternals=1showibull=1//1=all 2=bos 3=CHoCHshowibear=1//1=all 2=bos 3=CHoCHshowStructure=1showbull=1//1=all 2=bos 3=CHoCHshowbear=1//1=all 2=bos 3=CHoCHshowOB=1showiOB=1showlastOB=5ifilterConfluence=0obFilter=1 //1=ATR 0=Cumulative mean Range//--------------------------------------------------------------------------------////--------------------------------------------------------------------------------//atr=averagetruerange[200](close)cmeanrange=summation[max(1,n)](high-low)/n//--------------------------------------------------------------------------------////-----Swings---------------------------------------------------------------------////---Swing lengthos=0upper=highest[length](high)lower=lowest[length](low)if high[length]>upper thenos=0elsif low[length]<lower thenos=1elseos=os[1]endifif os=0 and os[1]<>0 thenmytop=high[length]elsemytop=0endifif os=1 and os[1]<>1 thenmybot=low[length]elsemybot=0endif//---Swing 5os1=0upper1=highest[5](high)lower1=lowest[5](low)if high[5]>upper1 thenos1=0elsif low[5]<lower1 thenos1=1elseos1=os1[1]endifif os1=0 and os1[1]<>0 thenitop=high[5]elseitop=0endifif os1=1 and os1[1]<>1 thenibot=low[5]elseibot=0endif//--------------------------------------------------------------------------------////-----Pivot High-----------------------------------------------------------------//if mytop thentopcross=1if showswings thenif mytop>topy then$phy[z+1]=mytop$phx[z+1]=n-length$phtype[z+1]=1z=z+1else$phy[z+1]=mytop$phx[z+1]=n-length$phtype[z+1]=-1z=z+1endifendiftopy=mytoptopx=n-lengthtrailup=mytoptrailupx=n-lengthendifif itop thenitopcross=1itopy=itopitopx=n-5endif//Trailing maximuntrailup=max(high,trailup)if trailup=high thentrailupx=nelsetrailupx=trailupxendif//--------------------------------------------------------------------------------////-----Pivot Low------------------------------------------------------------------//if mybot thenbotcross=1if showswings thenif mybot<boty then$ply[k+1]=mybot$plx[k+1]=n-length$pltype[k+1]=1k=k+1else$ply[k+1]=mybot$plx[k+1]=n-length$pltype[k+1]=-1k=k+1endifendifboty=mybotbotx=n-lengthtraildn=mybottraildnx=n-lengthendifif ibot thenibotcross=1iboty=ibotibotx=n-5endif//Trailing maximuntraildn=min(low,traildn)if traildn=low thentraildnx=nelsetraildnx=traildnxendif//--------------------------------------------------------------------------------////-----Pivot High BOS/CHoCH-------------------------------------------------------//bullConcordant=1if ifilterConfluence thenbullConcordant=high-max(close,open)>min(close,open-low)endif//Detect internal bullish structureif close crosses over itopy and itopcross and topy<>itopy and bullConcordant thenchoch=undefinedif itrend<0 thenchoch=1bullichochalert=1elsebullibosalert=1endifif showinternals thenif showibull=1 or (showibull=2 and not choch) or (showibull=3 and choch) then$itopx[m+1]=itopx$itopy[m+1]=itopy$ichoch[m+1]=choch$iright[m+1]=barindexm=m+1endifendifitopcross=0itrend=1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-itopx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=1t=t+1endifendif//Detect bullish Structureif close crosses over topy and topcross thenchoch=undefinedif trend<0 thenchoch=1endifif showStructure thenif showbull=1 or (showbull=2 and not choch) or (showbull=3 and choch) then$topx[g+1]=topx$topy[g+1]=topy$topchoch[g+1]=choch$right[g+1]=barindexg=g+1endifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-topx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=1r=r+1endiftopcross=0trend=1endif//--------------------------------------------------------------------------------////-----Pivot Low BOS/CHoCH--------------------------------------------------------//bearConcordant=1if ifilterConfluence thenbearConcordant=high-max(close,open)<min(close,open-low)endif//Detect internal bearish Structureif close crosses under iboty and ibotcross and boty<>iboty and bearConcordant thenchoch=0if itrend>0 thenchoch=1bearichochalert=1elsebearichochalert=1endifif showinternals thenif showibear=1 or (showibear=2 and not choch) or (showibear=3 and choch) then$ibotx[s+1]=ibotx$iboty[s+1]=iboty$ibotchoch[s+1]=choch$ibotright[s+1]=barindexs=s+1endifendifibotcross=0itrend=-1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-ibotx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=-1t=t+1endifendif//Detect Bullish Strcutureif close crosses under boty and botcross thenchoch=undefinedif trend>0 thenchoch=1bearchochalert=1elsebearbosalert=1endifif showStructure thenif showbear=1 or (showbear=2 and not choch) or (showbear=3 and choch) then$botx[w+1]=botx$boty[w+1]=boty$botchoch[w+1]=choch$botright[w+1]=barindexw=w+1endifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-botx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=-1r=r+1endifbotcross=0trend=-1endif//--------------------------------------------------------------------------------////-----Order Blocks---------------------------------------------------------------////--------------------------------------------------------------------------------////Delete internal Order Blocksfor j=t downto 0 doif close < $itargetBot[j] and $itargetType[j]=1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=undefinedelsif close > $itargetTop[j] and $itargetType[j]=-1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=0endifnext//Delete structural Order Blocksfor j=r downto 0 doif close < $targetBot[j] and $targetType[j]=1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=undefinedelsif close > $targetTop[j] and $targetType[j]=-1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=0endifnext//Plot Order Blocks if not brokencountiOB=0countOB=0if islastbarupdate then//---Internal Order Blocksfor i=t downto 0 doif $itargetBot[i]=0 thencountiOB=countiOBelsecountiOB=countiOB+1if countiOB = showlastOB thenbreakelseif close > $itargetTop[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("green",0)fillcolor("green",50)elsif close <$itargetBot[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("red",0)fillcolor("red",50)elsedrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("yellow",0)fillcolor("yellow",50)endifendifendifnext//---Structural Order Blocksfor i=r downto 0 doif $targetBot[i]=0 thencountOB=countOBelsecountOB=countOB+1if countOB = showlastOB thenbreakelseif close > $targetTop[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("green",0)fillcolor("green",100)elsif close <$targetBot[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("red",0)fillcolor("red",100)elsedrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("yellow",0)fillcolor("yellow",100)PRC_Smart Money Concepts(1)endifendifendifnext//-----------------------------------------------------------------------------////------Draw Pivot Points------------------------------------------------------////-----------------------------------------------------------------------------////---Pivot Highfor i=z downto 0 doif $phtype[i]=1 thendrawtext("HH",$phx[i],$phy[i]+atr*0.5)coloured("red")elsedrawtext("LH",$phx[i],$phy[i]+atr*0.5)coloured("red")endifnext//---Pivot Lowfor i=k downto 0 doif $pltype[i]=1 thendrawtext("LL",$plx[i],$ply[i]-atr*0.5)coloured("green")elsedrawtext("HL",$plx[i],$ply[i]-atr*0.5)coloured("green")endifnext//-----------------------------------------------------------------------------////------Draw Internal Structure------------------------------------------------////-----------------------------------------------------------------------------//for i=m downto 0 dodrawsegment($itopx[i],$itopy[i],$iright[i],$itopy[i])style(dottedline)coloured("green")if $ichoch[i]=1 thendrawtext("CHoCH",($itopx[i]+$iright[i])/2,$itopy[i]+0.25*atr)coloured("green")elsedrawtext("BOS",($itopx[i]+$iright[i])/2,$itopy[i]+0.25*atr)coloured("green")endifnext//-----------------------------------------------------------------------------//for i=s downto 0 dodrawsegment($ibotx[i],$iboty[i],$ibotright[i],$iboty[i])style(dottedline)coloured("red")if $ibotchoch[i]=1 thendrawtext("CHoCH",($ibotx[i]+$ibotright[i])/2,$iboty[i]-0.25*atr)coloured("red")elsedrawtext("BOS",($ibotx[i]+$ibotright[i])/2,$iboty[i]-0.25*atr)coloured("red")endifnext//-----------------------------------------------------------------------------////------Draw Structure---------------------------------------------------------////-----------------------------------------------------------------------------//for i=g downto 0 dodrawsegment($topx[i],$topy[i],$right[i],$topy[i])style(line)coloured("green")if $topchoch[i]=1 thendrawtext("CHoCH",($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured("green")elsedrawtext("BOS",($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured("green")endifnext//-----------------------------------------------------------------------------//for i=w downto 0 dodrawsegment($botx[i],$boty[i],$botright[i],$boty[i])style(line)coloured("red")if $botchoch[i]=1 thendrawtext("CHoCH",($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured("red")elsedrawtext("BOS",($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured("red")endifnext//-----------------------------------------------------------------------------////-----Top and Bottom extension------------------------------------------------////-----------------------------------------------------------------------------//if showhlswings thendrawsegment(traildnx,traildn,n+20,traildn)coloured("blue")drawsegment(trailupx,trailup,n+20,trailup)coloured("red")if trend>0 thendrawtext("Strong Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Weak High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")elsedrawtext("Weak Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Strong High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")endifendifendif//--------------------------------------------------------------------------------//return2 users thanked author for this post.
07/30/2024 at 10:19 AM #235922Hi guys and thanks for this interesting indicator.
There is an error line 457 I cannot correct:
drawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured(“yellow”,0)fillcolor(“yellow”,100)PRC_Smart Money Concepts(1)
I assume PRC_Smart Money Concepts(1) is a missed copy/paste, right ?
07/30/2024 at 10:45 AM #235923hi! yes, I don’t know why…
sorry
Attached you will find the itf file.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537defparam drawonlastbaronly=true//--------------------------------------------------------------------------------////PRC_Smart Money Concepts//version = 1//29.07.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------------------------------------////-----Inputs---------------------------------------------------------------------//length=50n=barindexshowswings=1showHLswings=1showinternals=1showibull=1//1=all 2=bos 3=CHoCHshowibear=1//1=all 2=bos 3=CHoCHshowStructure=1showbull=1//1=all 2=bos 3=CHoCHshowbear=1//1=all 2=bos 3=CHoCHshowOB=1showiOB=1showlastOB=5ifilterConfluence=0obFilter=1 //1=ATR 0=Cumulative mean Range//--------------------------------------------------------------------------------////--------------------------------------------------------------------------------//atr=averagetruerange[200](close)cmeanrange=summation[max(1,n)](high-low)/n//--------------------------------------------------------------------------------////-----Swings---------------------------------------------------------------------////---Swing lengthos=0upper=highest[length](high)lower=lowest[length](low)if high[length]>upper thenos=0elsif low[length]<lower thenos=1elseos=os[1]endifif os=0 and os[1]<>0 thenmytop=high[length]elsemytop=0endifif os=1 and os[1]<>1 thenmybot=low[length]elsemybot=0endif//---Swing 5os1=0upper1=highest[5](high)lower1=lowest[5](low)if high[5]>upper1 thenos1=0elsif low[5]<lower1 thenos1=1elseos1=os1[1]endifif os1=0 and os1[1]<>0 thenitop=high[5]elseitop=0endifif os1=1 and os1[1]<>1 thenibot=low[5]elseibot=0endif//--------------------------------------------------------------------------------////-----Pivot High-----------------------------------------------------------------//if mytop thentopcross=1if showswings thenif mytop>topy then$phy[z+1]=mytop$phx[z+1]=n-length$phtype[z+1]=1z=z+1else$phy[z+1]=mytop$phx[z+1]=n-length$phtype[z+1]=-1z=z+1endifendiftopy=mytoptopx=n-lengthtrailup=mytoptrailupx=n-lengthendifif itop thenitopcross=1itopy=itopitopx=n-5endif//Trailing maximuntrailup=max(high,trailup)if trailup=high thentrailupx=nelsetrailupx=trailupxendif//--------------------------------------------------------------------------------////-----Pivot Low------------------------------------------------------------------//if mybot thenbotcross=1if showswings thenif mybot<boty then$ply[k+1]=mybot$plx[k+1]=n-length$pltype[k+1]=1k=k+1else$ply[k+1]=mybot$plx[k+1]=n-length$pltype[k+1]=-1k=k+1endifendifboty=mybotbotx=n-lengthtraildn=mybottraildnx=n-lengthendifif ibot thenibotcross=1iboty=ibotibotx=n-5endif//Trailing maximuntraildn=min(low,traildn)if traildn=low thentraildnx=nelsetraildnx=traildnxendif//--------------------------------------------------------------------------------////-----Pivot High BOS/CHoCH-------------------------------------------------------//bullConcordant=1if ifilterConfluence thenbullConcordant=high-max(close,open)>min(close,open-low)endif//Detect internal bullish structureif close crosses over itopy and itopcross and topy<>itopy and bullConcordant thenchoch=undefinedif itrend<0 thenchoch=1bullichochalert=1elsebullibosalert=1endifif showinternals thenif showibull=1 or (showibull=2 and not choch) or (showibull=3 and choch) then$itopx[m+1]=itopx$itopy[m+1]=itopy$ichoch[m+1]=choch$iright[m+1]=barindexm=m+1endifendifitopcross=0itrend=1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-itopx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=1t=t+1endifendif//Detect bullish Structureif close crosses over topy and topcross thenchoch=undefinedif trend<0 thenchoch=1endifif showStructure thenif showbull=1 or (showbull=2 and not choch) or (showbull=3 and choch) then$topx[g+1]=topx$topy[g+1]=topy$topchoch[g+1]=choch$right[g+1]=barindexg=g+1endifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-topx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=1r=r+1endiftopcross=0trend=1endif//--------------------------------------------------------------------------------////-----Pivot Low BOS/CHoCH--------------------------------------------------------//bearConcordant=1if ifilterConfluence thenbearConcordant=high-max(close,open)<min(close,open-low)endif//Detect internal bearish Structureif close crosses under iboty and ibotcross and boty<>iboty and bearConcordant thenchoch=0if itrend>0 thenchoch=1bearichochalert=1elsebearichochalert=1endifif showinternals thenif showibear=1 or (showibear=2 and not choch) or (showibear=3 and choch) then$ibotx[s+1]=ibotx$iboty[s+1]=iboty$ibotchoch[s+1]=choch$ibotright[s+1]=barindexs=s+1endifendifibotcross=0itrend=-1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-ibotx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=-1t=t+1endifendif//Detect Bullish Strcutureif close crosses under boty and botcross thenchoch=undefinedif trend>0 thenchoch=1bearchochalert=1elsebearbosalert=1endifif showStructure thenif showbear=1 or (showbear=2 and not choch) or (showbear=3 and choch) then$botx[w+1]=botx$boty[w+1]=boty$botchoch[w+1]=choch$botright[w+1]=barindexw=w+1endifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-botx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=-1r=r+1endifbotcross=0trend=-1endif//--------------------------------------------------------------------------------////-----Order Blocks---------------------------------------------------------------////--------------------------------------------------------------------------------////Delete internal Order Blocksfor j=t downto 0 doif close < $itargetBot[j] and $itargetType[j]=1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=undefinedelsif close > $itargetTop[j] and $itargetType[j]=-1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=0endifnext//Delete structural Order Blocksfor j=r downto 0 doif close < $targetBot[j] and $targetType[j]=1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=undefinedelsif close > $targetTop[j] and $targetType[j]=-1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=0endifnext//Plot Order Blocks if not brokencountiOB=0countOB=0if islastbarupdate then//---Internal Order Blocksfor i=t downto 0 doif $itargetBot[i]=0 thencountiOB=countiOBelsecountiOB=countiOB+1if countiOB = showlastOB thenbreakelseif close > $itargetTop[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("green",0)fillcolor("green",50)elsif close <$itargetBot[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("red",0)fillcolor("red",50)elsedrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("yellow",0)fillcolor("yellow",50)endifendifendifnext//---Structural Order Blocksfor i=r downto 0 doif $targetBot[i]=0 thencountOB=countOBelsecountOB=countOB+1if countOB = showlastOB thenbreakelseif close > $targetTop[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("green",0)fillcolor("green",100)elsif close <$targetBot[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("red",0)fillcolor("red",100)elsedrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("yellow",0)fillcolor("yellow",100)endifendifendifnext//-----------------------------------------------------------------------------////------Draw Pivot Points------------------------------------------------------////-----------------------------------------------------------------------------////---Pivot Highfor i=z downto 0 doif $phtype[i]=1 thendrawtext("HH",$phx[i],$phy[i]+atr*0.5)coloured("red")elsedrawtext("LH",$phx[i],$phy[i]+atr*0.5)coloured("red")endifnext//---Pivot Lowfor i=k downto 0 doif $pltype[i]=1 thendrawtext("LL",$plx[i],$ply[i]-atr*0.5)coloured("green")elsedrawtext("HL",$plx[i],$ply[i]-atr*0.5)coloured("green")endifnext//-----------------------------------------------------------------------------////------Draw Internal Structure------------------------------------------------////-----------------------------------------------------------------------------//for i=m downto 0 dodrawsegment($itopx[i],$itopy[i],$iright[i],$itopy[i])style(dottedline)coloured("green")if $ichoch[i]=1 thendrawtext("CHoCH",($itopx[i]+$iright[i])/2,$itopy[i]+0.25*atr)coloured("green")elsedrawtext("BOS",($itopx[i]+$iright[i])/2,$itopy[i]+0.25*atr)coloured("green")endifnext//-----------------------------------------------------------------------------//for i=s downto 0 dodrawsegment($ibotx[i],$iboty[i],$ibotright[i],$iboty[i])style(dottedline)coloured("red")if $ibotchoch[i]=1 thendrawtext("CHoCH",($ibotx[i]+$ibotright[i])/2,$iboty[i]-0.25*atr)coloured("red")elsedrawtext("BOS",($ibotx[i]+$ibotright[i])/2,$iboty[i]-0.25*atr)coloured("red")endifnext//-----------------------------------------------------------------------------////------Draw Structure---------------------------------------------------------////-----------------------------------------------------------------------------//for i=g downto 0 dodrawsegment($topx[i],$topy[i],$right[i],$topy[i])style(line)coloured("green")if $topchoch[i]=1 thendrawtext("CHoCH",($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured("green")elsedrawtext("BOS",($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured("green")endifnext//-----------------------------------------------------------------------------//for i=w downto 0 dodrawsegment($botx[i],$boty[i],$botright[i],$boty[i])style(line)coloured("red")if $botchoch[i]=1 thendrawtext("CHoCH",($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured("red")elsedrawtext("BOS",($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured("red")endifnext//-----------------------------------------------------------------------------////-----Top and Bottom extension------------------------------------------------////-----------------------------------------------------------------------------//if showhlswings thendrawsegment(traildnx,traildn,n+20,traildn)coloured("blue")drawsegment(trailupx,trailup,n+20,trailup)coloured("red")if trend>0 thendrawtext("Strong Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Weak High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")elsedrawtext("Weak Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Strong High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")endifendifendif//--------------------------------------------------------------------------------//return1 user thanked author for this post.
07/30/2024 at 11:56 AM #235932Hi Ivan,
Thank you for this code.
Is it possible to put the FVG’s in as well?
Many thanks
Robert
2 users thanked author for this post.
07/30/2024 at 9:10 PM #235951Beginner’s luck or not, I am on demo and the NQ hit the H4 liquidity zone computed by the indicator 375 points winning trade.
08/01/2024 at 9:28 PM #23604808/02/2024 at 10:34 AM #236059Ok.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547defparam drawonlastbaronly=true//--------------------------------------------------------------------------------////PRC_Smart Money Concepts//version = 1//29.07.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------------------------------------////-----Inputs---------------------------------------------------------------------//length=50n=barindexshowswings=1showHLswings=1showinternals=1showibull=1//1=all 2=bos 3=CHoCHshowibear=1//1=all 2=bos 3=CHoCHshowStructure=1showbull=1//1=all 2=bos 3=CHoCHshowbear=1//1=all 2=bos 3=CHoCHshowOB=1showiOB=1showlastOB=5ifilterConfluence=0obFilter=1 //1=ATR 0=Cumulative mean Rangemult=2bblength=20//--------------------------------------------------------------------------------////--------------------------------------------------------------------------------//atr=averagetruerange[200](close)cmeanrange=summation[max(1,n)](high-low)/n//--------------------------------------------------------------------------------////-----Bollinger Bands Calculation------------------------------------------------//averageBB=average[bblength](close)dev=mult*std[bblength](close)upperBB=averageBB+devlowerBB=averageBB-dev//--------------------------------------------------------------------------------////-----Swings---------------------------------------------------------------------////---Swing lengthos=0upper=highest[length](high)lower=lowest[length](low)if high[length]>upper thenos=0elsif low[length]<lower thenos=1elseos=os[1]endifif os=0 and os[1]<>0 thenmytop=high[length]elsemytop=0endifif os=1 and os[1]<>1 thenmybot=low[length]elsemybot=0endif//---Swing 5os1=0upper1=highest[5](high)lower1=lowest[5](low)if high[5]>upper1 thenos1=0elsif low[5]<lower1 thenos1=1elseos1=os1[1]endifif os1=0 and os1[1]<>0 thenitop=high[5]elseitop=0endifif os1=1 and os1[1]<>1 thenibot=low[5]elseibot=0endif//--------------------------------------------------------------------------------////-----Pivot High-----------------------------------------------------------------//if mytop thentopcross=1if showswings thenif mytop>topy then$phy[z+1]=mytop$phx[z+1]=n-length$phtype[z+1]=1z=z+1else$phy[z+1]=mytop$phx[z+1]=n-length$phtype[z+1]=-1z=z+1endifendiftopy=mytoptopx=n-lengthtrailup=mytoptrailupx=n-lengthendifif itop thenitopcross=1itopy=itopitopx=n-5endif//Trailing maximuntrailup=max(high,trailup)if trailup=high thentrailupx=nelsetrailupx=trailupxendif//--------------------------------------------------------------------------------////-----Pivot Low------------------------------------------------------------------//if mybot thenbotcross=1if showswings thenif mybot<boty then$ply[k+1]=mybot$plx[k+1]=n-length$pltype[k+1]=1k=k+1else$ply[k+1]=mybot$plx[k+1]=n-length$pltype[k+1]=-1k=k+1endifendifboty=mybotbotx=n-lengthtraildn=mybottraildnx=n-lengthendifif ibot thenibotcross=1iboty=ibotibotx=n-5endif//Trailing maximuntraildn=min(low,traildn)if traildn=low thentraildnx=nelsetraildnx=traildnxendif//--------------------------------------------------------------------------------////-----Pivot High BOS/CHoCH-------------------------------------------------------//bullConcordant=1if ifilterConfluence thenbullConcordant=high-max(close,open)>min(close,open-low)endif//Detect internal bullish structureif close crosses over itopy and itopcross and topy<>itopy and bullConcordant thenchoch=undefinedif itrend<0 thenchoch=1bullichochalert=1elsebullibosalert=1endifif showinternals thenif showibull=1 or (showibull=2 and not choch) or (showibull=3 and choch) then$itopx[m+1]=itopx$itopy[m+1]=itopy$ichoch[m+1]=choch$iright[m+1]=barindexm=m+1endifendifitopcross=0itrend=1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-itopx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=1t=t+1endifendif//Detect bullish Structureif close crosses over topy and topcross thenchoch=undefinedif trend<0 thenchoch=1endifif showStructure thenif showbull=1 or (showbull=2 and not choch) or (showbull=3 and choch) then$topx[g+1]=topx$topy[g+1]=topy$topchoch[g+1]=choch$right[g+1]=barindexg=g+1endifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-topx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenminim=min(low[i],minim)if minim=low[i] thenmaxim=high[i]idx=ielsemaxim=maximidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=1r=r+1endiftopcross=0trend=1endif//--------------------------------------------------------------------------------////-----Pivot Low BOS/CHoCH--------------------------------------------------------//bearConcordant=1if ifilterConfluence thenbearConcordant=high-max(close,open)<min(close,open-low)endif//Detect internal bearish Structureif close crosses under iboty and ibotcross and boty<>iboty and bearConcordant thenchoch=0if itrend>0 thenchoch=1bearichochalert=1elsebearichochalert=1endifif showinternals thenif showibear=1 or (showibear=2 and not choch) or (showibear=3 and choch) then$ibotx[s+1]=ibotx$iboty[s+1]=iboty$ibotchoch[s+1]=choch$ibotright[s+1]=barindexs=s+1endifendifibotcross=0itrend=-1//Internal order blockif showiOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-ibotx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$itargetTop[t+1]=maxim$itargetBot[t+1]=minim$itargetLeft[t+1]=barindex[idx]$itargetRight[t+1]=n$itargetType[t+1]=-1t=t+1endifendif//Detect Bullish Strcutureif close crosses under boty and botcross thenchoch=undefinedif trend>0 thenchoch=1bearchochalert=1elsebearbosalert=1endifif showStructure thenif showbear=1 or (showbear=2 and not choch) or (showbear=3 and choch) then$botx[w+1]=botx$boty[w+1]=boty$botchoch[w+1]=choch$botright[w+1]=barindexw=w+1endifendif//order blockif showOB thenminim=9999999999maxim=0idx=1if obFilter=1 thenobthreshold=atrelseobthreshold=cmeanRangeendiffor i=1 to (n-botx)-1 doif (high[i]-low[i])<obthreshold[i]*2 thenmaxim=max(high[i],maxim)if maxim=high[i] thenminim=low[i]idx=ielseminim=minimidx=idxendifendifnext$targetTop[r+1]=maxim$targetBot[r+1]=minim$targetLeft[r+1]=barindex[idx]$targetRight[r+1]=n$targetType[r+1]=-1r=r+1endifbotcross=0trend=-1endif//--------------------------------------------------------------------------------////-----Order Blocks---------------------------------------------------------------////--------------------------------------------------------------------------------////Delete internal Order Blocksfor j=t downto 0 doif close < $itargetBot[j] and $itargetType[j]=1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=undefinedelsif close > $itargetTop[j] and $itargetType[j]=-1 then$itargetTop[j]=0$itargetBot[j]=0$itargetLeft[j]=0$itargetRight[j]=0$itargetType[j]=0endifnext//Delete structural Order Blocksfor j=r downto 0 doif close < $targetBot[j] and $targetType[j]=1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=undefinedelsif close > $targetTop[j] and $targetType[j]=-1 then$targetTop[j]=0$targetBot[j]=0$targetLeft[j]=0$targetRight[j]=0$targetType[j]=0endifnext//Plot Order Blocks if not brokencountiOB=0countOB=0if islastbarupdate then//---Internal Order Blocksfor i=t downto 0 doif $itargetBot[i]=0 thencountiOB=countiOBelsecountiOB=countiOB+1if countiOB = showlastOB thenbreakelseif close > $itargetTop[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("green",0)fillcolor("green",50)elsif close <$itargetBot[i] thendrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("red",0)fillcolor("red",50)elsedrawrectangle($itargetLeft[i],$itargetBot[i],n+20,$itargetTop[i])coloured("yellow",0)fillcolor("yellow",50)endifendifendifnext//---Structural Order Blocksfor i=r downto 0 doif $targetBot[i]=0 thencountOB=countOBelsecountOB=countOB+1if countOB = showlastOB thenbreakelseif close > $targetTop[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("green",0)fillcolor("green",100)elsif close <$targetBot[i] thendrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("red",0)fillcolor("red",100)elsedrawrectangle($targetLeft[i],$targetBot[i],n+20,$targetTop[i])coloured("yellow",0)fillcolor("yellow",100)endifendifendifnext//-----------------------------------------------------------------------------////------Draw Pivot Points------------------------------------------------------////-----------------------------------------------------------------------------////---Pivot Highfor i=z downto 0 doif $phtype[i]=1 thendrawtext("HH",$phx[i],$phy[i]+atr*0.5)coloured("red")elsedrawtext("LH",$phx[i],$phy[i]+atr*0.5)coloured("red")endifnext//---Pivot Lowfor i=k downto 0 doif $pltype[i]=1 thendrawtext("LL",$plx[i],$ply[i]-atr*0.5)coloured("green")elsedrawtext("HL",$plx[i],$ply[i]-atr*0.5)coloured("green")endifnext//-----------------------------------------------------------------------------////------Draw Internal Structure------------------------------------------------////-----------------------------------------------------------------------------//for i=m downto 0 dodrawsegment($itopx[i],$itopy[i],$iright[i],$itopy[i])style(dottedline)coloured("green")if $ichoch[i]=1 thendrawtext("CHoCH",($itopx[i]+$iright[i])/2,$itopy[i]+0.25*atr)coloured("green")elsedrawtext("BOS",($itopx[i]+$iright[i])/2,$itopy[i]+0.25*atr)coloured("green")endifnext//-----------------------------------------------------------------------------//for i=s downto 0 dodrawsegment($ibotx[i],$iboty[i],$ibotright[i],$iboty[i])style(dottedline)coloured("red")if $ibotchoch[i]=1 thendrawtext("CHoCH",($ibotx[i]+$ibotright[i])/2,$iboty[i]-0.25*atr)coloured("red")elsedrawtext("BOS",($ibotx[i]+$ibotright[i])/2,$iboty[i]-0.25*atr)coloured("red")endifnext//-----------------------------------------------------------------------------////------Draw Structure---------------------------------------------------------////-----------------------------------------------------------------------------//for i=g downto 0 dodrawsegment($topx[i],$topy[i],$right[i],$topy[i])style(line)coloured("green")drawarrowup($right[i],$topy[i]-0.5*atr)coloured("green")if $topchoch[i]=1 thendrawtext("CHoCH",($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured("green")elsedrawtext("BOS",($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured("green")endifnext//-----------------------------------------------------------------------------//for i=w downto 0 dodrawsegment($botx[i],$boty[i],$botright[i],$boty[i])style(line)coloured("red")drawarrowdown($botright[i],$boty[i]+0.5*atr)coloured("red")if $botchoch[i]=1 thendrawtext("CHoCH",($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured("red")elsedrawtext("BOS",($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured("red")endifnext//-----------------------------------------------------------------------------////-----Top and Bottom extension------------------------------------------------////-----------------------------------------------------------------------------//if showhlswings thendrawsegment(traildnx,traildn,n+20,traildn)coloured("blue")drawsegment(trailupx,trailup,n+20,trailup)coloured("red")if trend>0 thendrawtext("Strong Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Weak High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")elsedrawtext("Weak Low",(traildnx+n+20)/2,traildn-0.35*atr)coloured("blue")drawtext("Strong High",(trailupx+n+20)/2,trailup+0.35*atr)coloured("red")endifendifendif//--------------------------------------------------------------------------------//return averageBB as "SMA" coloured(135,35,35), upperbb as "BB top"coloured("teal"),lowerbb as "BB bot"coloured("teal")3 users thanked author for this post.
08/02/2024 at 11:47 AM #236064Thank you, Ivan- Are the FVGs possible to code into the indicator? as they are an integral part of it
Robert
1 user thanked author for this post.
10/12/2024 at 7:28 PM #238917Iván, sería tremendo si me puedes sacar el Screener del indicador anterior cuando se producen las flechas hacia arriba o hacia abajo…..
Para que me entiendas…… aunque ya sé que está mal escrito eh:
//——Draw Structure———————————————————////—————————————————————————–//for i=g downto 0 dodrawsegment($topx[i],$topy[i],$right[i],$topy[i])style(line)coloured(“green”)drawarrowup($right[i],$topy[i]–0.5*atr)coloured(“green”)if $topchoch[i]=1 thendrawtext(“CHoCH”,($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured(“green”)elsedrawtext(“BOS”,($topx[i]+$right[i])/2,$topy[i]+0.25*atr)coloured(“green”)endifnext//—————————————————————————–//for i=w downto 0 dodrawsegment($botx[i],$boty[i],$botright[i],$boty[i])style(line)coloured(“red”)drawarrowdown($botright[i],$boty[i]+0.5*atr)coloured(“red”)if $botchoch[i]=1 thendrawtext(“CHoCH”,($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured(“red”)elsedrawtext(“BOS”,($botx[i]+$botright[i])/2,$boty[i]+0.25*atr)coloured(“red”)endifnextC1=drawarrowup($right[i],$topy[i]–0.5*atr)coloured(“green”)
C2=drawarrowdown($botright[i],$boty[i]+0.5*atr)coloured(“red”)
SCREENER[C1 OR C2 ]
-
AuthorPosts