Can we draw EquiVolume Chart in AmiBroker :)

#21
Thanks,
Here is the updated chart and the respective afl's.

1. Spread.
2. Main EquiVolume/EquiCandle chart.
3. Volume.

Code:
_SECTION_BEGIN("Start");

	spread		=	( H-L );
	Space		= Param("Bar-Space",1,-10,5,1);
	MaxSpread	=HighestVisibleValue( spread );
	MinSpread	=LowestVisibleValue( spread );

	PlotOHLC(0,spread,0,spread,"",colorLightGrey,styleCandle|styleNoDraw);

	MinVolume	=LowestVisibleValue( Volume );
	MaxVolume	=HighestVisibleValue( Volume );

	UpClose	=ParamColor("UpClose",colorLightGrey);
	DnClose	=ParamColor("DnClose",colorGrey50);


	Chg		= C > Ref(Close,-1);


	Maxy			=Status( "axismaxy" );
	Miny			=Status ( "axisminy" );
	pxchartheight	=Status ( "pxchartheight" );
	pxchartbottom	=Status( "pxchartbottom" );
	pxchartleft	=Status( "pxchartleft" );
	fvb				=Status ( "firstvisiblebar" );
	Lvb				=Status ( "lastvisiblebar" );
	pxchartwidth	=Status ( "pxchartwidth" );


function yConvert( Value )
{
    return  pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ (Maxy - Miny ) );
}
//=====================================================================================
	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;

	width = unitpx * ratio ;
	x = start - (width / 2);

//=====================================================================================
	H = Spread;
	L = 0;
//=====================================================================================

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
//=====================================================================================
//Draws the Vertical Line...

			y1	=yConvert ( H [i] );
			y2	=yConvert ( L [i] );

        GfxMoveTo(x,y1);
        GfxLineTo(x,y2);
//=====================================================================================
//Code below draws the rectangle between the Open and Close

    x1	= start - width;
    x2	= start ;

//=====================================================================================

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

    y2	= y1 + Hgt;

	PenColor		=IIf(Chg[i] > 0,UpClose,DnClose);
	GfxSelectPen( colorBlack,0 );
	GfxSelectSolidBrush( PenColor);

	GfxRoundRect(x1,y1,x2,y2,2,2);

    start	= x1 - Space;
}

RequestTimedRefresh( 1 );


_SECTION_BEGIN("Equi Volume");

	GfxSetTextAlign(6);
	GfxSetTextColor(colorBlack);
	GfxSelectFont( "Bernard MT Condensed",10,400,False );
	GfxTextOut("Spread "+"[ Candle Space  "+space+" ]",Status("pxwidth")/2,Status("pxheight")/600 );

Title="";

_SECTION_END();
Code:
_SECTION_BEGIN("Start");

	ChartType	=ParamToggle("Chart Type"," EquiVolume | CandleVolume",1);

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

	MinVolume	=LowestVisibleValue( Volume );
	MaxVolume	=HighestVisibleValue( Volume );

_SECTION_END();


_SECTION_BEGIN("UH Volume");

	VolIncr		= Param("Ultra % Volume",99,25,100,1);
	Space			= Param("Bar-Spsce",1,-10,5,1);
	pcincr			= ( MaxVolume * VolIncr ) / 100;
	ct				= ParamColor("Ultra Hi",colorCustom11);
	ExtremeVol	= ParamColor("Ultra Hi",ct) ;
	UpColor		= ParamColor("Up Close",colorLightGrey);
	DnColor		= ParamColor("Dn Close",colorGrey50);

	Chg			= Volume > pcincr;
	Chg2		= 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" );

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(Chg2[i] > 0,UpColor,DnColor);
	GfxSelectPen( colorBlack,1 );

	FillColor	=IIf(Chg[i] > 0,ExtremeVol,PenColor);
	GfxSelectSolidBrush( FillColor);

//--------------------------------------------------------------------------------------------
	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);

	GfxSetTextColor(colorBlack);
	GfxTextOut(" Volume Increase:  "+VolIncr+"% & Space"+space,Status("pxwidth")/1.98,Status("pxheight")/1.04 );


