Skip to content

Instantly share code, notes, and snippets.

@illcrx
Last active July 1, 2021 22:26
Show Gist options
  • Save illcrx/c4c5d7232c2ab2c61fefb8c75dc2517c to your computer and use it in GitHub Desktop.
Save illcrx/c4c5d7232c2ab2c61fefb8c75dc2517c to your computer and use it in GitHub Desktop.
Volume Aggregator
//@version=4
study("Volume Aggregation", overlay=false, precision=0)
colorRed = #ffa500
colorGreen = #6fff00
colorBlue = #6f00ff
//Variables to get percentage open/close
breadth = high - low //this is the bar range
closeBreadth = close - low // this is the closing
barCloseBreadth = closeBreadth / breadth
sellingWick = barCloseBreadth < .49 // (high-close > close-low)
buyingWick = barCloseBreadth > .51 //(high-close <= close-low)
allOtherBars = barCloseBreadth > .4 and barCloseBreadth < .6 // catches what the rest doesnt
aggPeriod = input(defval=20, title="Agg Period", type=input.integer)
show_diff = input(defval=true, title="Show Difference", type=input.bool)
red_volume = sellingWick ? volume : 0
green_volume = buyingWick ? volume : 0
other_volume = allOtherBars ? volume: 0
total_red_volume = sum(red_volume, aggPeriod)
total_green_volume = sum(green_volume, aggPeriod)
plot(total_red_volume, color=colorRed, linewidth=1, title="Distribution")
plot(total_green_volume, color=colorGreen, linewidth=1, title="Accumulation")
plot((show_diff) ? (total_green_volume >= total_red_volume) ? total_green_volume - total_red_volume : total_red_volume - total_green_volume : na, color=(total_green_volume >= total_red_volume) ? color.new(colorGreen,70) : color.new(colorRed, 70), linewidth=2, style=plot.style_columns, title="Difference")
//==============
// Pocket Pivots
show_green_pps = input(title="Show Pocket Pivots",
type=input.bool, defval=true)
bar_count_red = input(title="Lower Red Volume Bar Count",
type=input.integer, defval=10)
show_red_pps = input(title="Show Inverse Pocket Pivots",
type=input.bool, defval=true)
bar_count_green = input(title="Lower Green Volume Bar Count",
type=input.integer, defval=10)
var is_pocket_pivot_green = false
var vols_green = array.new_float(0)
var is_pocket_pivot_red = false
var vols_red = array.new_float(0)
if close < open
// reg candle so add to array
array.push(vols_red, volume)
if array.size(vols_red) > bar_count_red
array.shift(vols_red)
array.push(vols_green, 0)
if array.size(vols_green) > bar_count_green
array.shift(vols_green)
is_pocket_pivot_green := false
else if array.size(vols_red) == bar_count_red and volume > array.max(vols_red)
// green candle is higher than array red candles
is_pocket_pivot_green := show_green_pps
if close >= open
// green candle so add to array
array.push(vols_green, volume)
if array.size(vols_green) > bar_count_green
array.shift(vols_green)
array.push(vols_red, 0)
if array.size(vols_red) > bar_count_red
array.shift(vols_red)
is_pocket_pivot_red := false
else if array.size(vols_green) == bar_count_green and volume > array.max(vols_green)
// red candle is higher than array green candles
is_pocket_pivot_red := show_red_pps
plotshape(is_pocket_pivot_green ? total_green_volume : na, title="Pocket Pivot", color=colorGreen, style=shape.cross, size=size.tiny, location=location.absolute)
plotshape(is_pocket_pivot_red ? total_red_volume : na, title="Inverted Pocket Pivot", color=colorRed, style=shape.cross, size=size.tiny, location=location.absolute)
is_pocket_pivot_green := false
is_pocket_pivot_red := false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment