Can we draw EquiVolume Chart in AmiBroker :)

colion

Active Member
#14
how Can we draw EquiVolume Chart in AmiBroker
EquiVolume bars require the ability to change the time axis. This is not possible in AmiBroker. Until enough people indicate that they want this the program will not be changed. Until then programs such as Metastock are the only alternative.
 

pratapvb

Well-Known Member
#16
Hi friends..
I have been using MetaStock till now.. And most of my trading is done on the basis of EquiVolume or CandleVolume charts, which are inbuilt in MS.

For those who do not about these types of charts, I am enclosing them here.

This is Equivolume Chart of Reliance Industries. I basically shows a direct relationship between price and volume.



And this one is CandleVolume chart of RIL.


Now I want to shift to AmiBroker for its speed and efficiency.
But the problem is that I don't know how to draw EquiVolume chart in AB.
I will be very thankful if any one can help me out.
I think there might be some code to do the same. But I have not been able to find the code.

Thanks to all of you
Sunil
I don't know whether this helps....though ami does not have equivolume in the sense that it changes the width of the bar to span the time as per volume, it has Constant Volume Bars (CVB) which has non-linear time axis and each bars has constant volume as specified. It works best with tick data but in you have 1min data it will be approx as it will not split the 1min bar when the volume crosses
 
#17
Try this afl it has both equivolume as well as candlevolume. Credit goes to person who coded it not me.

regds,
S

// Aron Pipa
// January 2014
ChartType = ParamList ( "Chart Type", "CandleVolume,EquiVolume" );
Plot( C, "", 39, styleBar | styleNoDraw );
Maxy = Status( "axismaxy" );
Miny = Status ( "axisminy" );
pxchartheight = Status ( "pxchartheight" );
pxchartbottom = Status( "pxchartbottom" );
pxchartwidth = Status ( "pxchartwidth" );
pxchartleft = Status( "pxchartleft" );
fvb = Status ( "firstvisiblebar" );
Lvb = Status ( "lastvisiblebar" );

function yConvert( Value )
{
return pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight / (
Maxy - Miny ) );
}

MinVolume = LowestVisibleValue( Volume );
MinVolume = Max ( Minvolume, 1 );
//printf ( "Min Visibe Bar volume = %.f\n", Minvolume );

sigma = 0 ;

for ( i = BarCount - 1 ; i > fvb - 1 ; i -- )
{

ratio = Volume / MinVolume;
sigma += ratio;
}

GfxSelectPen( colorBlack );

Space = 5; // space between candles
visiblebars = Lvb - fvb + 1;
totalspace = Visiblebars * space;

unitpx = ( pxchartwidth - totalSpace ) / sigma; // pixel
LastbarRatio = Volume [BarCount -1] / MinVolume;
delta = unitpx * Lastbarratio / 2;
start = pxchartleft + ( BarCount - fvb - 1 ) * pxchartwidth / Visiblebars +
delta;
Chg = C - O;

for ( i = BarCount - 1 ; i >= fvb && start > 0 ; i -- )
{

ratio = Volume / MinVolume;
width = unitpx * ratio ;
width = Min ( width , pxchartwidth / 5 ); // limit max bar width in pixel to chartwidh/5

if ( ChartType == "CandleVolume" )
{
x = start - width / 2;
}

y1 = yConvert ( High );
y2 = yConvert ( Low );


if ( ChartType == "CandleVolume" )
{
GfxMoveTo ( x, y1 );
GfxLineTo( x, y2 );
}

x1 = start - width;
x2 = start ;

if ( ChartType == "CandleVolume" )
{
y1 = yConvert ( Open );
y2 = yConvert ( Close );
}

fillcolor = IIf ( Chg > 0 , colorWhite, colorBlack );
GfxSelectSolidBrush( fillcolor );
Hgt = y2 - y1;
if ( Hgt == 0 )
Hgt = 1;

y2 = y1 + Hgt;
GfxRectangle( x1, y1, x2, y2 );

start = x1 - Space;
// printf ( "\n%.f\t %.f px" , i, hgt );
}

Title = Charttype;
RequestTimedRefresh( 1 );
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
 
#19
Hello,

would appreciate if someone can code shapes and text above selected boxes. I am enclosing a sample chart and the respective code for the main chart,

Thanks in advance,
IB

Code:
_SECTION_BEGIN("Start");

	ChartType	=ParamToggle("Chart Type"," EquiVolume | CandleVolume",1);
	UpColor		=ParamColor("Up Close",colorLightGrey);
	DnColor		=ParamColor("Dn Close",colorGrey50);

	Plot(Close,"",39,styleBar|styleNoDraw);

	MinVolume	=LowestVisibleValue( Volume );
	MaxVolume	=HighestVisibleValue( Volume );
	Chg		= C > Ref(Close,-1);

_SECTION_END();



	Maxy			=Status( "axismaxy" );
	Miny			=Status ( "axisminy" );
	pxchartheight	=Status ( "pxchartheight" );
	pxchartbottom	=Status( "pxchartbottom" );
	pxchartwidth	=Status ( "pxchartwidth" );
	pxchartleft	=Status( "pxchartleft" );

	fvb				=Status ( "firstvisiblebar" );
	Lvb				=Status ( "lastvisiblebar" );
	Space			= Param("Bar-Spsce",1,-10,5,1);

function yConvert( Value )
{
    return  pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight / (Maxy - Miny ) );
}
	MinVolume	=LowestVisibleValue( Volume );
	MinVolume	=Max ( Minvolume, 1 );

	sigma		=0 ;

for ( i = BarCount - 1 ; i > fvb - 1  ; i -- )
{
    ratio		=Volume[i] /  MinVolume;
    sigma		+=ratio;
}


	visiblebars	=Lvb - fvb + 1;
	totalspace	=Visiblebars * space;

	unitpx			=( pxchartwidth - totalSpace ) / sigma; // pixel
	LastbarRatio	=Volume [BarCount -1] / MinVolume;
	delta			=unitpx * Lastbarratio / 2;
	start			= pxchartleft + ( BarCount - fvb - 1 )  * pxchartwidth / Visiblebars + delta;

//--------------------------------------------------------------------------------------------

for ( i = BarCount - 1 ; i >= fvb && start > 0  ; i -- )
{
    ratio		=Volume[i] / MinVolume;
    width		=unitpx * ratio ;
    width		=Min ( width , pxchartwidth / 5 ); // limit max bar width in pixel to chartwidh/5

if ( ChartType == 0 )
    {
	x	=start - (width / 2);
    }

    y1	=yConvert ( High[i] );
    y2	=yConvert ( Low[i] );

if ( ChartType == 0 )
    {
        GfxMoveTo(x,y1);
        GfxLineTo(x,y2);
    }

    x1	=start - width;
    x2	=start ;

if ( ChartType == 0 )
    {
	y1	=yConvert ( Open[i] );
	y2	=yConvert ( Close[i] );
    }
//--------------------------------------------------------------------------------------------

	PenColor		=IIf(Chg[i] > 0,UpColor,DnColor);
	GfxSelectPen( colorBlack,1 );
	GfxSelectSolidBrush( PenColor);

//--------------------------------------------------------------------------------------------
	Hgt	=(y2 - y1);
	if(Hgt == 0)
	Hgt			=1;

    y2	=(y1 + Hgt);
	GfxRoundRect(x1,y1,x2,y2,3,3);

    start	=x1 - Space;
}

RequestTimedRefresh( 1 );


_SECTION_BEGIN("HEading");

	Change = Close-Ref(Close,-1);

	BrushCol	=ParamColor("BrushColor",colorDarkGrey);
	TxtCol		=ParamColor("TxtColor",colorWhite);

	YC = TimeFrameGetPrice( "C", inDaily, -1 );
	DD = Prec( C - YC, 2 );
	xx = Prec( ( DD / YC ) * 100, 2 );

	GfxSelectSolidBrush( BrushCol );
	GfxRectangle(1,25,1640,1);

	GfxSetTextAlign(6);
	GfxSetBkMode(0);
	GfxSetTextColor(TxtCol);
	GfxSelectFont( "Futura",8,700,False );

	GfxTextOut(
	Name()+" ..... "+
	Interval(2)+
	" ..... Date: "+Date()+
	" ..... Open:  "+WriteVal(Open,5.2)+
	" ..... Hi:  "+WriteVal(High,5.2)+
	" ..... Lo:  "+WriteVal(Low,5.2)+   
	" ..... Close:  "+WriteVal(Close,2.2)+
	" ..... Change:  " + WriteVal(DD,5.2)+
	" ..... " + xx + "%",Status("pxwidth")/2,Status("pxheight")/125);

_SECTION_END();
 

Attachments

#20
Hello,

would appreciate if someone can code shapes and text above selected boxes. I am enclosing a sample chart and the respective code for the main chart,

Thanks in advance,
IB