_SECTION_END();
Code:
_SECTION_BEGIN("Equi Volume");


	Plot(Volume,"",colorGrey50,styleHistogram | styleNoDraw );

	VolIncr	= Param("Ultra Vol%",99,25,100,1);
	MinVolume	= LowestVisibleValue( Volume );
	MaxVolume	= HighestVisibleValue( Volume );
	Space		= Param("Bar-Spsce",1,-10,5,1);
	ExtremeVol= ParamColor("Ultra Hi",colorCustom11) ;
	UpClose	= ParamColor("UpClose",colorLightGrey);
	DnClose	= ParamColor("DnClose",colorGrey50);

_SECTION_END();

//=====================================================================================
	pcincr		=( MaxVolume * VolIncr ) / 100;
	Chg			= Volume > pcincr;
	Chg2		= C > Ref(Close,-1);

	Maxy			=Status( "axismaxy" );
	Miny			=Status ( "axisminy" );
	pxchartheight	=Status ( "pxchartheight" );
	pxchartbottom	=Status( "pxchartbottom" );
	pxchartleft	=Status( "pxchartleft" );
	fvb				=Status ( "firstvisiblebar" );
	Lvb				=Status ( "lastvisiblebar" );
	pxchartwidth	=Status ( "pxchartwidth" );

//=====================================================================================

function yConvert( Value )
{
    return  pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ (Maxy - Miny ) );
}
//=====================================================================================
	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;

	width = unitpx * ratio ;
	x = start - (width / 2);

//=====================================================================================
	H = Volume;
	L = 0;
//=====================================================================================

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
//=====================================================================================
//Draws the Vertical Line...

			y1	=yConvert ( H [i] );
			y2	=yConvert ( L [i] );

        GfxMoveTo(x,y1);
        GfxLineTo(x,y2);
//=====================================================================================
//Code below draws the rectangle between the Open and Close

    x1	= start - width;
    x2	= start ;

//=====================================================================================

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

    y2	= y1 + Hgt;

	PenColor		=IIf(Chg2[i] > 0,UpClose,DnClose);
	GfxSelectPen( colorBlack,0 );

	FillColor	=IIf(Chg[i] > 0,ExtremeVol,PenColor);
	GfxSelectSolidBrush( FillColor);

	GfxRoundRect(x1,y1,x2,y2,2,2);

    start	= x1 - Space;
}

RequestTimedRefresh( 1 );

_SECTION_END();


_SECTION_BEGIN("HEading");

	GfxSetTextAlign(6);
	GfxSetTextColor(colorBlack);
	GfxSelectFont( "Bernard MT Condensed",10,400,False );
	GfxTextOut(" Volume Increase:  "+VolIncr+"% "+"[ Candle Space  "+space+" ]",Status("pxwidth")/2,Status("pxheight")/600 );

Title ="";

_SECTION_END();
 

Attachments

#23
Hey xsis,

I don't quite get what you mean. I have just copied and pasted both the first (Spread) and the last (Volume) into the formula editor, and and then clicked on the button in the formula editor that says 'insert indicator' and presto, it appeared in my chart.

How easy was that?

IB
 

xsis

Active Member
#24
thks @burressian!
sorry to trouble U!
my silly mistake of copy pasting :mad:
everything works fine :thumb:

btw how do u use this spread indicator?

Hey xsis,

I don't quite get what you mean. I have just copied and pasted both the first (Spread) and the last (Volume) into the formula editor, and and then clicked on the button in the formula editor that says 'insert indicator' and presto, it appeared in my chart.

How easy was that?

IB
 
#26
Hi Trash,

can you post the coding for you E-chart. I like the bar color you have applied.

Also, would you happen to know how to display icons, such as ultra volume text, above ultra volume boxes.

I am able to do this, but unfortunately, I am unable to line them up on the respective boxes. I am aware that I would have to use 'drawtext', using low graphics, or something similar.

The latter would be greatly appreciated.

Thanks in advance,
Ian
 

Similar threads