Fixed starting point for charts

There is always a way... in AmiBroker.

Since you talk about this page's code here.... you just have to change view things.

Things I modified are...
From this one

fvb = Status( "firstvisiblebar" );

to this one

Param_dt = ParamDate("Select Date", "2019-01-01", 2);
bi = BarIndex();
fvb = Status( "firstvisiblebar" );
fvb = Nz(Lookup(bi, Param_dt), fvb);

Adding line

bi_cond = bi >= fvb;

To be used within loop (to plot only since start date)... so we get as a whole....

/// @link http://www.amibroker.com/kb/2015/08/29/how-to-add-symbol-labels-to-relative-performance-chart/
/// modification to set start date
/// @link https://forum.amibroker.com/t/fixed-starting-point-for-charts/15488/1
Version(6.20);
_N( TickerList = ParamStr( "Tickers", "^DJI,MSFT,GE" ) );
Param_dt = ParamDate("Select Date", "2019-01-01", 2);
fontsize = Param("Label font size", 10, 4, 30, 1 );
///
bi = BarIndex();
fvb = Status( "firstvisiblebar" );
fvb = Nz(Lookup(bi, Param_dt), fvb);
bi_cond = bi >= fvb;
///
for ( i = 0; ( symbol = StrExtract( Name() + "," + TickerList, i ) ) != ""; i++ ) 
{
    fc = Foreign( symbol, "C" );
    if ( ! IsNull( fc[ 0 ] ) ) 
    {
        relP = 100 * ( fc - fc[ fvb ] ) / fc[ fvb ];
        x = LastValue( bi ) + 1;
        y = LastValue( relP );
        //
        Plot( IIf( bi_cond, relP, Null), symbol, color = colorLightOrange + ( ( 2 * i ) % 15 ), styleLine );
        PlotTextSetFont( symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2 );
    }
}
///
PlotGrid( 0, colorYellow );
_N(Title = StrFormat( "{{NAME}} - Start Date: %s, Relative Performance [%%]: {{VALUES}}", DateTimeToStr(Param_dt, 1))); 

6 Likes