How to generate volume/dollar bars?

Posted By: Dalla

How to generate volume/dollar bars? - 01/06/19 20:28

I know we can generate custom bars with the bar function.
I tried creating volume bars using variants of the code below, but it doesnīt look like expected. Atleast the plot does not reflect bars that contain atleast a volume of 500.
Can we create volume/dollar bars?

Code:
static int vol = 0;

int bar(vars Open, vars High, vars Low, vars Close)
{
	vol += marketVol();
	if (vol >= 500) {
		vol = 0;
		return 1;
	}
	return 4;
}

Posted By: jcl

Re: How to generate volume/dollar bars? - 01/09/19 08:13

Depends on the volume, Your code would work if marketVol is the volume of the last quote. If it is something different or no volume at all, modify the code or generate other types of bars.
Posted By: Dalla

Re: How to generate volume/dollar bars? - 01/09/19 08:46

Consider the following code, where marketVol does contain the volume

Code:
// Custom Bars
static int vol = 0;

int bar(vars Open, vars High, vars Low, vars Close)
{
	//printf("nVol %i", vol);
	vol += marketVol();
	if (vol >= 500) {
		vol = 0;
		return 1;
	}
	return 4;
}

function run() {
	set(TICKS);
	StartDate = 20150101;
	EndDate = 20150115;
	set(PLOTNOW);
	BarPeriod = 10;
	vars Close = series(priceClose());
	plot("Vol",marketVol(),NEW,RED);
}



This leads to the attached (zoomed in) chart, where all bars have a volume less than 500. I would expect them to be > 500 ?

Attached picture Screenshot 2019-01-09 at 09.36.04.png
Posted By: jcl

Re: How to generate volume/dollar bars? - 01/09/19 19:18

Why do you think they have a volume less than 500? I see nowhere their volume.
Posted By: Dalla

Re: How to generate volume/dollar bars? - 01/10/19 04:29

Did you check the attached file? The volume is plotted below the price chart
Posted By: jcl

Re: How to generate volume/dollar bars? - 01/10/19 06:39

I see only a marketVol plot. Plot the bar volume instead. You can get it with a tick function and the same formula that you used for your bars.
Posted By: Dalla

Re: How to generate volume/dollar bars? - 01/10/19 07:01

OK, there is something I'm missing here.
How do I get the bar volume? And what is it that I'm plotting now? (that I thought was the bar volume)
Posted By: jcl

Re: How to generate volume/dollar bars? - 01/10/19 07:05

I don't know what it is. It depends on your broker. But it is not the volume of your bars.
Posted By: Dalla

Re: How to generate volume/dollar bars? - 01/10/19 08:09

This is FXCM data, so as per the manual, itīs "Tick frequency in live data and in historical data." I still donīt understand what is the difference between this and the volume of the bar?
Posted By: jcl

Re: How to generate volume/dollar bars? - 01/10/19 08:50

The tick frequency is the number of quotes per minute.
© 2024 lite-C Forums