Implementing Volume by Price Analysis in ProBuilder

18 Aug 2017
0 comment
0 attachment

This code snippet demonstrates how to perform a volume by price analysis using the ProBuilder programming language. The code calculates the volume at each price level within the range of the highest and lowest prices of the current chart and visualizes this data as segments on the chart.


defparam DRAWONLASTBARONLY = true
if IsLastBarUpdate and not isset($somme[0]) then
    Y3Rmax = round(highest[barindex](high))
    Y3Rmin = round(lowest[barindex](low))
    for x = 0 to barindex-1
        xi = barindex - x
        LowR = round(low[xi])
        HighR = round(high[xi])
        for i = LowR to HighR
            if isset($X2[i]) then
                //Le prix a déjà été atteint, on ajoute 1
                $X2[i] = $X2[i]+1
            else
                //Toute première fois que le prix est atteint, on le crée
                $X2[i] = 1
                $Y2R[i] = i
            endif
        next
    next
    Somme = 0
    for i = Y3Rmin to Y3Rmax
        Somme = Somme + $X2[i]
    next
    $somme[0]=somme
    $Y3Rmax[0] = Y3Rmax
    $Y3Rmin[0] = Y3Rmin
endif

if isset($somme[0]) then
    for i = $Y3Rmin[0] to $Y3Rmax[0]
        DRAWSEGMENT(0, $Y2R[i], $X2[i], $Y2R[i])
        style(line,5)
    next
endif

return

The code snippet above is structured to execute only on the last update of the bar, ensuring that calculations are only performed once per bar, optimizing performance. Here’s a step-by-step breakdown:

  • Initialization: The defparam DRAWONLASTBARONLY = true directive ensures that drawing commands are executed only on the last bar to avoid unnecessary recalculations.
  • Volume Calculation: The script calculates the highest and lowest prices within the visible bars and iterates through each price level between these extremes. For each price level, it checks if the price has been reached before. If so, it increments the volume count; if not, it initializes the count for that price.
  • Volume Aggregation: After determining the volume at each price level, the total volume within the range is calculated.
  • Drawing Segments: Finally, if the volume data is set, the script draws segments on the chart representing the volume at each price level, with the segment length proportional to the volume.

This approach provides a visual representation of where the majority of trading activity occurred, which can be useful for identifying support and resistance levels based on volume.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/mettre-a-jour-un-tableau-sur-cloture-de-bougie/#post-202412

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...