Calculating Intraday Relative Volume Using ProBuilder

11 Aug 2019
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to calculate the relative volume of a stock compared to its average volume over a specified number of days. The relative volume is a useful indicator in trading that shows how current volume compares to past trading volumes at a similar time of day.


Period = 5 //X days averaging period
intraindex = intradaybarindex
$ivol[intraindex] = volume
$gvol[barindex] = volume
$gintraindex[barindex] = intraindex
count = 0
sum = 0
for i = barindex downto 0 do
    if $gintraindex[i]=intraindex then //found same intraday bar
        sum=sum+$gvol[i]
        count=count+1
    endif
    if count=period then break endif
next
avg = sum/period
rvol = $ivol[intraindex] / avg
return rvol
style(histogram)//$ivol[intraindex], avg coloured(255,0,0)

Explanation of the code:

  • Initialization: The code starts by setting the averaging period to 5 days. It then initializes variables to store the index of the current intraday bar, the volume of the current intraday bar, and a global volume array indexed by the bar index.
  • Volume Accumulation: A loop iterates from the current bar index down to the first bar. Inside the loop, it checks if the bar belongs to the same intraday period as the current bar. If true, it accumulates the volume of these bars and counts the number of bars considered.
  • Average Calculation: Once the count reaches the specified period (5 days in this case), the loop breaks, and the average volume is calculated by dividing the accumulated volume sum by the count.
  • Relative Volume Calculation: The relative volume (rvol) is then calculated by dividing the volume of the current intraday bar by the calculated average volume.
  • Output: The relative volume is returned and displayed as a histogram with the current intraday volume and average volume colored in red.

This code is a practical example of how to use loops, conditional statements, and arithmetic operations to analyze trading data in ProBuilder.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/relative-volume-rvol/#post-125548

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 Master
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
133
strategy
171

Recent Snippets

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 [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...