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:
defparam DRAWONLASTBARONLY = true directive ensures that drawing commands are executed only on the last bar to avoid unnecessary recalculations.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.
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