ProRealCode - Trading & Coding with ProRealTime™
A ver si se puede convertir el siguiente indicador de tradingview a prorealtime. Da la estructura de mercado y da una idea de donde se está muy fidedigna, la tendencia en definitiva. Es bastante largo, pero creo que merece la pena. https://www.tradingview.com/script/dqfTA4kM-Price-Action-Concepts-HunterAlgos/ https://www.tradingview.com/i/dqfTA4kM/
// 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/
// © HunterAlgos
//@version=5
indicator("Price Action Concepts [HunterAlgos]", shorttitle = "Price Action Concepts [1.0.0]", overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back = 500, max_boxes_count = 500)
//-----------------------------------------------------------------------------{
//Boolean set
//-----------------------------------------------------------------------------{
s_bos = 0
s_choch = 1
i_bos = 2
i_choch = 3
i_pp_choch = 4
green_candle = 5
red_candle = 6
boolean =
array.from(
false // s_bos
, false // s_choch
, false // i_bos
, false // i_choch
, false // i_pp_choch
, false // up
, false // dn
)
//-----------------------------------------------------------------------------{
// User inputs
//-----------------------------------------------------------------------------{
show_swing_ms = input.string("All", "Swing ", ["All", "CHoCH", "BOS", "None"] , group = "MARKET STRUCTURE", inline = "1")
show_internal_ms = input.string("All", "Internal", ["All", "CHoCH", "BOS", "CHoCH+", "None"] , group = "MARKET STRUCTURE", inline = "2")
internal_r_lookback = input.int(5 , "", group = "MARKET STRUCTURE", inline = "2", minval = 2)
swing_r_lookback = input.int(50, "", group = "MARKET STRUCTURE", inline = "1", minval = 2)
internal_l_lookback = math.round(internal_r_lookback / 2)
swing_l_lookback = swing_r_lookback / 2
i_ms_up_bos = input.color(#089981, group = "MARKET STRUCTURE", inline = "2", title = "")
i_ms_up_choch = input.color(#00332a, group = "MARKET STRUCTURE", inline = "2", title = "")
i_ms_dn_bos = input.color(#f23645, group = "MARKET STRUCTURE", inline = "2", title = "")
i_ms_dn_choch = input.color(#801922, group = "MARKET STRUCTURE", inline = "2", title = "")
s_ms_up_bos = input.color(#089981, group = "MARKET STRUCTURE", inline = "1", title = "")
s_ms_up_choch = input.color(#00332a, group = "MARKET STRUCTURE", inline = "1", title = "")
s_ms_dn_bos = input.color(#f23645, group = "MARKET STRUCTURE", inline = "1", title = "")
s_ms_dn_choch = input.color(#801922, group = "MARKET STRUCTURE", inline = "1", title = "")
invcol = color.new(color.white, 100)
lvl_daily = input.bool(false, "Day " , inline = "1", group = "HIGHS & LOWS MTF")
lvl_weekly = input.bool(false, "Week " , inline = "2", group = "HIGHS & LOWS MTF")
lvl_monthly = input.bool(false, "Month", inline = "3", group = "HIGHS & LOWS MTF")
lvl_yearly = input.bool(false, "Year " , inline = "4", group = "HIGHS & LOWS MTF")
css_d = input.color(color.blue, "", group = "HIGHS & LOWS MTF", inline = "1")
css_w = input.color(color.blue, "", group = "HIGHS & LOWS MTF", inline = "2")
css_m = input.color(color.blue, "", group = "HIGHS & LOWS MTF", inline = "3")
css_y = input.color(color.blue, "", group = "HIGHS & LOWS MTF", inline = "4")
s_d = input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = '1', group = 'HIGHS & LOWS MTF')
s_w = input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = '2', group = 'HIGHS & LOWS MTF')
s_m = input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = '3', group = 'HIGHS & LOWS MTF')
s_y = input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = '4', group = 'HIGHS & LOWS MTF')
ob_show = input.bool(true, "Order blocks", inline = "1", group = "VOLUME ORDER BLOCKS")
ob_num = input.int(2 , "" , tooltip = "Orderblocks number", inline = "1", group = "VOLUME ORDER BLOCKS", minval = 1, maxval = 10)
mult = input.int(5 , "Mult ", tooltip = "Add more bar to the right for a clear view", inline = "2", group = "VOLUME ORDER BLOCKS", minval = 1)
ob_timeframe = input.timeframe("", "Timeframe " , inline = "3", group = "VOLUME ORDER BLOCKS")
ob_bull_css = input.color(#08998186, "", inline = "1", group = "VOLUME ORDER BLOCKS")
ob_bear_css = input.color(#f2364683, "", inline = "1", group = "VOLUME ORDER BLOCKS")
ob_opacity = input.int(80, "", inline = "1", tooltip = "Opacity main orderblocks", group = "VOLUME ORDER BLOCKS")
show_liq = input.bool(false, "Liquidity Wicks", inline = "1", group = "LIQUIDITY WICKS")
liq_up_css = input.color(color.yellow, "", inline = "1", group = "LIQUIDITY WICKS")
liq_dn_css = input.color(color.orange, "", inline = "1", group = "LIQUIDITY WICKS")
volMA = input.int (200, "MA Volume threshold", group = "LIQUIDITY WICKS", tooltip = "MA on volume to be above", minval = 2)
liq_thresh = input.float(10 , "Threshold" , group = "LIQUIDITY WICKS", tooltip = "Wick bigger than body" , minval = 2, step = 0.1)
show_lbl = input.bool(true, "Show swing point", inline = "1", group = "GENERAL SETTINGS")
lbl_size = input.string("Small", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = "GENERAL SETTINGS", inline = "1")
show_bar_css = input.bool(false, "Show bar coloring", group = "GENERAL SETTINGS")
//-----------------------------------------------------------------------------{
// Switch market strcture visuals
//-----------------------------------------------------------------------------{
switch show_swing_ms
"All" => boolean.set(s_bos, true) , boolean.set(s_choch, true)
"CHoCH" => boolean.set(s_bos, false), boolean.set(s_choch, true)
"BOS" => boolean.set(s_bos, true) , boolean.set(s_choch, false)
"None" => boolean.set(s_bos, false), boolean.set(s_choch, false)
=> na
switch show_internal_ms
"All" => boolean.set(i_bos, true) , boolean.set(i_choch, true) , boolean.set(i_pp_choch, true)
"CHoCH" => boolean.set(i_bos, false), boolean.set(i_choch, true) , boolean.set(i_pp_choch, false)
"BOS" => boolean.set(i_bos, true) , boolean.set(i_choch, false), boolean.set(i_pp_choch, false)
"CHoCH+" => boolean.set(i_bos, false), boolean.set(i_choch, false), boolean.set(i_pp_choch, true)
"None" => boolean.set(i_bos, false), boolean.set(i_choch, false), boolean.set(i_pp_choch, false)
=> na
//-----------------------------------------------------------------------------{
// Custom Type
//-----------------------------------------------------------------------------{
type bar
float o = open
float c = close
float h = high
float l = low
float v = volume
int n = bar_index
int t = time
string xt = xloc.bar_time
string xn = xloc.bar_index
type bin
float [] i_hpoint
float [] i_lpoint
int [] i_nBull
int [] i_nBear
float [] s_hpoint
float [] s_lpoint
int [] s_nBull
int [] s_nBear
float [] up_ms_logs
float [] dn_ms_logs
string[] i_bulltxt
string[] i_beartxt
type ob
float[] bear_h
float[] bear_l
int [] bear_n
float[] bull_h
float[] bull_l
int [] bull_n
float[] h
float[] l
float[] m
int [] left
box [] ob_bx
line [] ob_line
int [] t_bull
int [] t_bear
float[] v_bull
float[] v_bear
int [] vn
//-----------------------------------------------------------------------------{
// Type set
//-----------------------------------------------------------------------------{
bar b = bar.new()
var pp = bin.new(
array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< int >(1, na)
, array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< int >(1, na)
, array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< string>(1, na)
, array.new< string>(1, na)
)
var obv = ob.new(
array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< float >(0, na)
, array.new< float >(0, na)
, array.new< float >(0, na)
, array.new< int >(0, na)
, array.new< box >(0, na)
, array.new< line >(0, na)
, array.new< int >(1 ,na)
, array.new< int >(1 ,na)
, array.new< float >(1 ,na)
, array.new< float >(1 ,na)
, array.new< int >(1 ,na)
)
//-----------------------------------------------------------------------------{
// order blocks candle cordinate
//-----------------------------------------------------------------------------{
switch
b.c > b.o => boolean.set(green_candle, true)
b.c < b.o => boolean.set(red_candle , true)
switch
boolean.get(green_candle) => obv.bull_h.push(b.h), obv.bull_l.push(b.l), obv.bull_n.push(b.n), obv.t_bull.push(b.t)
boolean.get(red_candle) => obv.bear_h.push(b.h), obv.bear_l.push(b.l), obv.bear_n.push(b.n), obv.t_bear.push(b.t)
=> na
//-----------------------------------------------------------------------------{
// lower timeframe volume
//-----------------------------------------------------------------------------{
method normalize(float _src, int _min, int _max) =>
var _historicMin = 10e10
var _historicMax = -10e10
_historicMin := math.min(nz(_src, _historicMin), _historicMin)
_historicMax := math.max(nz(_src, _historicMax), _historicMax)
_min + (_max - _min) * (_src - _historicMin) / math.max(_historicMax - _historicMin, 10e-10)
vol() =>
float posVol = 0.0
float negVol = 0.0
switch
close > open => posVol += volume
close < open => negVol -= volume
tf = (timeframe.in_seconds("") / 60) / 6
[_one, _two] = request.security_lower_tf("", ob_timeframe , [posVol, negVol])
[_one.sum().normalize(0, 100), _two.sum().normalize(-100, 0)]
//-----------------------------------------------------------------------------{
// set orderblocks
//-----------------------------------------------------------------------------{
method orderblock(bool condition, float top, float btm, int left, int right, float mitigation, bool bull, int num, color css, string _extend, string _xloc, float target_bull, float target_bear, int transp_bg, int transp_border, string strVol) =>
var ob_top = array.new< float >(0)
var ob_btm = array.new< float >(0)
var ob_left = array.new< int >(0)
var ob_right = array.new< int >(0)
var bx = array.new< box >(0)
var l = array.new< line >(0)
var bull_tar = array.new< float >(0)
var bear_tar = array.new< float >(0)
if condition
avg = math.avg(top, btm )
ob_top .unshift(top )
ob_btm .unshift(btm )
ob_left .unshift(left )
ob_right.unshift(right )
bull_tar.unshift(target_bull)
bear_tar.unshift(target_bear)
if barstate.isconfirmed
target = bull ? bull_tar : bear_tar
for stuff in target
index = target.indexof(stuff)
if (bull ? mitigation < stuff : mitigation > stuff)
ob_top .remove(index)
ob_btm .remove(index)
ob_left .remove(index)
ob_right.remove(index)
bull_tar.remove(index)
bear_tar.remove(index)
if barstate.isfirst
for j = 0 to num - 1
bx.unshift(box.new(na, na, na, na
, xloc = _xloc
, extend = _extend
, bgcolor = css
, border_color = color.new(css, 100)
, text = str.tostring(strVol)
, text_halign = text.align_right
, text_size = size.auto
, text_color = css))
if barstate.islast
if ob_top.size() > 0
for j = 0 to math.min(num - 1, ob_top.size() - 1)
g_box = bx.get(j)
g_line = l.get (j)
g_box.set_left (ob_left .get(j))
g_box.set_right (ob_right.get(j))
g_box.set_top (ob_top .get(j))
g_box.set_bottom(ob_btm .get(j))
[up, dn] = vol()
//-----------------------------------------------------------------------------{
// General functions
//-----------------------------------------------------------------------------{
size(x) =>
switch x
"Tiny" => size.tiny
"Small" => size.small
"Large" => size.large
"Huge" => size.huge
_h_l() => [b.h, b.l]
lineStyle(x) =>
y = switch x
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted
y
f_line(x, y, z, css, txt, down, size, style) =>
var line id = na
var label lbl = na
id := line.new(x, y, z, y
, xloc = b.xn
, color = css
, width = 1
, style = style)
lbl := label.new(int(math.avg(x, z)), y, txt
, color = invcol
, textcolor = css
, style = down ? label.style_label_down : label.style_label_up
, size = size)
method sf_hl(string tf) =>
[h, l] = request.security("", tf, _h_l(), lookahead = barmerge.lookahead_on)
[h, l]
method f_hl_line(string _style, color css, string tf) =>
var line h_line = na
var line l_line = na
var label h_label = na
var label l_label = na
h_line := line.new(na, na, na, na
, xloc = b.xt
, color = css
, style = _style
)
l_line := line.new(na, na, na, na
, xloc = b.xt
, color = css
, style = _style
)
h_label := label.new(na, na
, xloc = b.xt
, text = str.format("{0} High" , tf)
, size = size.small
, style = label.style_label_left
, color = invcol
, textcolor = css
)
l_label := label.new(na, na
, xloc = b.xt
, text = str.format("{0} Low", tf)
, size = size.small
, style = label.style_label_left
, color = invcol
, textcolor = css
)
[h_line, l_line, h_label, l_label]
//-----------------------------------------------------------------------------{
// HTF high and low
//-----------------------------------------------------------------------------{
method highANDlow(string _tf, float _higs, float _lows, string _style, color _css) =>
highY = ta.valuewhen(_higs != _higs[1], _higs, 1)
highX = ta.valuewhen(_higs == b.h , b.t , 1)
lowY = ta.valuewhen(_lows != _lows[1], _lows, 1)
lowX = ta.valuewhen(_lows == b.l , b.t , 1)
[h_line, l_line, h_label, l_label] = _style.f_hl_line(_css, _tf)
if barstate.islast
t_end = time + (time - time[1]) * 20
line.set_xy1(h_line , highX, highY)
line.set_xy2(h_line , t_end, highY)
label.set_xy(h_label, t_end, highY)
line.set_xy1(l_line , lowX , lowY )
line.set_xy2(l_line , t_end, lowY )
label.set_xy(l_label, t_end, lowY )
[d_h, d_l] = "D" .sf_hl()
[w_h, w_l] = "W" .sf_hl()
[m_h, m_l] = "M" .sf_hl()
[y_h, y_l] = "12M".sf_hl()
if lvl_daily
"D" .highANDlow(d_h, d_l, lineStyle(s_d), css_d)
if lvl_weekly
"W" .highANDlow(w_h, w_l, lineStyle(s_w), css_w)
if lvl_monthly
"M" .highANDlow(m_h, m_l, lineStyle(s_m), css_m)
if lvl_yearly
"12M".highANDlow(y_h, y_l, lineStyle(s_y), css_y)
//-----------------------------------------------------------------------------{
// Market strcture pivot point
//-----------------------------------------------------------------------------{
point() =>
ph_i = ta.pivothigh(b.h, internal_l_lookback, internal_r_lookback)
pl_i = ta.pivotlow (b.l , internal_l_lookback, internal_r_lookback)
ph_s = ta.pivothigh(b.h, swing_l_lookback, swing_r_lookback)
pl_s = ta.pivotlow (b.l , swing_l_lookback, swing_r_lookback)
[ph_i, pl_i, ph_s, pl_s]
[ph_i, pl_i, ph_s, pl_s] = point()
switch
ph_i => pp.i_hpoint.clear(), pp.i_nBull.clear(), pp.i_hpoint.push(b.h[internal_r_lookback]), pp.i_nBull.push(b.n[internal_r_lookback]), pp.up_ms_logs.push(b.h[internal_r_lookback])
pl_i => pp.i_lpoint.clear(), pp.i_nBear.clear(), pp.i_lpoint.push(b.l[internal_r_lookback]), pp.i_nBear.push(b.n[internal_r_lookback]), pp.dn_ms_logs.push(b.l[internal_r_lookback])
ph_s => pp.s_hpoint.clear(), pp.s_nBull.clear(), pp.s_hpoint.push(b.h[swing_r_lookback]) , pp.s_nBull.push(b.n[swing_r_lookback])
pl_s => pp.s_lpoint.clear(), pp.s_nBear.clear(), pp.s_lpoint.push(b.l[swing_r_lookback]) , pp.s_nBear.push(b.n[swing_r_lookback])
=> na
//-----------------------------------------------------------------------------{
// strcture set
//-----------------------------------------------------------------------------{
method structure(bin zz, bool mtf) =>
var color css = na
var int count = 0
var trend = 0
var itrend = 0
var ob_bear = false
bool bear_ob = false
bool bull_ob = false
if true
//-----------------------------------------------------------------------------{
//Internal structure bullish
//-----------------------------------------------------------------------------{
if zz.dn_ms_logs.size() > 1 and zz.i_hpoint.size() > 0 and zz.i_nBull.size() > 0
if ta.crossover(b.c, zz.i_hpoint.last())
bool choch = na
string txt = na
if itrend < 0
choch := true
switch
choch and not (zz.dn_ms_logs.last() > zz.dn_ms_logs.get(zz.dn_ms_logs.indexof(zz.dn_ms_logs.last()) - 1)) => txt := "CHoCH"
choch and (zz.dn_ms_logs.last() > zz.dn_ms_logs.get(zz.dn_ms_logs.indexof(zz.dn_ms_logs.last()) - 1)) => txt := "CHoCH+"
not choch => txt := "BOS"
itrend := 1
switch txt
"CHoCH" => css := i_ms_up_choch
"BOS" => css := i_ms_up_bos
"CHoCH+" => css := i_ms_up_choch
=> css
if ((txt == "BOS" and boolean.get(i_bos) == true) or (txt == "CHoCH" and boolean.get(i_choch) == true) or (txt =="CHoCH+" and boolean.get(i_pp_choch) == true)) and mtf == false
f_line(zz.i_nBull.last(), zz.i_hpoint.last(), b.n, i_ms_up_bos, txt, true, size.small, line.style_dashed)
if txt == "BOS"
bull_ob := true
zz.i_nBull.clear ()
zz.i_hpoint.clear()
zz.i_bulltxt.push(txt)
//-----------------------------------------------------------------------------{
//Internal structure bearish
//-----------------------------------------------------------------------------{
if zz.up_ms_logs.size() > 1 and zz.i_lpoint.size() > 0 and zz.i_nBear.size() > 0
if ta.crossunder(b.c, zz.i_lpoint.last())
bool choch = na
string txt = na
if itrend > 0
choch := true
switch
choch and not (zz.up_ms_logs.last() < zz.up_ms_logs.get(zz.up_ms_logs.indexof(zz.up_ms_logs.last()) - 1)) => txt := "CHoCH"
choch and (zz.up_ms_logs.last() < zz.up_ms_logs.get(zz.up_ms_logs.indexof(zz.up_ms_logs.last()) - 1)) => txt := "CHoCH+"
not choch => txt := "BOS"
itrend := -1
switch txt
"CHoCH" => css := i_ms_dn_choch
"BOS" => css := i_ms_dn_bos
"CHoCH+" => css := i_ms_dn_choch
=> css
if ((txt == "BOS" and boolean.get(i_bos) == true) or (txt == "CHoCH" and boolean.get(i_choch) == true) or (txt =="CHoCH+" and boolean.get(i_pp_choch) == true)) and mtf == false
f_line(zz.i_nBear.last(), zz.i_lpoint.last(), b.n, i_ms_dn_bos, txt, false, size.small, line.style_dashed)
if txt == "BOS"
bear_ob := true
zz.i_nBear.clear ()
zz.i_lpoint.clear()
zz.i_beartxt.push(txt)
//-----------------------------------------------------------------------------{
//Swing structure bullish
//-----------------------------------------------------------------------------{
if zz.s_hpoint.size() > 0
if ta.crossover(b.c, zz.s_hpoint.last())
bool choch = na
string txt = na
if trend < 0
choch := true
txt := choch ? "CHoCH" : "BOS"
trend := 1
if ((txt == "BOS" and boolean.get(s_bos) == true) or (txt == "CHoCH" and boolean.get(s_choch) == true) and mtf == false)
f_line(zz.s_nBull.last(), zz.s_hpoint.last(), b.n, i_ms_up_bos, txt, true, size.small, line.style_solid)
zz.s_nBull.clear ()
zz.s_hpoint.clear()
//-----------------------------------------------------------------------------{
//Swing structure bearish
//-----------------------------------------------------------------------------{
if zz.s_lpoint.size() > 0
if ta.crossunder(b.c, zz.s_lpoint.last())
bool choch = na
string txt = na
if trend > 0
choch := true
txt := choch ? "CHoCH" : "BOS"
trend := -1
if ((txt == "BOS" and boolean.get(s_bos) == true) or (txt == "CHoCH" and boolean.get(s_choch) == true) and mtf == false)
f_line(zz.s_nBear.last(), zz.s_lpoint.last(), b.n, i_ms_dn_bos, txt, false, size.small, line.style_solid)
zz.s_nBear.clear ()
zz.s_lpoint.clear()
[css, bear_ob, bull_ob]
[css, bear_ob_check, bull_ob_check] = pp.structure(false)
//-----------------------------------------------------------------------------{
// basic Liquidity wick function
//-----------------------------------------------------------------------------{
liq_wick(bool green, int len, float thresh) =>
bool up_liq = false
bool dn_liq = false
bool vol = b.v > ta.sma(b.v, len) ? true : false
float u_c = na
float u_h = na
float u_o = na
float d_c = na
float d_lo = na
float d_o = na
upwick = math.abs(high - math.max(open, close))
dnwick = math.abs(low - math.min(open, close))
body = math.abs(close - open)
switch green
true => up_liq := upwick > thresh * body and vol ? true : false
false => dn_liq := dnwick > thresh * body and vol ? true : false
=> na
switch up_liq
true => u_c := close, u_h := high, u_o := open
=> na
switch dn_liq
true => d_c := close, d_lo := low, d_o := open
=> na
[up_liq, dn_liq, u_c, u_h, u_o, d_c, d_lo, d_o]
[up_liq, dn_liq, u_c, u_h, u_o, d_c, d_lo, d_o] = liq_wick(close > open, volMA, liq_thresh)
//-----------------------------------------------------------------------------{
// set order blocks
//-----------------------------------------------------------------------------{
switch ob_show
false => bear_ob_check := false, bull_ob_check := false
=> na
bull_ob_check.orderblock(
obv.bear_h.last()
, obv.bear_l.last()
, obv.t_bear.last()
, obv.t_bear.last()
, close
, true
, ob_num
, color.new(ob_bull_css, ob_opacity)
, extend.right
, xloc.bar_time
, obv.bear_l.last()
, obv.bear_l.last()
, ob_opacity
, 100
, "")
bull_ob_check.orderblock(
obv.bear_h.last()
, ((obv.bear_l.last() + obv.bear_h.last()) / 2)
, obv.t_bear.last()
, time_close + (time_close - time_close[1]) * int(up * mult)
, close
, true
, ob_num
, ob_bull_css
, extend.none, xloc.bar_time
, obv.bear_l.last()
, obv.bear_l.last()
, 60
, 100
, "")
bull_ob_check.orderblock(
((obv.bear_l.last() + obv.bear_h.last()) / 2)
, obv.bear_l.last()
, obv.t_bear.last()
, time_close + (time_close - time_close[1]) * int(math.abs(dn * mult))
, close
, true
, ob_num
, ob_bear_css
, extend.none
, xloc.bar_time
, obv.bear_l.last()
, obv.bear_l.last()
, 60
, 100
, "")
bear_ob_check.orderblock(
obv.bull_h.last()
, obv.bull_l.last()
, obv.t_bull.last()
, obv.t_bull.last()
, close
, false
, ob_num
, color.new(ob_bear_css, ob_opacity)
, extend.right
, xloc.bar_time
, obv.bull_h.last()
, obv.bull_h.last()
, ob_opacity
, 100
, "")
bear_ob_check.orderblock(
obv.bull_h.last()
, ((obv.bull_l.last() + obv.bull_h.last()) / 2)
, obv.t_bull.last()
, time_close + (time_close - time_close[1]) * int(up * mult)
, close
, false
, ob_num
, ob_bull_css
, extend.none
, xloc.bar_time
, obv.bull_h.last()
, obv.bull_h.last()
, 60
, 100
, "")
bear_ob_check.orderblock(
((obv.bull_l.last() + obv.bull_h.last()) / 2)
, obv.bull_l.last(), obv.t_bull.last()
, time_close + (time_close - time_close[1]) * int(math.abs(dn * mult))
, close
, false
, ob_num
, ob_bear_css
, extend.none
, xloc.bar_time
, obv.bull_h.last()
, obv.bull_h.last()
, 60
, 100
, "")
//-----------------------------------------------------------------------------{
// plotting
//-----------------------------------------------------------------------------{
if pp.s_hpoint.size() > 0
if ta.change(pp.s_hpoint.last())
label.new(bar_index[swing_r_lookback], high[swing_r_lookback], text = "HH", color = invcol, style = label.style_label_down, textcolor = i_ms_up_bos, size = size(lbl_size))
if pp.s_lpoint.size() > 0
if ta.change(pp.s_lpoint.last())
label.new(bar_index[swing_r_lookback], low[swing_r_lookback], text = "LL", color = invcol, style = label.style_label_up, textcolor = i_ms_dn_bos, size = size(lbl_size))
plotcandle(open,high,low,close , color = css , wickcolor = color.rgb(120, 123, 134, 50), bordercolor = css)
plotcandle(u_c, u_h, u_o, u_h , wickcolor = invcol, color = invcol, bordercolor = show_liq ? liq_up_css : invcol)
plotcandle(d_c, d_c, d_lo, d_lo, wickcolor = invcol, color = invcol, bordercolor = show_liq ? liq_dn_css : invcol)
barcolor(color = show_bar_css ? css : na)
Buenas! aquí un código que se aproxima bastante al original. No he traducido el apartado de order blocks porque el pinescript utiliza timeframes menores y esto en PRT no se puede hacer.
// --------------------------------------------
// PRC_Price Action Concepts
// Based on: HunterAlgos (PineScript v5)
// version = 0
// 04.03.2026
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
// --------------------------------------------
// --- PARAMETERS ---
// --------------------------------------------
// Internal structure: right lookback (left = round(right/2))
internalRLB = 5 // min 2
// Swing structure: right lookback (left = round(right/2))
swingRLB = 50 // min 2
// Show Internal MS: 0=None, 1=All, 2=CHoCH only, 3=BOS only, 4=CHoCH+ only
showInternal = 1
// Show Swing MS: 0=None, 1=All, 2=CHoCH only, 3=BOS only
showSwing = 1
// Swing point labels (HH/LH/HL/LL): 1=show, 0=hide
showLabels = 1
// Liquidity wicks: 1=show, 0=hide
showLiq = 1
// Bar coloring by internal trend: 1=show, 0=hide
showCandle = 1
// Volume MA length for liquidity filter
volMALen = 200
// Wick threshold (wick > N * body)
liqThresh = 10
// --------------------------------------------
// --- DERIVED LOOKBACKS ---
// --------------------------------------------
internalLLB = max(1, round(internalRLB / 2))
swingLLB = max(1, round(swingRLB / 2))
// ATR for label offset
atrRef = averagetruerange[14]
// --------------------------------------------
// PIVOT DETECTION
// --------------------------------------------
// Internal pivot high (asymmetric: left=internalLLB, right=internalRLB)
newIPH = 0
totalIWin = internalLLB + internalRLB + 1
if barindex >= totalIWin then
if high[internalRLB] >= highest[totalIWin](high) then
newIPH = 1
endif
endif
// Internal pivot low
newIPL = 0
if barindex >= totalIWin then
if low[internalRLB] <= lowest[totalIWin](low) then
newIPL = 1
endif
endif
// Swing pivot high (asymmetric: left=swingLLB, right=swingRLB)
newSPH = 0
totalSWin = swingLLB + swingRLB + 1
if barindex >= totalSWin then
if high[swingRLB] >= highest[totalSWin](high) then
newSPH = 1
endif
endif
// Swing pivot low
newSPL = 0
if barindex >= totalSWin then
if low[swingRLB] <= lowest[totalSWin](low) then
newSPL = 1
endif
endif
// --------------------------------------------
// PIVOT STORAGE + LOGS
// --------------------------------------------
once iHiReady = 0
once iLoReady = 0
once sHiReady = 0
once sLoReady = 0
once itrend = 0
once strend = 0
once logHiCount = 0
once logLoCount = 0
once sphCount = 0
once splCount = 0
once lastIPH = -1
once lastIPL = -1
once lastIPHx = 0
once lastIPLx = 0
once lastSPH = -1
once lastSPL = -1
once lastSPHx = 0
once lastSPLx = 0
once lastLogHi = -1
once lastLogLo = -1
once prevLogHi = -1
once prevLogLo = -1
once prevSPH = -1
once prevSPL = 999999999
// --- Internal pivot high found ---
if newIPH then
lastIPH = high[internalRLB]
lastIPHx = barindex - internalRLB
iHiReady = 1
// Cumulative log for CHoCH+ detection
prevLogHi = lastLogHi
lastLogHi = high[internalRLB]
logHiCount = logHiCount + 1
endif
// --- Internal pivot low found ---
if newIPL then
lastIPL = low[internalRLB]
lastIPLx = barindex - internalRLB
iLoReady = 1
// Cumulative log for CHoCH+ detection
prevLogLo = lastLogLo
lastLogLo = low[internalRLB]
logLoCount = logLoCount + 1
endif
// --- Swing pivot high found ---
if newSPH then
lastSPH = high[swingRLB]
lastSPHx = barindex - swingRLB
sHiReady = 1
// Draw HH/LH label
if showLabels then
if sphCount > 0 then
if lastSPH > prevSPH then
drawtext("HH", barindex - swingRLB, high[swingRLB] + atrRef * 0.5) coloured(8,153,129)
else
drawtext("LH", barindex - swingRLB, high[swingRLB] + atrRef * 0.5) coloured(242,54,69)
endif
endif
endif
prevSPH = lastSPH
sphCount = sphCount + 1
endif
// --- Swing pivot low found ---
if newSPL then
lastSPL = low[swingRLB]
lastSPLx = barindex - swingRLB
sLoReady = 1
// Draw HL/LL label
if showLabels then
if splCount > 0 then
if lastSPL > prevSPL then
drawtext("HL", barindex - swingRLB, low[swingRLB] - atrRef * 0.5) coloured(8,153,129)
else
drawtext("LL", barindex - swingRLB, low[swingRLB] - atrRef * 0.5) coloured(242,54,69)
endif
endif
endif
prevSPL = lastSPL
splCount = splCount + 1
endif
// --------------------------------------------
// INTERNAL STRUCTURE DETECTION
// --------------------------------------------
// --- Internal Bullish Break (close crosses above pivot high) ---
if iHiReady = 1 and lastIPH > 0 then
if close > lastIPH and close[1] <= lastIPH then
// Determine type
iBullType = 0
if itrend < 0 then
// Was bearish -> CHoCH or CHoCH+
if logLoCount >= 2 and lastLogLo > prevLogLo then
iBullType = 3 // CHoCH+ (higher low confirms)
else
iBullType = 2 // CHoCH
endif
else
iBullType = 1 // BOS (trend continuation)
endif
itrend = 1
// Decide if we should draw
iBullDraw = 0
if iBullType = 1 and (showInternal = 1 or showInternal = 3) then
iBullDraw = 1
elsif iBullType = 2 and (showInternal = 1 or showInternal = 2) then
iBullDraw = 1
elsif iBullType = 3 and (showInternal = 1 or showInternal = 4) then
iBullDraw = 1
endif
if iBullDraw then
// Colors: BOS=green, CHoCH/CHoCH+=dark green
if iBullType = 1 then
ibR = 8
ibG = 153
ibB = 129
else
ibR = 0
ibG = 120
ibB = 100
endif
// Draw structure line (dashed) + label
midIBx = round((lastIPHx + barindex) / 2)
drawsegment(lastIPHx, lastIPH, barindex, lastIPH) coloured(ibR, ibG, ibB) style(dottedline2, 1)
if iBullType = 1 then
drawtext("BOS", midIBx, lastIPH + atrRef * 0.2) coloured(ibR, ibG, ibB)
elsif iBullType = 2 then
drawtext("CHoCH", midIBx, lastIPH + atrRef * 0.2) coloured(ibR, ibG, ibB)
else
drawtext("CHoCH+", midIBx, lastIPH + atrRef * 0.2) coloured(ibR, ibG, ibB)
endif
endif
// Pivot consumed
iHiReady = 0
endif
endif
// --- Internal Bearish Break (close crosses below pivot low) ---
if iLoReady = 1 and lastIPL > 0 then
if close < lastIPL and close[1] >= lastIPL then
// Determine type
iBearType = 0
if itrend > 0 then
// Was bullish -> CHoCH or CHoCH+
if logHiCount >= 2 and lastLogHi < prevLogHi then
iBearType = 3 // CHoCH+ (lower high confirms)
else
iBearType = 2 // CHoCH
endif
else
iBearType = 1 // BOS
endif
itrend = -1
// Decide if we should draw
iBearDraw = 0
if iBearType = 1 and (showInternal = 1 or showInternal = 3) then
iBearDraw = 1
elsif iBearType = 2 and (showInternal = 1 or showInternal = 2) then
iBearDraw = 1
elsif iBearType = 3 and (showInternal = 1 or showInternal = 4) then
iBearDraw = 1
endif
if iBearDraw then
// Colors: BOS=red, CHoCH/CHoCH+=dark red
if iBearType = 1 then
ieR = 242
ieG = 54
ieB = 69
else
ieR = 180
ieG = 40
ieB = 55
endif
// Draw structure line (dashed) + label
midIEx = round((lastIPLx + barindex) / 2)
drawsegment(lastIPLx, lastIPL, barindex, lastIPL) coloured(ieR, ieG, ieB) style(dottedline2, 1)
if iBearType = 1 then
drawtext("BOS", midIEx, lastIPL - atrRef * 0.2) coloured(ieR, ieG, ieB)
elsif iBearType = 2 then
drawtext("CHoCH", midIEx, lastIPL - atrRef * 0.2) coloured(ieR, ieG, ieB)
else
drawtext("CHoCH+", midIEx, lastIPL - atrRef * 0.2) coloured(ieR, ieG, ieB)
endif
endif
// Pivot consumed
iLoReady = 0
endif
endif
// --------------------------------------------
// SWING STRUCTURE DETECTION
// --------------------------------------------
// --- Swing Bullish Break ---
if sHiReady = 1 and lastSPH > 0 then
if close > lastSPH and close[1] <= lastSPH then
// Determine type
if strend < 0 then
sBullType = 2 // CHoCH
else
sBullType = 1 // BOS
endif
strend = 1
// Decide if we should draw
sBullDraw = 0
if sBullType = 1 and (showSwing = 1 or showSwing = 3) then
sBullDraw = 1
elsif sBullType = 2 and (showSwing = 1 or showSwing = 2) then
sBullDraw = 1
endif
if sBullDraw then
if sBullType = 1 then
sbR = 8
sbG = 153
sbB = 129
else
sbR = 0
sbG = 120
sbB = 100
endif
midSBx = round((lastSPHx + barindex) / 2)
drawsegment(lastSPHx, lastSPH, barindex, lastSPH) coloured(sbR, sbG, sbB) style(line, 2)
if sBullType = 1 then
drawtext("BOS", midSBx, lastSPH + atrRef * 0.4) coloured(sbR, sbG, sbB)
else
drawtext("CHoCH", midSBx, lastSPH + atrRef * 0.4) coloured(sbR, sbG, sbB)
endif
endif
// Pivot consumed
sHiReady = 0
endif
endif
// --- Swing Bearish Break ---
if sLoReady = 1 and lastSPL > 0 then
if close < lastSPL and close[1] >= lastSPL then
// Determine type
if strend > 0 then
sBearType = 2 // CHoCH
else
sBearType = 1 // BOS
endif
strend = -1
// Decide if we should draw
sBearDraw = 0
if sBearType = 1 and (showSwing = 1 or showSwing = 3) then
sBearDraw = 1
elsif sBearType = 2 and (showSwing = 1 or showSwing = 2) then
sBearDraw = 1
endif
if sBearDraw then
if sBearType = 1 then
seR = 242
seG = 54
seB = 69
else
seR = 180
seG = 40
seB = 55
endif
midSEx = round((lastSPLx + barindex) / 2)
drawsegment(lastSPLx, lastSPL, barindex, lastSPL) coloured(seR, seG, seB) style(line, 2)
if sBearType = 1 then
drawtext("BOS", midSEx, lastSPL - atrRef * 0.4) coloured(seR, seG, seB)
else
drawtext("CHoCH", midSEx, lastSPL - atrRef * 0.4) coloured(seR, seG, seB)
endif
endif
// Pivot consumed
sLoReady = 0
endif
endif
// --------------------------------------------
// LIQUIDITY WICKS
// --------------------------------------------
if showLiq then
upWick = abs(high - max(open, close))
dnWick = abs(low - min(open, close))
body = abs(close - open)
volAboveMA = volume > average[volMALen](volume)
// Upper wick liquidity (green candle only)
if close > open and upWick > liqThresh * body and volAboveMA then
drawsegment(barindex, max(open, close), barindex, high) coloured(255, 255, 0) style(line, 3)
endif
// Lower wick liquidity (red candle only)
if close < open and dnWick > liqThresh * body and volAboveMA then
drawsegment(barindex, min(open, close), barindex, low) coloured(255, 165, 0) style(line, 3)
endif
endif
// --------------------------------------------
// BAR COLORING (drawcandle by internal trend)
// --------------------------------------------
if showCandle then
if itrend > 0 then
cR = 8
cG = 153
cB = 129
elsif itrend < 0 then
cR = 242
cG = 54
cB = 69
else
cR = 120
cG = 123
cB = 134
endif
drawcandle(open, high, low, close) coloured(cR, cG, cB)
endif
// --------------------------------------------
return
This topic contains 3 replies,
has 3 voices, and was last updated by
Iván González
9 hours, 6 minutes ago.
| Forum: | TradingView to ProRealTime Translation Center Forum |
| Started: | 09/22/2023 |
| Status: | Active |
| Attachments: | No files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.