Getting the bar width in pixels

Something like Status("pxbarwidth") returning the number of pixels in a chart's current bar width would be really nice. Also, Status("pxbarspacing") to reveal the number of pixels between each price bar.

I'm drawing entry/target/price lines for interactive real-time trading. I can get around not having these by having the lines occupy a pct of the chart's width (in pixels), but there could be many other applications of this which would benefit script programming. The information is there. Just need a native AFL function call to get at the values.

BarSpacing can be calculated with existing functions.

bi = BarIndex();
lvb = LastVisibleValue(bi);
fvb = FirstVisibleValue(bi);
slvb = Status("lastvisiblebar");
pxcw = Status("pxchartwidth")+5;

function pxBarSpacing() {	
	/// https://forum.amibroker.com/t/getting-the-bar-width-in-pixels/26303
	/// Spacing from center
	/// to center of each bar
	global lvb, fvb, bi, slvb, pxcw;
	bars = lvb-fvb+1;
	blankmargin = slvb-lvb+1;
	result = pxcw / (bars+blankmargin-1);
	return result;
}

printf("pxBarSpacing: %g", pxBarSpacing());
3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.