Sorry why on Amibroker I can't display the watchlist symbol as shown

Sorry, why on Amibroker I can't display the watchlist symbol list as shown. Thanks

_SECTION_BEGIN("Relative Performance_modified");
/// Code source:
/// @link https://www.amibroker.com/kb/2015/08/29/how-to-add-symbol-labels-to-relative-performance-chart/
/// Added sorting in Chart title and Exploration output:
/// @link https://forum.amibroker.com/t/customize-title-chart/22313/4
/// by AmiBroker.com and fxshrat@gmail.com
WatchlistName = ParamStr("Insert WatchList Name", "List 0");
wlnumber = CategoryFind(WatchlistName, cat = categoryWatchlist); 
tickerlist = Name() + "," + CategoryGetSymbols(cat, wlnumber);
fontsize = Param("Label font size", 10, 4, 30, 1 );
bi = BarIndex();
fbr = Status("firstbarinrange");
Filter = Status("barinrange");
explore = Status("action") == actionExplore;
fvb = IIf(explore, LastValue(ValueWhen(fbr,bi)), Status("firstvisiblebar"));
mat = Matrix(StrCount(tickerlist, ",")+1, 2);
rownum = MxGetSize(mat, 0);
for ( i = 0; ( symbol = StrExtract(TickerList, i ) ) != ""; i++ ) {
	fc = Foreign( symbol, "C" ); 
	idx = Max(NullCount(fc), fvb);
	if (! IsNull(fc[ idx ])) {
		relP = 100 * (fc - fc[ idx ]) / fc[ idx ]; 		
		mat[i][0] = SelectedValue(relP); 
		mat[i][1] = i; 		
		x = LastValue(bi) + 1;
		y = LastValue(relP);
		VarSet("color"+i, colorLightOrange + ((2*i)%15));      
		AddColumn(relP, "RS-"+symbol, 1.2, color = Varget("color"+i));     
		Plot(relP, "\n"+symbol, color, styleNoLabel | styleNoTitle);        
		PlotTextSetFont(symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2);
	}
}
//
PlotGrid( 0, colorYellow );
Param_dt = FirstVisibleValue(DateTime());
_N(Title = StrFormat( "WL(%g): %s, {{NAME}} - Start Date: %s, Relative Performance [%%]: {{VALUES}}", 
						wlnumber, WatchlistName, DateTimeToStr(Param_dt, 1))); 
SetChartOptions(0, chartWrapTitle);
//
mat = MxSortRows(mat, False, 0);
//_TRACE(MxToString(mat));
for ( i = 0; i < rownum; i++ ) {
	val = mat[i][0];	n = mat[i][1];
	if (! IsNull(val)) {		
		sym = StrExtract(tickerlist, n);
		color = EncodeColor(Nz(Varget("color"+n)));
		Title += StrFormat("\n%s %s: %g", color,sym,val);		
	}
}

14

Unfortunately your question does not specify what you have problems with and what really does not work for you. You have to be specific. The screenshot shows that it is working fine. Please follow this advice: How to ask a good question

1 Like

Now I got it, you are talking about these tickers in the chart window.
image

The ticker is displayed, it is only one, because in your chart is only the ^DJI displayed.
image

I tried to get it working and assumed it has to do with this line of code at the beginning. In this line needs to be written your desired watchlist and as second entry the default list.

WatchlistName = ParamStr("Insert WatchList Name", "List 0");

Yet I was not able to get it running as intended. If I insert the default "Relative Performance"-Code in a new chart, it shows multiple symbols.
image

No, there does not need to be written anything in code.
It is ParamStr function and you just have to open Param window (CTRL+R) to insert your filled watchlist.

The Param clearly says "Insert Watchlist name". Insert.
As you can see I insert existing Watchlist being filled with symbols having quotes.
So another important requirement. Symbols have to have quotes not just names.

8


Warning: do not choose watchlists with thousands of symbols.
I added limit of 200 in below code.
Plot function internally allows 500 plots anyway. If it is more then inefficiency warning will show up.

_SECTION_BEGIN("Relative Performance_modified");
/// Code source:
/// @link https://www.amibroker.com/kb/2015/08/29/how-to-add-symbol-labels-to-relative-performance-chart/
/// Added sorting in Chart title and Exploration output:
/// @link https://forum.amibroker.com/t/customize-title-chart/22313/4
/// by AmiBroker.com and fxshrat@gmail.com
/// !!! INSERT FILLED WATCHLIST IN PARAM WINDOW !!! PARAM  WINDOW -> CTRL+R
WatchlistName = ParamStr("Insert WatchList Name", "List 0");
wlnumber = CategoryFind(WatchlistName, cat = categoryWatchlist); 
tickerlist = Name() + "," + CategoryGetSymbols(cat, wlnumber);
fontsize = Param("Label font size", 10, 4, 30, 1 );
bi = BarIndex();
fbr = Status("firstbarinrange");
Filter = Status("barinrange");
explore = Status("action") == actionExplore;
fvb = IIf(explore, LastValue(ValueWhen(fbr,bi)), Status("firstvisiblebar"));
sym_num = StrCount(tickerlist, ",")+1;
mat = Matrix(sym_num, 2);
rownum = MxGetSize(mat, 0);
last_bar = BarCount-1;

