Professional Documents
Culture Documents
//
//==> Volumetric Order Blocks
ob_show = input.bool (true
, "Show Last " , inline = "1", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Display volumetric order blocks on the chart \n\n[Input] Ammount of
volumetric order blocks to show")
ob_num = input.int (2
, "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Orderblocks number", minval = 1, maxval = 10)
ob_metrics_show = input.bool (true
, "Internal Buy/Sell Activity" , inline = "2", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Display volume metrics that have formed the orderblock")
css_metric_up = input.color (color.new(color.teal, 50)
, " " , inline = "2", group = "VOLUMETRIC ORDER BLOCKS")
css_metric_dn = input.color (color.new(color.red , 50)
, "" , inline = "2", group = "VOLUMETRIC ORDER BLOCKS")
ob_swings = input.bool (false
, "Swing Order Blocks" , inline = "a", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Display swing volumetric order blocks")
css_swing_up = input.color (color.new(#42bda8, 40)
, " " , inline = "a", group = "VOLUMETRIC ORDER BLOCKS")
css_swing_dn = input.color (color.new(#ff5252, 40)
, "" , inline = "a", group = "VOLUMETRIC ORDER BLOCKS")
ob_lookback_bool = input.bool (false
, "Lenght " , inline = "3", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "[Enable] Use the lenght period to determine the lowest/highest point
of the orderblock creation\n\n[Disable] Use the last opposite candle to determine
the orderblock creation")
ob_filter = input.string ("None"
, "Filtering " , inline = "d", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Filter out volumetric order blocks by BOS/CHoCH/CHoCH+", options =
["None", "BOS", "CHoCH", "CHoCH+"])
ob_looback = input.int (5
, "" , inline = "3", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Lookback to find lowest point for the construction of the volumetric
order blocks")
ob_mitigation = input.string ("Absolute"
, "Mitigation " , inline = "4", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Trigger to remove volumetric order blocks", options = ["Absolute",
"Middle"])
ob_timeframe = input.timeframe (""
, "Timeframe " , inline = "5", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Timeframe of the volumetric order blocks")
use_grayscale = input.bool (true
, "Grayscale" , inline = "6", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Use gray as basic order blocks color")
use_show_metric = input.bool (true
, "Show Metrics" , inline = "7", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Show volume associated with the orderblock and his relevance")
use_middle_line = input.bool (true
, "Show Middle-Line" , inline = "8", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Show mid-line order blocks")
use_overlap = input.bool (true
, "Hide Overlap" , inline = "9", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "Hide overlapping order blocks")
use_overlap_method = input.string ("Previous"
, "Overlap Method " , inline = "Z", group = "VOLUMETRIC ORDER BLOCKS"
, tooltip = "[Recent] Preserve the most recent volumetric order blocks\n\
n[Previous] Preserve the previous volumetric order blocks", options = ["Recent",
"Previous"])
ob_bull_css = input.color (color.new(color.teal, 90)
, "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS")
ob_bear_css = input.color (color.new(color.red , 90)
, "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS")
//
//-----------------------------------------------------------------------------{
// Custom Type
//-----------------------------------------------------------------------------{
type ob
float[] up_vol
float[] up_top
float[] up_bottom
int [] up_current_time
int [] up_last_time
int [] up_n
float[] dn_vol
float[] dn_top
float[] dn_bottom
int [] dn_current_time
int [] dn_last_time
int [] dn_n
float[] metric_up
float[] metric_dn
//-----------------------------------------------------------------------------{
// Type set
//-----------------------------------------------------------------------------{
bar b = bar.new()
var obv = ob.new(
array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< int >(1, na)
, array.new< int >(1, na)
lstyle(style) =>
volblock(bool condition, bool bull, string mitigation, float top, float bottom, int
left, int right, color css, float upx, float dnx, int position, float upv, float
dnv) =>
var ob_top = array.new< float >()
var ob_bottom = array.new< float >()
var ob_left = array.new< int >()
var ob_right = array.new< int >()
var ob_avg = array.new< float >()
var ob_vol = array.new< float >()
var redvol = array.new< float >()
var greenvol = array.new< float >()
var pos = array.new< int >()
var when = array.new< int >()
var countup = array.new< int >()
var countdn = array.new< int >()
if condition
paperlow = array.new< float >()
paperhigh = array.new< float >()
paperindex = array.new< int >()
paperlow .clear()
paperhigh.clear()
float avg = na
var bool isna = na
for i = 1 to ob_looback + 1
if ob_lookback_bool == false
ob_top .unshift(top )
ob_bottom.unshift(bottom)
ob_left .unshift(left )
if ob_lookback_bool
ob_top .unshift(bull ?
paperhigh .get(paperlow.indexof(paperlow.min())) : paperhigh .max())
ob_bottom.unshift(bull ? paperlow .min()
: paperlow .get(paperhigh.indexof(paperhigh.max())))
ob_left .unshift(bull ?
paperindex.get(paperlow.indexof(paperlow.min())) :
paperindex.get(paperhigh.indexof(paperhigh.max())))
ob_right .unshift(right )
ob_avg .unshift(avg )
ob_vol .unshift(bull ? dnv : upv)
redvol .unshift(dnx )
greenvol .unshift(upx )
pos .unshift(position )
when .unshift(1 )
countup .unshift(0 )
countdn .unshift(0 )
if use_overlap
if ob_avg.size() > 1
ob_top .remove(num)
ob_bottom.remove(num)
ob_left .remove(num)
ob_right .remove(num)
ob_avg .remove(num)
ob_vol .remove(num)
redvol .remove(num)
greenvol .remove(num)
pos .remove(num)
when .remove(num)
countup .remove(num)
countdn .remove(num)
if barstate.isconfirmed
out = switch mitigation
"Middle" => ob_avg
"Absolute" => bull ? ob_bottom : ob_top
target = out
idx = target.indexof(stuff)
ob_top .remove(idx)
ob_bottom.remove(idx)
ob_left .remove(idx)
ob_right .remove(idx)
ob_avg .remove(idx)
ob_vol .remove(idx)
redvol .remove(idx)
greenvol .remove(idx)
pos .remove(idx)
when .remove(idx)
countup .remove(idx)
countdn .remove(idx)
if true
if barstate.isfirst
for i = 0 to ob_num - 1
if barstate.islast
if ob_top.size() > 0
// MAIN ORDERBLOCK
box.set_top (get_orderblock, ob_top .get(i)
)
box.set_bottom(get_orderblock, ob_bottom .get(i)
)
box.set_left (get_orderblock, ob_left .get(i)
)
box.set_right (get_orderblock, time
)
// CONTINUATION BLOCK
box.set_top (get_continuationorderblock, ob_top .get(i)
)
box.set_bottom(get_continuationorderblock, ob_bottom.get(i)
)
box.set_left (get_continuationorderblock, time
)
box.set_right (get_continuationorderblock, time + (time -
time[1]) * 100)
// MIDDLE LEVEL
if use_middle_line
if ob_metrics_show
takeup = box.get_right(get_uporderblock)
takedn = box.get_right(get_dnorderblock)
box.set_right (get_dnorderblock, takedn + (time - time[1])
* countdn.get(i))
box.set_right (get_uporderblock, takeup + (time - time[1])
* countup.get(i))
if use_show_metric
box.set_text (get_continuationorderblock,
str.tostring(math.round(ob_vol.get(i) / 1000,3)) + "K" + " (" +
str.tostring( math.abs(math.round((ob_vol.get(i) - (i == 0 ? sum : ob_vol.get(0)) )
/ (i == 0 ? sum : ob_vol.get(0)) ,3)) * 10) + "%)")
box.set_text_size (get_continuationorderblock, size.auto)
box.set_text_halign(get_continuationorderblock,
text.align_left)
box.set_text_color (get_continuationorderblock,
color.new(css,0))
if ob_metrics_show
for i = 0 to countup.size() - 1
switch when.get(i)
1 => countdn.set(i, countdn.get(i) + 1), when.set(i, 2)
2 => countdn.set(i, countdn.get(i) + 1), when.set(i, 3)
3 => countup.set(i, countup.get(i) + 1), when.set(i, 1)
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
)
//-----------------------------------------------------------------------------{
// Market strcture pivot point
//-----------------------------------------------------------------------------{
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.up_bottom.push(obsec(low)),
obv.up_top.push(obsec(high)), obv.up_vol.push(math.abs(_v)),
obv.up_current_time.push(time), obv.up_last_time.push(time[1]),
obv.up_n.push(bar_index), obv.metric_up.push(upvol),
obv.metric_dn.push(math.abs(dnvol))
boolean.get(red_candle) => obv.dn_bottom.push(obsec(low)),
obv.dn_top.push(obsec(high)), obv.dn_vol.push(math.abs(_v)),
obv.dn_current_time.push(time), obv.dn_last_time.push(time[1]),
obv.dn_n.push(bar_index), obv.metric_up.push(upvol),
obv.metric_dn.push(math.abs(dnvol))
=> na
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) =>
if true