Volume Imbalance

Status
Not open for further replies.

prolab

New member
anyone has a script for "Volume Imbalance"? this seems to be an easy one to write? just closing prices w/o wick but what do I know about writing.

This seems to be a really powerful toll

Untitled-picture.png
code...
 
Thanks. I looked at this but this is completely different. it's not your typical indicator but rather a heatmap of volume and is not part of a chart.
Your post above did not make any specific requests. If you have code, or an indicator somewhere else you've seen, please provide code and or links -- preferably both. I don't have the first clue how the indicator you took a screen shot of was created, or even which platform the screen grab is from. Your admonition that it is simply closing prices without wicks doesn't make a great deal of sense when trying to convert the idea to code.

I don't mean to sound offensive, but it is far easier to help the more we know more about what you want rather than a vague and fuzzy picture.

happy trading,
mashume
 
This is the pine script from Trading view, however, this one includes FVG and script which is already included in another thread here on the forum https://usethinkscript.com/threads/fair-value-gap-fvg-for-thinkorswim.11103/page-3#post-113720

But what I am asking for is the small "price gap" between the candle bodies called "volume imbalance"

Thank you!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Vulnerable_human_x
//@version=5
indicator("ICT - GAPS, BPR, Volume & Price Imbalance", shorttitle = "ICT - Imbalances", overlay=true)