if ( sym_num < 200 ) {
	for ( i = 0; ( symbol = StrExtract(TickerList, i ) ) != ""; i++ ) {
		fc = Foreign( symbol, "C" ); 
		idx = Max(Min(NullCount(fc),last_bar), fvb);
		if (! IsNull(fc[ idx ])) {
			relP = 100 * (fc - fc[ idx ]) / fc[ idx ]; 		
			mat[i][0] = SelectedValue(relP); 
			mat[i][1] = i; 		
			x = LastValue(bi) + 1;
			y = LastValue(relP);
			VarSet("color"+i, colorLightOrange + ((2*i)%15));      
			AddColumn(relP, "RS-"+symbol, 1.2, color = Varget("color"+i));     
			Plot(relP, "\n"+symbol, color, styleNoLabel | styleNoTitle);        
			PlotTextSetFont(symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2);
		}
	}
	//
	PlotGrid( 0, colorYellow );
	Param_dt = FirstVisibleValue(DateTime());
	_N(Title = StrFormat( "WL(%g): %s, {{NAME}} - Start Date: %s, Relative Performance [%%]: {{VALUES}}", 
							wlnumber, WatchlistName, DateTimeToStr(Param_dt, 1))); 
	SetChartOptions(0, chartWrapTitle);
	//
	mat = MxSortRows(mat, False, 0);
	//_TRACE(MxToString(mat));
	for ( i = 0; i < rownum; i++ ) {
		val = mat[i][0];	n = mat[i][1];
		if (! IsNull(val)) {		
			sym = StrExtract(tickerlist, n);
			color = EncodeColor(Nz(Varget("color"+n)));
			Title += StrFormat("\n%s %s: %g", color,sym,val);		
		}
	}
} else Title = EncodeColor(colorRed)+ "TOO MANY SYMBOLS. CHOOSE DIFFERENT WATCHLIST.";
_SECTION_END();
2 Likes

Thanks fxshrat for clearing up my misunderstanding. Now I get it working.

1 Like

Here is a version that does not stop entire plot if watchlist has too many symbols.
Now it just stops at set max_num value of line 10.
Again if you set max_num to e.g. 500 then Plot will show internal efficiency warning.
So do not complain about error again. It is a internal AB warning (not error).

_SECTION_BEGIN("Relative Performance_modified");
/// Code source:
/// @link https://www.amibroker.com/kb/2015/08/29/how-to-add-symbol-labels-to-relative-performance-chart/
/// Added sorting in Chart title and Exploration output:
/// @link https://forum.amibroker.com/t/customize-title-chart/22313/4
/// by AmiBroker.com and fxshrat@gmail.com
/// !!! INSERT FILLED WATCHLIST IN PARAM WINDOW !!! PARAM  WINDOW -> CTRL+R
WatchlistName = ParamStr("Insert WatchList Name", "List 0");
fontsize = Param("Label font size", 10, 4, 30, 1 );
max_num = 200;// change at your own risk.
cat = categoryWatchlist;
wlnumber = CategoryFind(WatchlistName, cat); 
tickerlist = Name() + "," + CategoryGetSymbols(cat, wlnumber);
bi = BarIndex();
fvb = Status("firstvisiblebar");
sym_num = StrCount(tickerlist, ",")+1;
mat = Matrix(Min(sym_num, max_num), 2);
rownum = MxGetSize(mat, 0);
last_bar = BarCount-1;

for ( i = 0; ( symbol = StrExtract(TickerList, i ) ) != "" AND i < max_num; i++ ) {
	fc = Foreign( symbol, "C" ); 
	idx = Max(Min(NullCount(fc),last_bar), fvb);
	if (! IsNull(fc[ idx ])) {
		relP = 100 * (fc - fc[ idx ]) / fc[ idx ]; 		
		mat[i][0] = SelectedValue(relP); 
		mat[i][1] = i; 		
		x = LastValue(bi) + 1;
		y = LastValue(relP);
		VarSet("color"+i, colorLightOrange + ((2*i)%15));      
		AddColumn(relP, "RS-"+symbol, 1.2, color = Varget("color"+i));     
		Plot(relP, "\n"+symbol, color, styleNoLabel | styleNoTitle);        
		PlotTextSetFont(symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2);
	}
}
//
PlotGrid( 0, colorYellow );
Param_dt = FirstVisibleValue(DateTime());
_N(Title = StrFormat( "WL(%g): %s, {{NAME}} - Start Date: %s, Relative Performance [%%]: {{VALUES}}", 
						wlnumber, WatchlistName, DateTimeToStr(Param_dt, 1))); 