Code:
_SECTION_BEGIN("Start");

	ChartType	=ParamToggle("Chart Type"," EquiVolume | CandleVolume",1);
	UpColor		=ParamColor("Up Close",colorLightGrey);
	DnColor		=ParamColor("Dn Close",colorGrey50);

	Plot(Close,"",39,styleBar|styleNoDraw);

	MinVolume	=LowestVisibleValue( Volume );
	MaxVolume	=HighestVisibleValue( Volume );
	Chg		= C > Ref(Close,-1);

_SECTION_END();



	Maxy			=Status( "axismaxy" );
	Miny			=Status ( "axisminy" );
	pxchartheight	=Status ( "pxchartheight" );
	pxchartbottom	=Status( "pxchartbottom" );
	pxchartwidth	=Status ( "pxchartwidth" );
	pxchartleft	=Status( "pxchartleft" );

	fvb				=Status ( "firstvisiblebar" );
	Lvb				=Status ( "lastvisiblebar" );
	Space			= Param("Bar-Spsce",1,-10,5,1);

function yConvert( Value )
{
    return  pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight / (Maxy - Miny ) );
}
	MinVolume	=LowestVisibleValue( Volume );
	MinVolume	=Max ( Minvolume, 1 );

	sigma		=0 ;

for ( i = BarCount - 1 ; i > fvb - 1  ; i -- )
{
    ratio		=Volume[i] /  MinVolume;
    sigma		+=ratio;
}


	visiblebars	=Lvb - fvb + 1;
	totalspace	=Visiblebars * space;

	unitpx			=( pxchartwidth - totalSpace ) / sigma; // pixel
	LastbarRatio	=Volume [BarCount -1] / MinVolume;
	delta			=unitpx * Lastbarratio / 2;
	start			= pxchartleft + ( BarCount - fvb - 1 )  * pxchartwidth / Visiblebars + delta;

//--------------------------------------------------------------------------------------------

for ( i = BarCount - 1 ; i >= fvb && start > 0  ; i -- )
{
    ratio		=Volume[i] / MinVolume;
    width		=unitpx * ratio ;
    width		=Min ( width , pxchartwidth / 5 ); // limit max bar width in pixel to chartwidh/5

if ( ChartType == 0 )
    {
	x	=start - (width / 2);
    }

    y1	=yConvert ( High[i] );
    y2	=yConvert ( Low[i] );

if ( ChartType == 0 )
    {
        GfxMoveTo(x,y1);
        GfxLineTo(x,y2);
    }

    x1	=start - width;
    x2	=start ;

if ( ChartType == 0 )
    {
	y1	=yConvert ( Open[i] );
	y2	=yConvert ( Close[i] );
    }
//--------------------------------------------------------------------------------------------

	PenColor		=IIf(Chg[i] > 0,UpColor,DnColor);
	GfxSelectPen( colorBlack,1 );
	GfxSelectSolidBrush( PenColor);

//--------------------------------------------------------------------------------------------
	Hgt	=(y2 - y1);
	if(Hgt == 0)
	Hgt			=1;

    y2	=(y1 + Hgt);
	GfxRoundRect(x1,y1,x2,y2,3,3);

    start	=x1 - Space;
}

RequestTimedRefresh( 1 );


_SECTION_BEGIN("HEading");

	Change = Close-Ref(Close,-1);

	BrushCol	=ParamColor("BrushColor",colorDarkGrey);
	TxtCol		=ParamColor("TxtColor",colorWhite);

	YC = TimeFrameGetPrice( "C", inDaily, -1 );
	DD = Prec( C - YC, 2 );
	xx = Prec( ( DD / YC ) * 100, 2 );

	GfxSelectSolidBrush( BrushCol );
	GfxRectangle(1,25,1640,1);

	GfxSetTextAlign(6);
	GfxSetBkMode(0);
	GfxSetTextColor(TxtCol);
	GfxSelectFont( "Futura",8,700,False );

	GfxTextOut(
	Name()+" ..... "+
	Interval(2)+
	" ..... Date: "+Date()+
	" ..... Open:  "+WriteVal(Open,5.2)+
	" ..... Hi:  "+WriteVal(High,5.2)+
	" ..... Lo:  "+WriteVal(Low,5.2)+   
	" ..... Close:  "+WriteVal(Close,2.2)+
	" ..... Change:  " + WriteVal(DD,5.2)+
	" ..... " + xx + "%",Status("pxwidth")/2,Status("pxheight")/125);

_SECTION_END();

Hi,

This is a much better version of equivolume than what I posted, visually. Thanks for the share.
Request you to please share the volume and spread afl also.

Regards,
S
 

Similar threads