Relative Performance customization

WhatsApp Image 2021-08-18 at 19.552229

I have 2 questions about the indicator relative performance.

The first one:
I think is not possible but I ask you for be sure, it is posible customize the colors for each ticker?

And the second one:
Whenever I compare a ticker with a watchlist I get the duplicate ticker because the one I compare is in that same watchlist, is there any way to prevent it from getting duplicated?
It would be something like that when the selected ticker is inside the comparison array it only comes out 1 time instead of twice.

My reference

Thank you very much

E.g. replace line 9 with:

tickerlist = WriteIf(InWatchList(wlnumber), "", Name() + ",") + 
            CategoryGetSymbols(cat, wlnumber);

Or remove Name()+"," completely if you do not want to include selected symbol into plot at all:

tickerlist = CategoryGetSymbols(cat, wlnumber);

Hi,

Thank you very much, works perfectly.

But I have the lastest question about the final costumization on this indicator. I'm interested in the comparation from one specific date.
For that I add the following lines to the initial code, but should be something else to add to achieve the comparison well.

line 8
Param_dt = ParamDate("Select Date", "2019-01-01", 2);
line 18
fvb = Nz(Lookup(bi, Param_dt), fvb);
line 26
I've tried with 
relP = 100 * (fc - fc[ fvb ]) / fc[ fvb ]; 

But I doesn't work as expected

Could you help me? what am I missing?

_SECTION_BEGIN("Relative Performance with order and date");
/// 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

Param_dt = ParamDate("Select Date", "2019-01-01", 2);
wlnumber   = Param( "WatchListNumber" , 34, 0, 150, 1 );
tickerlist = WriteIf(InWatchList(wlnumber), "", Name() + ",") + 
            CategoryGetSymbols(categoryWatchlist, 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"));
fvb = Nz(Lookup(bi, Param_dt), fvb);

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, colorblack );
Param_dt = FirstVisibleValue(DateTime());
_N(Title = StrFormat( "Start Date: %s, Relative Performance [%%]: {{VALUES}}\n", 
						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();

replace by

dt = DateTime();
dt_cond = dt>=Param_dt;

for ( i = 0; ( symbol = StrExtract(TickerList, i ) ) != ""; i++ ) {
		fc = IIf(dt_cond, Foreign( symbol, "C" ), Null); 

Can be removed.

Hi!

I did the changes and I see a different behaviour that this another post with (your code too)

I have recorded my screen so you can see what I mean more easily

The first seconds is the latest modification, if you see when I do the horizontal scroll is not a good behaivour (I don't know how to explain it in other words)

However, the second part of the video you can see the other link of your code and it works as you would expect

Can you see the difference?

I would love to solve it, thanks for your time.

_SECTION_BEGIN("Relative Performance with order and date");
/// 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

Param_dt = ParamDate("Select Date", "2019-01-01", 2);
wlnumber   = Param( "WatchListNumber" , 34, 0, 150, 1 );
tickerlist = WriteIf(InWatchList(wlnumber), "", Name() + ",") + 
            CategoryGetSymbols(categoryWatchlist, 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);

dt = DateTime();
dt_cond = dt>=Param_dt;

for ( i = 0; ( symbol = StrExtract(TickerList, i ) ) != ""; i++ ) {
		fc = IIf(dt_cond, Foreign( symbol, "C" ), Null);  
		idx = Max(NullCount(fc), fvb);
		if (! IsNull(fc[ idx ])) {
			relP = 100 * (fc - fc[ fvb ]) / fc[ fvb ]; 		
			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(IIf( dt_cond, relP, Null), "\n"+symbol, color, styleNoLabel | styleNoTitle);  
			Plot(relP, "\n"+symbol, color, styleNoLabel | styleNoTitle);      
			PlotTextSetFont(symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2);
		}
}
//
PlotGrid( 0, colorblack );
Param_dt = FirstVisibleValue(DateTime());
_N(Title = StrFormat( "Start Date: %s, Relative Performance [%%]: {{VALUES}}\n", 
						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();

That's a different code of different thread.

You have changed to

That's not the line of this post's code and not of this post's code of same thread and not of this post' code either and not of first post's code either.

So it should be this one instead (if you want to talk about first post):

relP = 100 * (fc - fc[ idx ]) / fc[ idx ]; 

You changed it but not me.


Alternatively you could do like this

_SECTION_BEGIN("Relative Performance with order and date");
/// 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

Param_dt = ParamDate("Select Date", "2019-01-01", 2);
wlnumber   = Param( "WatchListNumber" , 34, 0, 150, 1 );
tickerlist = WriteIf(InWatchList(wlnumber), "", Name() + ",") + 
            CategoryGetSymbols(categoryWatchlist, wlnumber);            
fontsize = Param("Label font size", 10, 4, 30, 1 );

bi = BarIndex();
fbr = Status("firstbarinrange");
Filter = Status("barinrange");
explore = Status("action") == actionExplore;

fvb = Lookup(bi, Param_dt);
fvb = IIf(explore, LastValue(ValueWhen(fbr,bi)), fvb);
bi_cond = bi >= fvb;

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 = IIf(bi_cond, 100 * (fc - fc[ idx ]) / fc[ idx ], Null); 		
		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(IIf( dt_cond, relP, Null), "\n"+symbol, color, styleNoLabel | styleNoTitle);  
		Plot(relP, "\n"+symbol, color, styleNoLabel | styleNoTitle);      
		PlotTextSetFont(symbol, "Arial", fontsize, x, y, GetChartBkColor(), color, -fontsize/2);
	}
}
//
PlotGrid( 0, colorblack );
Param_dt = FirstVisibleValue(DateTime());
_N(Title = StrFormat( "Start Date: %s, Relative Performance [%%]: {{VALUES}}\n", 
						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

Oh my apologies, the last code you posted does not give any problems, it works as expected.

As a curiosity, I see that it has an AddColum type line for the explorer I understand, right?, but I have tried in all differents ways and I always get 0. Should I run the explorer in some specific way to be able to see the same result as in the graph?

I have put the same watchlist and the date range starts the same as the indicator, until today and I get 0.
I also tried with the "1 recent bar (s)" and "1 recent day (s)" everything appears at 0.

Can you confirm if you too or am I doing something wrong?

Thanks very much for your time!

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