How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)

27 May 2026
0 comment
0 attachment

This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last price update moved higher or not. It solves the problem of seeing buying vs. selling pressure building during a candle rather than only after the candle closes.

if not isset($volumes[barindex]) then
$volumesUp[barindex] = 0
$volumesDn[barindex] = 0
$volumes[barindex] = 0
$lastPrice[barindex] = close
endif

if islastbarupdate then
diff=volume-$volumes[barindex]
if close>$lastPrice[barindex] then
$volumesUp[barindex]=$volumesUp[barindex]+diff
else
$volumesDn[barindex]=$volumesDn[barindex]+diff
endif
$lastPrice[barindex] = close
$volumes[barindex] = volume
endif

return $volumesUp[barindex] coloured("lightgreen") style(histogram,2), -$volumesDn[barindex] coloured("crimson") style(histogram,2)

Code Logic

  • isset($volumes[barindex]): Initializes per-bar storage the first time the script encounters a bar, preventing undefined values.
  • $volumesUp[barindex]: Accumulates the incremental volume (diff) when the latest update’s close is greater than the stored $lastPrice, treating it as up-tick volume.
  • $volumesDn[barindex]: Accumulates the incremental volume (diff) when price did not move up (i.e., close is less than or equal to $lastPrice), treating it as down/neutral tick volume.
  • $volumes[barindex]: Stores the last known volume value for the current bar so the script can compute only the newly added volume since the previous update.
  • $lastPrice[barindex]: Stores the last observed close for the bar; it is the reference used to classify the next update as up or down.
  • islastbarupdate: Ensures the accumulation logic runs only on the actively forming candle (the last bar), where volume and price are updating in real time.
  • diff = volume – $volumes[barindex]: Calculates the incremental volume added since the last update; this is the amount assigned to up-volume or down-volume.
  • return … histogram: Plots up-volume as a positive light-green histogram and down-volume as a negative crimson histogram (using – $volumesDn) so both sides are visually separated around the zero line.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/indicateur-cumulative-volume-delta/#post-261548

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
135
strategy
171

Recent Snippets

A multi indicator Dashboard for ProRealTime
indicator
This snippet creates a compact on-chart dashboard that aggregates multiple indicator states into a single, readable [...]
How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
Logo Logo
Loading...