//Volume Imbalance
showbullvi = input.bool(true, "Show Bullish Volume Imbalance", group="Volume Imbalance")
showbearvi = input.bool(true, "Show Bearish Volume Imbalance", group="Volume Imbalance")
bullimbalance = input.color(color.new(#00e640,10), "Bullish VI Color", group="Volume Imbalance", inline="1")
bearimbalance = input.color(color.new(#e30000,10), "Bearish VI Color", group="Volume Imbalance", inline="1")
viMaxBoxSet = input.int(defval=15, title='Maximum Box Displayed', minval=1, maxval=100, group="Volume Imbalance", tooltip='Minimum = 1, Maximum = 100')
extendvibox = input.bool(false, title="Extend Unmitigated VI Boxes", group="Volume Imbalance")
//Gaps
showgaps = input.bool(true, "Show Gaps in Price", group="GAP")
gapcolor = input.color(color.new(#fff176, 85), "GAP Color", group="GAP")
gapsMaxBoxSet = input.int(defval=15, title='Maximum Box Displayed', minval=1, maxval=100, group="GAP", tooltip='Minimum = 1, Maximum = 100')
extendgapbox = input.bool(true, title="Extend Unmitigated GAP Boxes", group="GAP")
//FVG and BPR
plotFVG = input.bool(true, "FVG BOX", inline="18", group="FVG/BPR")
plotBPR = input.bool(true, "BPR BOX", inline="18", group="FVG/BPR")
fvgBullColor = input.color(defval=color.new(color.green, 85), title='Bullish FVG',inline="1", group="FVG/BPR")
fvgBearColor = input.color(defval=color.new(color.red, 85), title='Bearish FVG',inline="1", group="FVG/BPR")
bprBullColor = input.color(defval=color.new(#41ed47, 70), title='Bullish BPR',inline="2", group="FVG/BPR")
bprBearColor = input.color(defval=color.new(#d83d3d, 70), title='Bearish BPR',inline="2", group="FVG/BPR")
var float bprprecision = input.float(0.00005,"BPR Precision",step=0.00001, group="FVG/BPR")
fvgMaxBoxSet = input.int(defval=10, title='Maximum Box Displayed', minval=1, maxval=100, group="FVG/BPR", tooltip='Minimum = 1, Maximum = 100')
extendfvgbox = input.bool(true, title="Extend Unmitigated FVG/BPR Boxes", group="FVG/BPR")
//Box Styling
BoxBorder = input.string(defval=line.style_solid, title='Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group="Box Style", tooltip='To disable border, set Border Width below to 0')
BorderTransparency = input.int(defval=60, title='Border Box Transparency', minval=0, maxval=100, group="Box Style")
filterMitBOX = input.bool(defval=false, title='Mitigated Box Color', group="Box Style")
mitBOXColor = input.color(defval=color.new(color.gray, 80), title='Mitigated Box Color', group="Box Style", tooltip='Set Transparency to 0 to make mitigated Boxes disappear')
plotBoxLabel = input.bool(defval=true, title='Plot Label', group="Box Style")
BoxLabelColor = input.color(defval=color.rgb(161, 163, 171), title='Label Color', group="Box Style")
BoxLabelSize = input.string(defval=size.tiny, title="Label Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], group="Box Style")


var int _fvg = 2
//Box Labels
var string _fvgLabel = "FVG"
var string _plus = "+"
var string _minus = "-"
var string _empty = ""
var string _bprLabel = "BPR"

var box[] _bearBoxesFVG = array.new_box()
var box[] _bullBoxesFVG = array.new_box()
var box[] _gapsboxes = array.new_box()
var box[] _bullishvi = array.new_box()
var box[] _bearishvi = array.new_box()
_controlBox(_boxes, _high, _low, _type) =>
if array.size(_boxes) > 0
for i = array.size(_boxes) - 1 to 0 by 1
_box = array.get(_boxes, i)
_boxLow = box.get_bottom(_box)
_boxHigh = box.get_top(_box)
_boxRight = box.get_right(_box)
if (filterMitBOX and _type == _fvg)
if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)
else
if _type == _fvg
box.set_bgcolor(_box, mitBOXColor)
box.set_border_color(_box, mitBOXColor)
else
if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)


//Volume Imbalance
//Bullish Volume Imbalance
if showbullvi and open > close[1] and low <= high[1] and close > close[1] and open > open[1]
box _bullboxVI = na
_bullboxVI := box.new(left=bar_index-1, top=math.min(open,close), right=bar_index+1, bottom=math.max(close[1],open[1]), bgcolor=bullimbalance,border_style=BoxBorder, border_color=color.new(bullimbalance,BorderTransparency), text=plotBoxLabel?"VI+":na, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bullishvi) > viMaxBoxSet
box.delete(array.shift(_bullishvi))
array.push(_bullishvi, _bullboxVI)
//Bearish Volume Imbalance
if showbearvi and open < close[1] and open < open[1] and high >= low[1] and close < close[1] and close < open[1]
box _bearboxVI = na
_bearboxVI := box.new(left=bar_index-1, top=math.min(close[1],open[1]), right=bar_index+1, bottom=math.max(open,close), bgcolor=bearimbalance,border_style=BoxBorder, border_color=color.new(bearimbalance,BorderTransparency),text=plotBoxLabel?"VI-":na, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bearishvi) > viMaxBoxSet
box.delete(array.shift(_bearishvi))
array.push(_bearishvi, _bearboxVI)

//Gap
if (showgaps and high[1] < low) or (showgaps and low[1] > high)
box _gaps = na
if high[1] < low
_gaps := box.new(left=bar_index-1, top=low, right=bar_index, bottom=high[1], bgcolor=gapcolor, border_color=color.new(gapcolor,BorderTransparency), text=plotBoxLabel?"GAP+":na,border_style=BoxBorder, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
else if low[1] > high
_gaps := box.new(left=bar_index-1, top=low[1], right=bar_index, bottom=high, bgcolor=gapcolor, border_color=color.new(gapcolor,BorderTransparency), text=plotBoxLabel?"GAP-":na,border_style=BoxBorder, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_gapsboxes) > gapsMaxBoxSet
box.delete(array.shift(_gapsboxes))
array.push(_gapsboxes, _gaps)


//fvg
isFvgUp(index) =>
(low[index] > high[index + 2] and low[index + 1] <= high[index + 2] and high[index + 1] >= low[index])
isFvgDown(index) =>
(high[index] < low[index + 2] and high[index] >= low[index + 1] and high[index +1] >= low[index +2])

//Balanced Price Range
isbprdown (index) =>
low [index + 3] > high[index] and low[index + 3] < low[index + 2] and low[index + 3] < close[index + 3] and high[index + 2] >= close[index + 2] and high[index + 1] <= ((open [index + 1]) + (open[index + 1] * bprprecision)) and (low[index + 2] >= ((open[index + 2]) - (open[index + 2] * bprprecision)) or (low[index + 2] >= ((close[index + 2]) - (close[index + 2] * bprprecision))))
isbprup (index) =>
high [index + 3] < low[index] and high[index + 3] > high[index + 2] and high[index + 3] > close[index + 3] and low[index + 2] <= close[index + 2] and low[index + 1] >= ((open [index + 1]) - (open[index + 1] * bprprecision)) and (high[index + 2] <= ((open[index + 2]) + (open[index + 2] * bprprecision)) or (high[index + 2] <= ((close[index + 2]) + (close[index + 2] * bprprecision))))


//Bullish FVG Box Plotting
if isbprup(0) and isFvgUp(0)
box _bullboxFVG = na
if plotBPR
_bullboxFVG := box.new(left=bar_index-3, top=low[0], right=bar_index, bottom=high[3], bgcolor=bprBullColor, border_color=color.new(bprBullColor,BorderTransparency), border_style=BoxBorder, border_width=1,
text=plotBoxLabel ? _bprLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
else if plotFVG
_bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index, bottom=high[2], bgcolor=fvgBullColor, border_color=color.new(fvgBullColor,BorderTransparency), border_style=BoxBorder, border_width=1,
text=plotBoxLabel ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bullBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bullBoxesFVG))
array.push(_bullBoxesFVG, _bullboxFVG)
else if isFvgUp(0)
box _bullboxFVG = na
if plotFVG
_bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index, bottom=high[2], bgcolor=fvgBullColor, border_color=color.new(fvgBullColor,BorderTransparency), border_style=BoxBorder, border_width=1,
text=plotBoxLabel ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bullBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bullBoxesFVG))
array.push(_bullBoxesFVG, _bullboxFVG)
//Bearish FVG Box Plotting
if isbprdown(0) and isFvgDown(0)
box _bearboxFVG = na
if plotBPR
_bearboxFVG := box.new(left=bar_index-3, top=low[3], right=bar_index, bottom=high[0], bgcolor=bprBearColor, border_color=color.new(bprBearColor,BorderTransparency), border_style=BoxBorder, border_width=1,
text=plotBoxLabel ? _bprLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
else if plotFVG
_bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index, bottom=high[0], bgcolor=fvgBearColor, border_color=color.new(fvgBearColor,BorderTransparency), border_style=BoxBorder, border_width=1,
text=plotBoxLabel ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bearBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bearBoxesFVG))
array.push(_bearBoxesFVG, _bearboxFVG)
else if isFvgDown(0)
box _bearboxFVG = na
if plotFVG
_bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index, bottom=high[0], bgcolor=fvgBearColor, border_color=color.new(fvgBearColor,BorderTransparency), border_style=BoxBorder, border_width=1,
text=plotBoxLabel ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bearBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bearBoxesFVG))
array.push(_bearBoxesFVG, _bearboxFVG)

if extendfvgbox
_controlBox(_bearBoxesFVG, high, low, _fvg)
_controlBox(_bullBoxesFVG, high, low, _fvg)
if extendgapbox
_controlBox(_gapsboxes, high, low, _fvg)
if extendvibox
_controlBox(_bullishvi, high, low, _fvg)
_controlBox(_bearishvi, high, low, _fvg)
//end of script
 
yes, I guess the code for FVG and BPR exists in other thread but what doesn't is the Volume imbalance

//Volume Imbalance

//Bullish Volume Imbalance
if showbullvi and open > close[1] and low <= high[1] and close > close[1] and open > open[1]
box _bullboxVI = na
_bullboxVI := box.new(left=bar_index-1, top=math.min(open,close), right=bar_index+1, bottom=math.max(close[1],open[1]), bgcolor=bullimbalance,border_style=BoxBorder, border_color=color.new(bullimbalance,BorderTransparency), text=plotBoxLabel?"VI+":na, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bullishvi) > viMaxBoxSet
box.delete(array.shift(_bullishvi))
array.push(_bullishvi, _bullboxVI)

//Bearish Volume Imbalance
if showbearvi and open < close[1] and open < open[1] and high >= low[1] and close < close[1] and close < open[1]
box _bearboxVI = na
_bearboxVI := box.new(left=bar_index-1, top=math.min(close[1],open[1]), right=bar_index+1, bottom=math.max(open,close), bgcolor=bearimbalance,border_style=BoxBorder, border_color=color.new(bearimbalance,BorderTransparency),text=plotBoxLabel?"VI-":na, text_halign=text.align_right, text_valign=text.align_bottom, text_size=BoxLabelSize, text_color=BoxLabelColor)
if array.size(_bearishvi) > viMaxBoxSet
box.delete(array.shift(_bearishvi))
array.push(_bearishvi, _bearboxVI)
 
anyone has a script for "Volume Imbalance"? this seems to be an easy one to write? just closing prices w/o wick but what do I know about writing.

This seems to be a really powerful toll

Untitled-picture.png
code...

Have you seen this post before? Someone linked to some images of what looks like to me is a volume imbalance indicator but unfortunately there’s no more info as to where it originates from.

https://usethinkscript.com/threads/...hart-setup-for-thinkorswim.11618/#post-111152

I wish someone could write such an indicator even if it’s not reflecting the real buy/sell volume because TOS doesn’t have access to this data but looking at the example i linked to, it’s still possible to make a good presentation of where imbalances are present. Let’s hope someone can come up with a smart idea of how to build one.
 
Last edited by a moderator:
Solution
Status
Not open for further replies.

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
208 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top