The code below lets you select one of your own watchlists if you type their names in ParamList.
When there are many symbols, some tend to print on top of each other. Using a smaller label font size helps separate them, but sometimes some are still on top of each other.
I have used modulus to randomly shift every nth label to the right. As you move the "Shift nth label" slider, some of the labels shift to the right and you can often identify each line plotted.
This works but is not elegant - perhaps someone can write some code so that every symbol that would have printed on top of another will instead print to the right?
/// Relative Performance.afl by AmiBroker.com
/// to be found in Charts window -> Basic Charts
_SECTION_BEGIN("watchlist");
WatchlistName = ParamList("WatchList", "0 Portfolio,1 Buys,2 Watch,3 Supertrenders,5 Exchange Rates,6 Indices World,10 Metals Precious,22 Cryptos,23,24");
category = categoryWatchlist;
listnum = CategoryFind( WatchListName, category );
TickerList = CategoryGetSymbols( category, listnum);
_SECTION_END();
_SECTION_BEGIN("FontSize");
fontsize = Param("Label font size", 7, 4, 10, 1 );
_SECTION_END();
_SECTION_BEGIN("RelativePerformance");
fvb = Status( "firstvisiblebar" );
for( i = 0; ( symbol = StrExtract( Name() + "," + TickerList, i ) ) != ""; i++ )
{
fc = Foreign( symbol, "C" );
if( ! IsNull( fc[ 0 ] ) )
{
relP = 100 * ( fc - fc[ fvb ] ) / fc[ fvb ];
Plot( relP , symbol, color = colorOrange + ( ( 2 * i ) % 15 ), styleLine );
x = LastValue( BarIndex() ) + 1;
y = LastValue( relP );
//Several labels overlap. Use modulus to shift every nth label to the right.
n = Param("Shift nth label right", 2, 2, 9, 1 );
PlotTextSetFont( symbol, "Arial", fontsize, IIf( i % n == 0, x, x+3), y, GetChartBkColor(), color, -fontsize/2 );
}
}
PlotGrid( 0, colorDarkGrey );
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
_SECTION_END();