# Stocked Volume Histograme

In my data, volume is partitioned as:

`Total_Traded_Volume = Vol1 + Vol2;`

I need to plot a Stocked Volume Histograme of the `Total_Traded_Volume so I can have a sense of Total Volume Traded also the indivisual contribution of Vol1 & Vol2.

I am not able to figure out, How to plot such a chart.

Here is how the final cut looks like:

Hello
I do not have such data to test it.
But I am pretty sure it is easy. if you plot FIRST the vol1+vol2 colorblue then on the second line just plot vo2 .

``````plot(vol1+vol2 ,â€ťtotalâ€ť,colorblueâ€¦â€¦..
plot(vol2 ,â€ťvol2â€ť,colorredâ€¦â€¦..
``````

also you can use PlotOHLC() instead of plot()

Hey Neil and PanoS, I know very little about charting in AmiBroker but it looked like an interesting problem and I could not get PanoS' solution to work. But I think ZOrder may be the ticket to your solution.

http://www.amibroker.com/guide/afl/plot.html

"ZOrder - defines the Z-axis position of given plot. The default is zero. Zorder = 0 means also where the "grid" is located. So if you want to plot BEHIND the grid you need to specify negative zorder parameter.Plots are drawn in the following order:
zorder parameter takes precedence over the order of calling Plot() functions, so if z-order is set, it determines plotting order. See http://www.amibroker.com/gifs/zorder.gif
If multiple plots use the same z-order parameter they are plotted in reverse call order (ones that appear last in the code are plotted first). This rule can be changed by already existing switch graphzorder = 1 which, when specified, reverses this behaviour (so plots are drawn in call order).
"

By plotting the two data sets on top of each other using different ZOrder's you get the following type of chart.

I do not have two Volume data sets so in this example code I created a fake volume data set based upon a fraction of the real volume.

``````fraction = Param("Fraction", 0.1, 0.1, 0.9, 0.1);

TotalVolume = Volume;
FakeVol2 = fraction*V;

Plot( TotalVolume, "Vol2", colorBlue, styleHistogram | styleThick,Null,Null,0,1, 5 );
Plot( FakeVol2, "Vol1", colorRed, styleHistogram | styleThick,Null,Null,0,2,5 );

``````

I also thought the default width was fairly narrow, and to add an extra element to confuse you I have increased the width from its default setting of 1 to 5.

Good luck.

4 Likes

Since the picture in post #1 is showing a distribution plot the answer is:
Multi-dimensional array.

Either use AmiBroker's inbuilt function PriceVolDistribution()...
https://www.amibroker.com/guide/afl/pricevoldistribution.html

... or you may create a custom function of your choice too. Both options would be of type matrix.

In order to plot it you may use inbuilt low level graphics functions of AmiBroker (Gfx).
http://www.amibroker.com/guide/h_lowlevelgfx.html
Some Gfx functions of recent AmiBroker implementations are missing in upper link.
You may find them here https://www.amibroker.com/guide/a_funref.html

But I think Explorer functions XYChartSetAxis and XYChartAddPoint could work too (but I have not tested it in regards to stacked histograms).

[quote]Analysis: Exploration's XYChart now allows bar style in addition to point style.
AFL: New argument for XYChartSetAxis("chartname", "xaxis", "yaxis", chartStyle = 0 )
Note that XY chart styles are different than regular chart styles and only two are supported at the moment: 0 (default) - point style, 1 - bar style (new)[/quote]

IMO Gfx functionality provides more flexibility on what and how to plot.

In order to show/prove (since mostly people only believe if you show some visual proof) that it is possible to graph such distributions being similarly plotted as in your picture here is an example plot of horizontal stacked volume distribution using AmiBroker's Gfx functions.

3 Likes

Yes. I agree with what written above, about GFX and Zorder
But we have to give one more example with PlotOHLC() to the new users.

Note: we donot use Zorder here
We need Only 4 lines code with PlotOHLC(), and 2 lines with Plot() function

``````fraction = Param("Fraction", 0.1, 0.1, 0.9, 0.1);
TotalVolume = Volume;
FakeVol2 = fraction*V;

// Note we donot use Zorder here
// We need Only 4 lines code with PlotOHLC(), and 2 lines with Plot() function

SetBarFillColor( colorBlue) ;
PlotOHLC(FakeVol2,TotalVolume,FakeVol2,TotalVolume,"Total", colorBlue,64 );
SetBarFillColor( colorOrange);
PlotOHLC(0,FakeVol2,0,FakeVol2," Vol2", colorred,64);
``````

4 Likes