Fullname in Relative Performance

I have still a problem with fullname in the relativer performance function

_SECTION_BEGIN("Relative Performance");
_N( TickerList = ParamStr("Tickers", "846900,965881,B14000,CBK100,873403,850605,858872,875773,B40811") );
NumBars = 20;
fvb = Status("firstvisiblebar");
Plot( 100 * ( C - C[ fvb ] ) / C[ fvb ],FullName(), colorBlue );
for( i = 0; ( symbol = StrExtract( tickerlist, i ) ) != ""; i++ )
{
 fc = Foreign( symbol, "C" );

 if( ! IsNull( fc[ 0 ] ) )
 {
   Plot( 100 * ( fc - fc[ fvb ] )/ fc[ fvb ], symbol, colorLightOrange + ( (2*i) % 15 ), styleLine );
 }
}
PlotGrid( 0, colorYellow );
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
_SECTION_END();

to see the full name at the top of the different stocks how can I change here
or add the fullname? And where can I set the time frame for example at the beginning of the year till now? Thanks for any advise.

@Munichtrader, please see this KB article (in your case replace symbols with full names):

How to add symbol labels to Relative Performance chart

See this other thread to get ideas how to "zoom" to a specific bar index (to find the start of the current year bar index probably you can use the Lookup() function with mode 1).

You may use Range Markers for marking start and end of year.
For Fullname at top use SetForeign and FullName().

Here is example

_SECTION_BEGIN("Relative Performance");
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
_N( TickerList = ParamStr("Tickers", "846900,965881,B14000,CBK100,873403,850605,858872,875773,B40811") );

bi = BarIndex();
fvb = Max(0,BeginValue(bi));// Status("firstvisiblebar");
lvb = EndValue(bi);
barcond = bi >= fvb AND bi <= lvb;

Plot( IIf( barcond, 100 * ( C - C[ fvb ] ) / C[ fvb ], Null),FullName(), colorBlue );

for( i = 0; ( symbol = StrExtract( tickerlist, i ) ) != ""; i++ )
{
    //fc = Foreign( symbol, "C" );
    SetForeign( symbol );
		fc = C;

		if( ! IsNull( fc[ 0 ] ) )
		{
			Plot( IIf( barcond, 100 * ( fc - fc[ fvb ] ) / fc[ fvb ], Null), FullName() /*+ ", " + symbol*/, colorLightOrange + ( ( 2 * i ) % 15 ), styleLine );
		}
    RestorePriceArrays();
}
PlotGrid( 0, colorYellow );
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
_SECTION_END();

145

5 Likes

thanks. Great Tool.:smiley:

Sorry to consult but I make a mess. I do something very wrong because I paste code and put the tickers of my market server and I can not paint the relative behavior of 4/5 indices.

Sin%20t%C3%ADtulo

_SECTION_BEGIN("Relative Performance");
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
_N( TickerList = ParamStr("Tickers", "") );

bi = BarIndex();
fvb = Max(0,BeginValue(bi));// Status("firstvisiblebar");
lvb = EndValue(bi);
barcond = bi >= fvb AND bi <= lvb;

Plot( IIf( barcond, 100 * ( C - C[ fvb ] ) / C[ fvb ], Null),FullName(), colorBlue );

for( i = 0; ( symbol = StrExtract( tickerlist, i ) ) != ""; i++ )
{
    //fc = Foreign( symbol, "C" );
    SetForeign( symbol ); 
		fc = C;

		if( ! IsNull( fc[ 0 ] ) )
		{
			Plot( IIf( barcond, 100 * ( fc - fc[ fvb ] ) / fc[ fvb ], Null), FullName() /*+ ", " + symbol*/, colorLightOrange + ( ( 2 * i ) % 15 ), styleLine );
		}
    RestorePriceArrays();
}
PlotGrid( 0, colorYellow );
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
_SECTION_END();

The tickers have to exist in your DB and with actual historical data!

Forgive so much insistence !!! I'm useless. I am not able to put 3 indexes comparing relatively in% for marking start and end of year. ![ and the name is painted. The tíckers, as you can see, are in my database.
regards
Sin%20t%C3%ADtulo

like this but marking start and end of year
Regards
Captura

1 Like

You have spaces after comma in your ticker list.
Also I said

So if foreign symbol has missing data at start then it won't plot

Here is modified version taking care of spaces in ticker list as well as taking care of missing data at start.

_SECTION_BEGIN("Relative Performance");
/// Role model code by www.amibroker.com at:
/// @link https://www.amibroker.com/kb/2015/08/29/how-to-add-symbol-labels-to-relative-performance-chart/
/// modified version taking care of spaces in tickerlist
/// as well as plotting symbols having missing data at start
/// as well as possibility of using range markers
/// https://forum.amibroker.com/t/fullname-in-relative-performance/8260/9
/// modified by fxshrat@gmail.com
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
_N( TickerList = ParamStr("Tickers", "") );
fontsize = Param("Label font size", 9, 4, 30, 1 );

bi = BarIndex();
fvb = FirstVisibleValue(bi);
fvb = Max(fvb,BeginValue(bi));
lvb = Min(LastValue(bi),EndValue(bi));
barcond = bi >= fvb AND bi <= lvb;

sc = 100 * ( C - C[ fvb ] ) / C[ fvb ];
Plot( IIf( barcond, sc, Null), FullName(), color = colorBlue );

x = lvb + 1;
y = sc[lvb];
PlotTextSetFont( Name(), "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2 );

for ( i = 0; ( symbol = StrExtract( tickerlist, i ) ) != ""; i++ ) {
    sym = StrTrim(symbol, " "); 
    SetForeign( sym, 1 ); 
		NOT_null = ! IsNull( C );		
		fc = SparseCompress(NOT_null, C);
		// if foreign symbol has missing data at start 
		// then go to next available bar
		maxbar = Max(NullCount(fc), fvb);		
		fc = IIf(barcond, 100 * ( fc - fc[ maxbar ] ) / fc[ maxbar ], Null);
		fc = SparseExpand(NOT_null, fc);
		Plot( fc, FullName() /*+ ", " + sym*/, color = colorLightOrange + ( ( 2 * i ) % 15 ), styleLine );

		y = fc[lvb];
		PlotText( sym, x, y, GetChartBkColor(), color, -fontsize/2 );
    RestorePriceArrays();
}

PlotGrid( 0, colorYellow );
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
_SECTION_END();

It works.

As you can see in picture.
11

And if you want to mark range then you have to double click on chart to activate range markers for start and end date.
12

4 Likes

Yes, Yes, Yes!!!!
You have been able to enlighten a blind man !!!!
Thank you very much!
Captura|690x242