quick question/ request to @fxshrat refering back to the topic/thread.
Anchoring Chart on the left side ( referring here since thread is locked)
how would i go about having
multiple chart windows to be anchored per the code written by @fxshrat before in
the above topic/thread.
I am thinking iterating through the visible chart windows ?
but I have no idea how to do that. if you be so kind as to guide me
thank you
original code:
dt = DateTime();
bi = BarIndex();
dn = DateNum();
SetBarsRequired( 86400 / Max(1, Interval()) );
procedure ZoomToBarIndex( fbi, lbi ) {
/// posted to discussion thread here
/// @link https://forum.amibroker.com/t/anchoring-chart-on-the-left-side/7988/7
gid = StrFormat( "%g_%s", GetChartID(), Name() );
static_fbi = Nz( StaticVarGet( "ZOOM_FIRST_BI_" + gid ) );
static_lbi = Nz( StaticVarGet( "ZOOM_LAST_BI_" + gid ) );
if ( static_fbi != fbi || static_lbi != lbi ) {
StaticVarSet( "ZOOM_FIRST_BI_" + gid, fbi );
StaticVarSet( "ZOOM_LAST_BI_" + gid, lbi );
tmfrm = Max(1, Interval());
fdt = LastValue( ValueWhen( bi == fbi, DateTimeAdd( dt, 0, tmfrm ) ) );
fdt_str = DateTimeToStr( fdt, 3 );
ldt = LastValue( ValueWhen( bi == lbi, DateTimeAdd( dt, 1, tmfrm ) ) );
ldt_str = DateTimeToStr( ldt, 3 );
AB = CreateObject( "Broker.Application" );
AW = AB.ActiveWindow;
AW.ZoomToRange( fdt_str, ldt_str );
}
}
newday = dn != Ref( dn, -1 );
fbi = LastValue( ValueWhen( newday, bi ) );
lbi = LastValue( bi );
if ( ParamToggle( "Chart Anchoring", "OFF|ON", 1 ) )
ZoomToBarIndex( fbi, lbi );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "Price", colorDefault, styleBar );
//cnahor
// original code by fxshrat amibroker forum
/// posted to discussion thread here
/// @link https://forum.amibroker.com/t/anchoring-chart-on-the-left-side/7988/7
tInterval = Interval();
dt = DateTime();
bi = BarIndex();
dn = DateNum();
if( tInterval < 86401){
SetBarsRequired( 86400 / Max(1, tInterval) ); // seconds in a day / interval gives the number of bars required
}
procedure ZoomToBarIndex( fbi, lbi , blankBars ) {
gid = StrFormat( "%g_%s", GetChartID(), Name() );
static_fbi = Nz( StaticVarGet( "ZOOM_FIRST_BI_" + gid ) ); // check if the static var exists else null
static_lbi = Nz( StaticVarGet( "ZOOM_LAST_BI_" + gid ) ); // check if the static var exists else null
//refresh / rezoom if the fbi is moved before
//start of day and each time new data is updated
if ( static_fbi != fbi || static_lbi != lbi ) { // check if the staticvars values which are bar index
StaticVarSet( "ZOOM_FIRST_BI_" + gid, fbi ); // assign the staticvar to anchor bar
StaticVarSet( "ZOOM_LAST_BI_" + gid, lbi ); // asssgin the var to the current last barindex
tmfrm = Max(1, Interval());
fdt = LastValue( ValueWhen( bi == fbi, DateTimeAdd( dt, 0, tmfrm ) ) );
fdt_str = DateTimeToStr( fdt, 3 );
ldt = LastValue( ValueWhen( bi == lbi, DateTimeAdd( dt, blankBars , tmfrm ) ) );
ldt_str = DateTimeToStr( ldt, 3 );
// create ole object and zoom on the active
// active window objet. user guide "AmiBroker's OLE Automation Object Model"
AB = CreateObject( "Broker.Application" );
AW = AB.ActiveWindow;
AW.ZoomToRange( fdt_str, ldt_str );
}
}
swZoomOn = ParamToggle( "Chart Anchoring", "OFF|ON", 0 );
blankBars = 5;
newday = dn != Ref( dn, -1 );
fbi = LastValue( ValueWhen( newday, bi ) );
lbi = LastValue( bi );
if( tInterval < 86401){
if ( swZoomOn ){
ZoomToBarIndex( fbi, lbi , blankBars );
}
}
-- only the top left , active window is anchoring.
