Hi,
I'm having trouble using the Report metrics to create custom Report Chart AFLs. Here's an example with a single metric, the CAR (%).
With this AFL:
Title = "";
SetGradientFill( colorLime, colorPaleGreen );
Plot( C, "Equity", ColorBlend( colorPaleGreen, colorBlack ), styleGradient | styleLine , Null, Null, 0, -1 );
// CÁLCULAR "A MANO" LA MÉTRICA CAR(%)
function CalendarDays()
{
ddsince1900 = DaysSince1900();
result = ddsince1900 - ddsince1900[0];
return result;
}
EQ = C;
bi = BarIndex();
fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );
fbrbi = LastValue( ValueWhen( fbr, bi ) );
lbrbi = LastValue( ValueWhen( lbr, bi ) );
cd = CalendarDays();
Days = cd[ lbrbi ] - cd[ fbrbi ];
CAR = 100 * ( ( eq / eq[ fbrbi ] ) ^ ( 365 / Days ) - 1 );
// TABLA GRÁFICA
_SECTION_BEGIN("GFX Table Backtest");
cellHeight = 20;
cellWidth = 60;
startX = 20;
startY = 40;
headerColor = ColorRGB(180, 210, 255);
valueColor = colorWhite;
borderColor = colorWhite;
textColor = colorBlack;
function Celda(text, col, row, bgColor)
{
x1 = startX + (col - 1) * cellWidth;
y1 = startY + (row - 1) * cellHeight;
x2 = x1 + cellWidth;
y2 = y1 + cellHeight;
GfxSelectPen(borderColor, 1);
GfxSelectSolidBrush(bgColor);
GfxRectangle(x1, y1, x2, y2);
GfxSetBkColor(bgColor);
GfxSetTextColor(textColor);
GfxSetTextAlign( 6 | 0 );
GfxSelectFont("Arial", 10, 700 );
GfxTextOut(text, x1 + cellWidth/2, y1 + cellHeight/8);
}
// MÉTRICAS DEL BACKTEST
CAR_lv = LastValue(CAR);
// FILA 1 - NOMBRES
Celda("CAR %", 1, 1, headerColor);
// FILA 2 - VALORES
Celda( StrFormat("%.2f", CAR_lv), 1, 2, valueColor);
_SECTION_END();
I get what I want, but I had to manually calculate the CAR (%).
What I'm trying to do is take advantage of the fact that the Report already provides the CAR (%) so I don't have to calculate it, just get it and use it in my Report Chart.

To do this, I'm using this AFL:
Title = "";
SetGradientFill( colorLime, colorPaleGreen );
Plot( C, "Equity", ColorBlend( colorPaleGreen, colorBlack ), styleGradient | styleLine , Null, Null, 0, -1 );
// OBTENER MÉTRICA CAR(%) DEL REPORT
SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest();
st = bo.GetPerformanceStats(0);
car_value = st.CAR;
StaticVarSet( "CAR_Value_Stored", st.CAR );
}
CAR = StaticVarGet( "CAR_Value_Stored" );
// TABLA GRÁFICA
_SECTION_BEGIN("GFX Table Backtest");
cellHeight = 20;
cellWidth = 60;
startX = 20;
startY = 40;
headerColor = ColorRGB(180, 210, 255);
valueColor = colorWhite;
borderColor = colorWhite;
textColor = colorBlack;
function Celda(text, col, row, bgColor)
{
x1 = startX + (col - 1) * cellWidth;
y1 = startY + (row - 1) * cellHeight;
x2 = x1 + cellWidth;
y2 = y1 + cellHeight;
GfxSelectPen(borderColor, 1);
GfxSelectSolidBrush(bgColor);
GfxRectangle(x1, y1, x2, y2);
GfxSetBkColor(bgColor);
GfxSetTextColor(textColor);
GfxSetTextAlign( 6 | 0 );
GfxSelectFont("Arial", 10, 700 );
GfxTextOut(text, x1 + cellWidth/2, y1 + cellHeight/8);
}
// MÉTRICAS DEL BACKTEST
CAR_lv = LastValue(CAR);
// FILA 1 - NOMBRES
Celda("CAR %", 1, 1, headerColor);
// FILA 2 - VALORES
Celda( StrFormat("%.2f", CAR_lv), 1, 2, valueColor);
_SECTION_END();
Which isn't working.
I know I'm doing it wrong, very wrong and missing something fundamental. I think I'm getting confused and I don't know where to go from here...



