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();