SetChartOptions(0, chartWrapTitle);
//
mat = MxSortRows(mat, False, 0);
//_TRACE(MxToString(mat));
for ( i = 0; i < rownum; i++ ) {	
	val = mat[i][0];	n = mat[i][1];
	if (! IsNull(val)) {		
		sym = StrExtract(tickerlist, n);
		color = EncodeColor(Nz(Varget("color"+n)));
		Title += StrFormat("\n%s %s: %g", color,sym,val);		
	}
}
_SECTION_END();
3 Likes

Thank you very much Mr. Fxshrat, you are the best in AFL coding and very generous. Gbu

No, the best programmer is the AmiBroker chief developer.
All others are second best by a long distance.
But what's important is that you can solve issues without being dependent on others.
So in the end it's mostly just a matter of gaining knowledge and hard work. The rest is talent.

5 Likes

Hello Sir, can the Title be added OHLCV and ROC ?. Thanks

_SECTION_BEGIN("Relative Performance_modified");
/// Code source:
/// @link https://www.amibroker.com/kb/2015/08/29/how-to-add-symbol-labels-to-relative-performance-chart/
/// Added sorting in Chart title and Exploration output:
/// @link https://forum.amibroker.com/t/customize-title-chart/22313/4
/// by AmiBroker.com and fxshrat@gmail.com
/// !!! INSERT FILLED WATCHLIST IN PARAM WINDOW !!! PARAM  WINDOW -> CTRL+R
WatchlistName = ParamStr("Insert WatchList Name", "List 0");
fontsize = Param("Label font size", 10, 4, 30, 1 );
max_num = 200;// change at your own risk.
cat = categoryWatchlist;
wlnumber = CategoryFind(WatchlistName, cat); 
tickerlist = Name() + "," + CategoryGetSymbols(cat, wlnumber);
bi = BarIndex();
fvb = Status("firstvisiblebar");
sym_num = StrCount(tickerlist, ",")+1;
mat = Matrix(Min(sym_num, max_num), 2);
rownum = MxGetSize(mat, 0);
last_bar = BarCount-1;

for ( i = 0; ( symbol = StrExtract(TickerList, i ) ) != "" AND i < max_num; i++ ) {
	fc = Foreign( symbol, "C" ); 
	idx = Max(Min(NullCount(fc),last_bar), fvb);
	if (! IsNull(fc[ idx ])) {
		relP = 100 * (fc - fc[ idx ]) / fc[ idx ]; 		
		mat[i][0] = SelectedValue(relP); 
		mat[i][1] = i; 		
		x = LastValue(bi) + 1;
		y = LastValue(relP);
		VarSet("color"+i, colorLightOrange + ((2*i)%15));      
		AddColumn(relP, "RS-"+symbol, 1.2, color = Varget("color"+i));     
		Plot(relP, "\n"+symbol, color, styleNoLabel | styleNoTitle);        
		PlotTextSetFont(symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2);
	}
}
//
PlotGrid( 0, colorYellow );
Param_dt = FirstVisibleValue(DateTime());
_N(Title = StrFormat( "WL(%g): %s, {{NAME}} - Start Date: %s, Relative Performance [%%]: {{VALUES}}", 
						wlnumber, WatchlistName, DateTimeToStr(Param_dt, 1))); 
SetChartOptions(0, chartWrapTitle);
//
mat = MxSortRows(mat, False, 0);
//_TRACE(MxToString(mat));
for ( i = 0; i < rownum; i++ ) {	
	val = mat[i][0];	n = mat[i][1];
	if (! IsNull(val)) {		
		sym = StrExtract(tickerlist, n);
		color = EncodeColor(Nz(Varget("color"+n)));

		//Title += StrFormat("\n%s %s: %g", color,sym,val);	
    
               Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, 
                Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, 
                SelectedValue( ROC( C, 1 )) ));
	
	}
}
_SECTION_END();

Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

Mr. @Tomasz or Mr @Beppe can help me?. Please :pray:

You have one closing bracket too many.
Also you should sum up via += operator.

//.. Code Snippet

mat = MxSortRows(mat, False, 0);
Title += "\nSelected Date: {{DATE}}";
//_TRACE(MxToString(mat));
for ( i = 0; i < rownum; i++ ) {	
	val = mat[i][0];	n = mat[i][1];
	if (! IsNull(val)) {		
		sym = StrExtract(tickerlist, n);
		color = EncodeColor(Nz(Varget("color"+n)));

		//Title += StrFormat("\n%s %s: %g", color,sym,val);

		SetForeign(sym);
		Title += StrFormat("\n%s%s - O: %g, H: %g, L: %g, C: %g (%.1f%%) V: %1.0f", 
		         color, sym, O, H, L, C, SelectedValue( ROC( C, 1 )), V );	
		RestorePriceArrays();	
	}
}

//...

33

1 Like

You are very kind and the Best AFL Programmer. Thanks and Gbu

I'm repeating:

.....

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.