something is incorrect either on myunderstanding of selectedvalue or
it does not behave correctly. basically if the cursor is not within
the visible range, it seems to return the last barindex of the
visible bars.
i have a work around here which only works on a intraday chart.
basically you can double click on the chart to create a green
beginvalue marker. then you can change the resolution to any lower
resolution interval like 15 minute or 5 minute and click on the
Run2FocusTrigger and it will actually scroll the window to the green
marker.
i dunno why it does not go from lower resolution to higher.
_SECTION_BEGIN("runToCursor");
SetBarsRequired( sbrAll,sbrAll);
procedure ZoomToIndex( FirstBarIndex, LastBarIndex )
{
StaticVarSet( "FirstBarIndex", FirstBarIndex );
StaticVarSet( "LastBarIndex", LastBarIndex );
LastVisiblebar = Status( "LastVisibleBar" );
FirstVisibleBar= Status( "FirstVisibleBar" );
range =LastVisiblebar - FirstVisibleBar;
_TRACE("range " + NumToStr(range));
DT = DateTime();
BI = BarIndex();
_TRACE(" FirstBarIndex " + NumToStr(FirstBarIndex) + "
LastBarIndex " + NumToStr(LastBarIndex));
LastDateTime = LastValue( ValueWhen( round
((FirstBarIndex+range/2)) == BI, DT ) );
FirstDateTime = LastValue( ValueWhen( round((FirstBarIndex-
range/2)) == BI, DT ) );
_TRACE("last date time" + NumToStr( LastDateTime));
LastDateTimestr = DateTimeToStr( LastDateTime );
FirstDateTimestr = DateTimeToStr( FirstDateTime );
_TRACE("LastDateTimestr" + LastDateTimestr + " FirstDateTimestr "
+ FirstDateTimestr);
AB = CreateObject( "Broker.Application" );
AW = AB.ActiveWindow;
AW.ZoomToRange( FirstDateTimestr, LastDateTimestr );
}
Run2FocusTrigger = ParamTrigger( "Run to Cursor", "Run" );// zoom out
by ZoomIncrement
if ( Run2FocusTrigger ){
_TRACE(NumToStr(SBI));
ZoomToIndex(BeginValue( BarIndex() ), EndValue( BarIndex() ) );
}
_SECTION_END();