Hi,
As an illustration, when a chart is zoomed in, the number of visible bars is small (eg, 10 bars are showing) so the number of pixels required to draw the width of each bar is large. On the other end of the spectrum, when a chart is zoomed out, the number of visible bars is substantial (eg, 1000 bars are showing) so the number of pixels required to draw each bar's width is minimal.
The right bar margin appears to be controlled by the number of "bars." This means the right bar margin increases when the chart is zoomed in, and decreases when the chart is zoomed out. I'd like to specify a constant pixel width for the right bar margin...but alas, I've been unsuccessful so far.
Here's my latest attempt:
function ConvertPixelsToBars( value )
{
// get extents of chart in "bars" and "pixels"
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxchartleft = Status("pxchartleft");
pxchartwidth = Status("pxchartwidth");
// get pixels per bar
barsOnChart = lvb - fvb + 1;
pixsOnChart = pxchartwidth - pxchartleft;
barsPerPix = barsOnChart/pixsOnChart;
barOutput = round( value * barsPerPix );
return barOutput;
}
barMargin = ConvertPixelsToBars(50);
SetChartOptions( 1, chartHideQuoteMarker, chartGridMiddle, 0, 0, barMargin );
Plot( C, "", colorDefault, styleCandle );
_TRACE( "DEBUG 50 pixels in bars: " + barMargin );
Any ideas?