Zoom range does not show blank bars at the right end of the chart

Blank bars variable is added to begin bar index and in spite of that there are no blank bars at the end of the chart.
BeginBarIndex = ValueWhen( LastValue(BarIndex())- BarIndex() > NumberOfBars + BlankBars, BI );
What I'm i missing?

_SECTION_BEGIN("ZoomRange");
/// code works for native EOD bars as well as daily bars created out of intraday data
/// @link https://forum.amibroker.com/t/chart-set-timeframe-from-1-1-2018-till-now/10534/2
/// @link https://www.amibroker.com/members/library/formula.php?id=1215
/// sample code by fxshrat@gmail.com

Version(6.20); // minimum AB version being required
zoom_activate = ParamToggle( "Activate Zoom", "OFF|ON", 1 ); // 1 means activated by default
//Days= 252 ; // no of days as look back
Days= Param("Days",252,160, 300, 1) ; // no of days as look back
end_date = ParamDate( "End Date", Now(1), 2);
zoom_trigger = ParamTrigger( "Zoom to Date Range", "CLICK HERE" ); // Zoom is activated only after clicking zoom_trigger

if ( zoom_activate ) {
	//SetBarsRequired( -2, -2 );
	BlankBars 		= 5; // Enter the number of Blank Bars you have defined under Preferences- Charting.
	NumberOfBars	= Days;
	BI 				= BarIndex();
	dt = DateTime();
	BeginBarIndex 	= ValueWhen( LastValue(BarIndex())- BarIndex() > NumberOfBars + BlankBars, BI );
	BeginDateTime 	= dt[LastValue( BeginBarIndex - BI[0] + 2 )];

	start_dt = DateTimeFormat("%Y-%m-%d", BeginDateTime);	
	Lookedup_end_dt = Lookup(dt, end_date, -1);
	end_dt = DateTimeFormat("%Y-%m-%d", Lookedup_end_dt);	
	if ( zoom_trigger ) {		
		AB = CreateObject( "Broker.Application" );
		AW = AB.ActiveWindow;
		AW.ZoomToRange( start_dt, end_dt );
	}
}
_SECTION_END();

Please follow this advice: How to ask a good question
Please send a screenshot with illustration of what you are after.

Sorry, Should have posted snapshots earlier.
I am trying to make the zoom range view have 5 bars space at the right end of the chart like in the normal view.

(Normal View)


Zoom Range View, Code snippet in original post

Blank area is only available for the FUTURE (where there are no quotes available).

There are two ways to get blank bars artificially:

  1. programmatically by using Null for bars that you don't want to see
NoDisplay = BarIndex() >= LastValue( BarIndex ) - 20;

Plot( IIF( NoDisplay, Null, Close ), "Price", colorDefault );
  1. using Bar Replay feature (just set the playback position to the last position you want to see)

https://www.amibroker.com/guide/w_barreplay.html

Hello erukumk,

I use AB 6.49.1 and Windows 11 23H2 22631.3085.

To "create" right space in active chartwindow after "OLE .ZoomToRange method" follow these steps :

  1. Define your Tools - Preferences - Charting - [ Blank bars in right margin (default): 10 ] or your desired bars count [ 5 ]

  2. Study this AB KB

http://www.amibroker.org/userkb/2011/03/

  1. Add following code next to AW.ZoomToRange( start_dt, end_dt ) inside if { ... }
WSHShell = CreateObject( "WScript.Shell" );
WSHShell.AppActivate( "AmiBroker" );
WSHShell.Sendkeys( "{PGDN}" );

Your code should be completed to :

_SECTION_BEGIN( "ZoomRange" );

/// code works for native EOD bars as well as daily bars created out of intraday data
/// @link https://forum.amibroker.com/t/chart-set-timeframe-from-1-1-2018-till-now/10534/2
/// @link https://www.amibroker.com/members/library/formula.php?id=1215
/// sample code by fxshrat@gmail.com

Version( 6.20 ); // minimum AB version being required
zoom_activate = ParamToggle( "Activate Zoom", "OFF|ON", 1 ); // 1 means activated by default
//Days= 252 ; // no of days as look back
Days = Param( "Days", 252, 160, 300, 1 ) ; // no of days as look back
end_date = ParamDate( "End Date", Now( 1 ), 2 );
zoom_trigger = ParamTrigger( "Zoom to Date Range", "CLICK HERE" ); // Zoom is activated only after clicking zoom_trigger

if( zoom_activate )
{
    //SetBarsRequired( -2, -2 );
    BlankBars 		= 5; // Enter the number of Blank Bars you have defined under Preferences- Charting.
    NumberOfBars	= Days;
    BI 				= BarIndex();
    dt = DateTime();
    BeginBarIndex 	= ValueWhen( LastValue( BarIndex() ) - BarIndex() > NumberOfBars + BlankBars, BI );
    BeginDateTime 	= dt[LastValue( BeginBarIndex - BI[0] + 2 )];

    start_dt = DateTimeFormat( "%Y-%m-%d", BeginDateTime );
    Lookedup_end_dt = Lookup( dt, end_date, -1 );
    end_dt = DateTimeFormat( "%Y-%m-%d", Lookedup_end_dt );

    if( zoom_trigger )
    {
        AB = CreateObject( "Broker.Application" );
        AW = AB.ActiveWindow;
        AW.ZoomToRange( start_dt, end_dt );

        WSHShell = CreateObject( "WScript.Shell" );
        WSHShell.AppActivate( "AmiBroker" );
        WSHShell.Sendkeys( "{PGDN}" );
    }
}

SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( Close, "", colorDefault, styleBar | styleNoTitle, 0, 0, 0, 0, 5 );

_SECTION_END();

best regards,
Peter

2 Likes

Thanks for the reply, will try it.