# Add a Moving Average to Volume on a "All in One" Price Chart

Hello

How do I add a moving average to the volume on a “all in one” chart ( Basic Charts - Price - All in One )

``````
_SECTION_BEGIN("Price");

GraphXSpace = 10;

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

_SECTION_END();

_SECTION_BEGIN("Volume");

Color = ParamColor("Color", ColorRGB( 128, 128, 192 ) );
Plot( Volume, _DEFAULT_NAME(), ColorBlend( Color, GetChartBkColor(), 0.5  ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram  ), 6 );

_SECTION_END();
``````

Use drag-drop ! It will write (append) formula for you !

http://www.amibroker.com/guide/h_dragdrop.html

1 Like

Hi Tomasz

I had already tried that. I'm trying to plot the moving average actually on top of the volume bars at the bottom of the chart. Am I doing something wrong? I selected styleownscale

Ozzie

`styleOwnScale` as name says means that given plot uses its OWN independent scale. If you want moving average on some other plot, you need to use SAME scale for both (input data and its average).

Since this “all-in-one” chart uses standard right hand scale for price, you need to use `styleLeftAxisScale` for both volume and its moving average.

``````// right axis chart
Plot( C, "Price", colorDefault, styleCandle );
// left axis charts
Plot( V, "Volume", colorGrey50, styleHistogram | styleThick | styleLeftAxisScale );
Plot( MA( V, 40 ), "MAVolume", colorGreen, styleLeftAxisScale );
``````

If you use `styleOwnScale` it will cause separate independent scaling for each plot which is not what you want.

But generally easier solution is to add Volume as separate pane and then overlay any averages on it.

1 Like

I want Price, Open Interest & Volume and SMA Volume 10 on the same chart pane. Am able to get volume and it's 10 period sma with your above suggested edit. But the scale of Volume is taking the whole chart where as i want the volume to only use about 1/3rd to 1/4th of the chart panel.

Pic TV

is of Trading View where i am able to achieve this

and Pic AB
"new users allowed only 1 pic per message"
is of Amibroker were i am unable to achieve this.

Attached is the relevant code as well. Earlier, when the axis were all to the right, using the value of 5 was able to shorten the volume bars to 1/3rd of the pane but the volume sma was not aligned. Now that the volume sma is aligned, the volume bars is taking the whole pane inspite of putting the value of 5.

``````_SECTION_BEGIN("V");
Plot( MA( V, 10 ), "MAV", colorLightGrey, styleLeftAxisScale, 5 );
Plot( V, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorGrey40 ), ParamColor("Down Color", colorGrey50 ) ), ParamStyle( "Style", styleArea | styleLeftAxisScale), 5 );
_SECTION_END();
``````

Pic AB

@Maxis You can do it for example like this:

``````_SECTION_BEGIN("V1");

HPercent = Param("Percentage of pane height", 30, 1, 100, 1);
MAV = MA(V, Param("MAV Period", 10, 1, 100, 1));

Plot( C, "Close", colorDefault, styleCandle );
Plot(V, "Volume", colorBlueGrey, styleHistogram|styleOwnScale|styleNoLabel, 0, HighestVisibleValue(V)*100/HPercent, 0, 0, 2);
Plot(MAV, "MAV", colorGrey50, styleLine|styleOwnScale|styleNoLabel, 0, HighestVisibleValue(MAV)*100/HPercent, 0, 0, 2);

_SECTION_END();
``````

2 Likes

And a slightly changed formula for better scaling. Basic charts --> Volume(color) + MA(V, 10) in a separate pane - for a comparison:

``````_SECTION_BEGIN("V1");

HPercent = Param("Percentage of pane height", 30, 1, 100, 1);
MAV = MA(V, Param("MAV Period", 10, 1, 100, 1));
Vmax =  HighestVisibleValue(V)*100/HPercent;
Vmin = LowestVisibleValue(V);

Plot( C, "Close", colorDefault, styleCandle );
Plot(V, "Volume", colorBlueGrey, styleHistogram|styleOwnScale, Vmin, Vmax, 0, 0, 2);
Plot(MAV, "MAV", colorGrey50, styleLine|styleOwnScale, Vmin, Vmax, 0, 0, 2);

_SECTION_END();
``````

I also think, that in general it is a better idea to use a separate pane for plotting volume.

5 Likes

Thanks for the share.
The second code works better than the fisrt as in the second one, the scales are same for Volume and its average.

Yes, the first one was written before 2 a.m. - which is not the perfect time for such tasks

You can modify (change colors, styles etc.) or expand the second one to suit your needs. I just wanted to show, how it can be done in general, because volume is not enclosed in any range (for instance 0 - 1 or 0 - 100) like some other indicators ...

3 Likes

Thanks Pal. I have many more to keep you up for the whole night, but let me first scratch my knees or pull my hair before i come back to you.

Enjoy the weekend, Cheers,

@Maxis I know, that your reply was supposed to be funny, but actually it's not, especially taking into account, that you have joined this forum 17 hours ago and bahave as if you were here with us since the beginning ...

1 Like

Here is a variation or "resizing" all-in-one price/volume plots (no MA line but it is easy to add)

1 Like

@Milosz Sorry i couldn't arouse your humor, but i have been doing just what i had mentioned.
I may be new to this forum but certainly not to the world of coding or trading. Have plenty of Mql ideas to convert.
Keying away at past 2am is a norm for me.

Just need a little bit more help with this one please. I have got the volume and a ribbon at the bottom of the screen. How can I move the volume up a bit so that the volume plots just above the ribbon and not on top of it?
Thanks

``````_SECTION_BEGIN("Volume & Ribbon");

//Volume
SetBarFillColor( IIf( Close>=Open, ColorRGB(197,226,201), ColorRGB(235,204,203 )) );
Plot(Volume, _DEFAULT_NAME(),colorwhite,styleArea|styleOwnScale,4);

//Ribbon
Color = IIf(Close>MA(Close,200),ColorRGB(0,192,0),colorRed);
Plot ( 2, "", Color, styleArea |styleNoLabel | styleOwnScale , -0.05, 200 );

_SECTION_END();
``````

Why don't you just specify the Z-Order in Ribbon and have it plot on top of the Volume bars?
I don't think moving the Volume Plot "up" itself is as easy as it sounds

``````Plot ( 2, "", Color, styleArea |styleNoLabel | styleOwnScale , 0, 100, 0, 5, 1 );
``````

The reason I said it isn't so easy is because you are using StyleOwnScale and min=4 in Volume, which is like 1/4 of the pane scale.

If you really want to move Volume up, then you can get the HighestVisibleValue() of Volume and multiple it by a factor ( 4 in your case ), while using some constant for the negative part to have a fixed beginning scale.

``````//Volume
SetBarFillColor( IIf( Close>=Open, ColorRGB(197,226,201), ColorRGB(235,204,203 )) );

hhvv = HighestVisibleValue( V );
minv = -hhvv/6;
// minv var you can adjust because a large spike may move the scale a bit
// compute a constant derived from the average Vol of the symbol etc

Plot(Volume, _DEFAULT_NAME(),colorwhite,styleArea|styleOwnScale, minv, hhvv*4);

//Ribbon
Color = IIf(Close>MA(Close,200),ColorRGB(0,192,0),colorRed);
Plot ( 2, "", Color, styleArea |styleNoLabel | styleOwnScale , 0, 100);
``````

<---- this is 4, large denominator -->

6 Likes

Hi Travick

Hey that's actually really good. Thanks for that. I didn't want to alter the z order because it meant that any low volume bar was hidden.

Appreciate the help mate

Thanks

2 Likes