Putting a space buffer to the left of the chart

Does anyone know if there is a method to leave a space to the left of the chart? I tried everything, including x = Ref(Price, x); and then Ref(x, -y); etc., but nothing that is really ideal or solid. I know people has done it, I just don't know how to do it myself. Thanks.

pricebar1

1 Like

@Clipper, for standard, charts, one simple way is to "hide" the required bars (the "empty" area width will change based on the chart zoom...)

The logic is similar to what is used in this KB article: Drawing indicators on a subset of visible bars.

bars = Param( "# of bars to hide at left side", 16, 1, 100, 1 );

// hlb <- hide left bars
function hlb( array, bars )
{
    local fvb, bi;
    bi = BarIndex();
    fvb = FirstVisibleValue( bi );
    // set as NULL the bars to hide...
    return ( IIf( bi >= fvb AND bi <= fvb + bars - 1, Null, array ) );
}

periods = 21; 
sma = MA( Close, periods );
bbt = BBandTop(Close, periods);
bbb = BBandBot(Close, periods);
Plot( hlb( Close, bars ), "Close", colorDefault, styleCandle);
Plot( hlb( sma, bars ), "SMA", colorRed );
Plot( hlb( bbt, bars ), "BBTop", colorBlue );
Plot( hlb( bbb, bars ), "BBBot", colorBlue );

Or a bit fancier way (if you care about displaying the values in the "hidden area):

bars = Param( "# of bars to hide at left side", 16, 1, 100, 1 );
showHiddenValues = ParamToggle("Show values in the'hidden' bars", "No|Yes", 1);

// hlb <- hide left bars
function hlb( array, bars )
{
    local fvb, bi;
    bi = BarIndex();
    fvb = FirstVisibleValue( bi );
    // set as NULL the bars to hide...
    return ( IIf( bi >= fvb AND bi <= fvb + bars - 1, Null, array ) );
}

periods = 21; 
sma = MA( Close, periods );
bbt = BBandTop(Close, periods);
bbb = BBandBot(Close, periods);
if (showHiddenValues) {
	// plot hidden arrays to get ALL the values in the title and right axis labels
	styleHide = styleNoLine;
	Plot( Close, "Close", colorDefault, styleHide);
	Plot( sma, "SMA", colorRed, styleHide );
	Plot( bbt, "BBTop", colorBlue, styleHide );
	Plot( bbb, "BBBot", colorBlue, styleHide );
	styleNoData = styleNoTitle | styleNoLabel;
}	
else // display {EMPTY} values when quote marker is on the "empty" left bars
	styleNoData = 1;  
Plot( hlb( Close, bars ), "Close", colorDefault, styleCandle | styleNoData);
Plot( hlb( sma, bars ), "SMA", colorRed, styleNoData );
Plot( hlb( bbt, bars ), "BBTop", colorBlue, styleNoData );
Plot( hlb( bbb, bars ), "BBBot", colorBlue, styleNoData );
_N(Title = StrFormat("{{NAME}} - " + FullName() +
   " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
   WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

You can also apply the function to some indicator and not to others for particular cases.
Probably you plan to use it in some other way, but I hope you'll get the idea.

3 Likes

You can simply draw left axis ON TOP. It is easy with Z-ordering. You can draw on Z-order layer > 0 and it will be drawn on TOP of charts

Plot( C, "Price", colorDefault, styleCandle );
GfxSetZOrder(1);
GfxFillSolidRect( 0, 0, 100, Status("pxchartbottom"), colorYellow );
4 Likes

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