It would be nice to have the report in dollars instead of percent. I was able to change the profit table but I cannot change the distribution charts, any idea? Thanks
The table is formula based, but the chart in the report is internally generated (without formula) so it is always in percent.
Thanks Tomasz for your answer. It would be nice to have the option to chose the report in dollars or in percent. Percent is not useful for futures' trading.
Hi Armin, do you mind sharing the code to change the profit table into dollars? And the distribution charts?
Thanks
EnableTextOutput( 3 ); // enable HTML output into report (Version 5.84 or higher!)
eq = C;
yr = Year();
mo = Month();
YearChange = yr != Ref( yr, 1 );
MonChange = mo != Ref( mo, 1 );
FirstYr = 0;
LastYr = 0;
startbar = 0;
////////////////////////////
// SKIP non-trading bars
////////////////////////////
for ( i = 0; i < BarCount; i++ )
{
if ( eq[ i ] )
{
startbar = i;
break;
}
}
////////////////////////////
// collect yearly / monthly changes in equity
// into dynamic variables
////////////////////////////
LastYrValue = eq[ startbar ];
LastMoValue = eq[ startbar ];
MaxYrProfit = MinYrProfit = 0;
MaxMoProfit = MinMoProfit = 0;
for ( i = startbar + 1; i < BarCount; i++ )
{
if ( YearChange[ i ] || i == BarCount - 1 )
{
Chg = eq[ i ] - LastYrValue;
VarSet( "ChgYear" + yr[ i ], Chg );
MaxYrProfit = Max( MaxYrProfit, Chg );
MinYrProfit = Min( MinYrProfit, Chg );
if ( FirstYr == 0 )
FirstYr = yr[ i ];
LastYr = yr[ i ];
LastYrValue = eq[ i ];
}
if ( MonChange [ i ] || i == BarCount - 1 )
{
mon = mo[ i ];
Chg = eq[ i ] - LastMoValue;
VarSet( "ChgMon" + yr[ i ] + "-" + mon, Chg );
VarSet( "SumChgMon" + mon, Chg + Nz( VarGet( "SumChgMon" + mon ) ) );
VarSet( "SumMon" + mon, 1 + Nz( VarGet( "SumMon" + mon ) ) );
MaxMoProfit = Max( MaxMoProfit, Chg );
MinMoProfit = Min( MinMoProfit, Chg );
LastMoValue = eq[ i ];
}
}
MonthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
function GenProfitTableHTML( )
{
printf( "<table border='1' bordercolor='#000000' cellspacing='0' cellpadding='3'style='border-collapse:collapse;'>\n" );
printf( "<tr bgcolor='#eeffee' >\n" );
Header = "Year," + MonthNames + ",Yr";
for ( Col = 0; ( Colname = StrExtract( Header, Col ) ) != ""; Col++ )
{
printf( "<td><b>" + Colname + "</b></td>" );
}
printf( "</tr>\n" );
for ( y = FirstYr; y <= LastYr; y++ )
{
//Color = ColorRGB( IIf( row == 0 || col == 0 || col == 13, 220, 255 ), 255, IIf( row % 2, 255, 220 ) );
// new row
if ( y % 2 )
printf( "<tr bgcolor='#ffffff'>\n<td bgcolor='#eeffff'>" );
else
printf( "<tr bgcolor='#ffffee'>\n<td bgcolor='#eeffee'>" );
printf( "<b>%g</b></td>", y );
for ( m = 1; m <= 12; m++ )
{
Chg = VarGet( "ChgMon" + y + "-" + m );
if ( NOT IsNull( Chg ) )
{
if ( Chg >= 0 )
//printf( "<td nowrap>%.1f%%</td>", Chg );
printf( "<td nowrap>%.0f</td>", Chg ); //aquí cambiado
else
//printf( "<td nowrap><font color='880000'>%.1f%%</font></td>", Chg );
printf( "<td nowrap><font color='880000'>%.0f</font></td>", Chg );
}
else
printf( "<td>N/A</td>" );
}
if ( y % 2 )
printf( "<td nowrap bgcolor='#eeffff'>" );
else
printf( "<td nowrap bgcolor='#eeffee'>" );
x = VarGet( "ChgYear" + y );
if ( x >= 0 )
//printf( "<b>%.1f%%</b></td>", x );
printf( "<b>%.0f</b></td>", x );
else
//printf( "<font color='880000'><b>%.1f%%</b></font></td>", x );
printf( "<font color='880000'><b>%.0f</b></font></td>", x );
printf( "</tr>\n" ); // end row
}
printf( "<tr bgcolor='#eeffee' >\n" ); // new row
printf( "<td><b>Avg</b></td>" );
for ( m = 1; m <= 12; m++ )
{
x = Nz( VarGet( "SumChgMon" + m ) / VarGet( "SumMon" + m ) );
if ( x >= 0 )
//printf( "<td nowrap><b>%.1f%%</b></td>", x );
printf( "<td nowrap><b>%.0f</b></td>", x );
else
//printf( "<td nowrap><font color='880000'><b>%.1f%%</b></font></td>", x );
printf( "<td nowrap><font color='880000'><b>%.0f</b></font></td>", x );
}
printf( "<td> </td>" );
printf( "</tr></table>\n" );
}
///////////////////////////
// This function checks if currently selected symbol
// is portfolio equity
//////////////////////////
function CheckSymbol()
{
if ( Name() != "~~~EQUITY" AND Name() != "~~~OSEQUITY" )
{
printf( "For accurate results switch to ~~~EQUITY symbol<br>" );
}
}
CheckSymbol();
////////////////////////////
// Main program
////////////////////////////
GenProfitTableHTML();
Distribution charts are hardcoded in Amibroker (see above). I cannot change that.
2 Likes
Thank you very much for your help!
I have tweaked the formatting: removed "%" references where existing and added a thousands "," separator to hopefully make it easier to read, here is the final version.
EnableTextOutput( 3 ); // enable HTML output into report (Version 5.84 or higher!)
eq = C;
yr = Year();
mo = Month();
YearChange = yr != Ref( yr, 1 );
MonChange = mo != Ref( mo, 1 );
FirstYr = 0;
LastYr = 0;
startbar = 0;
////////////////////////////
// SKIP non-trading bars
////////////////////////////
for ( i = 0; i < BarCount; i++ )
{
if ( eq[ i ] )
{
startbar = i;
break;
}
}
////////////////////////////
// collect yearly / monthly changes in equity
// into dynamic variables
////////////////////////////
LastYrValue = eq[ startbar ];
LastMoValue = eq[ startbar ];
MaxYrProfit = MinYrProfit = 0;
MaxMoProfit = MinMoProfit = 0;
for ( i = startbar + 1; i < BarCount; i++ )
{
if ( YearChange[ i ] || i == BarCount - 1 )
{
Chg = eq[ i ] - LastYrValue;
VarSet( "ChgYear" + yr[ i ], Chg );
MaxYrProfit = Max( MaxYrProfit, Chg );
MinYrProfit = Min( MinYrProfit, Chg );
if ( FirstYr == 0 )
FirstYr = yr[ i ];
LastYr = yr[ i ];
LastYrValue = eq[ i ];
}
if ( MonChange [ i ] || i == BarCount - 1 )
{
mon = mo[ i ];
Chg = eq[ i ] - LastMoValue;
VarSet( "ChgMon" + yr[ i ] + "-" + mon, Chg );
VarSet( "SumChgMon" + mon, Chg + Nz( VarGet( "SumChgMon" + mon ) ) );
VarSet( "SumMon" + mon, 1 + Nz( VarGet( "SumMon" + mon ) ) );
MaxMoProfit = Max( MaxMoProfit, Chg );
MinMoProfit = Min( MinMoProfit, Chg );
LastMoValue = eq[ i ];
}
}
MonthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
function GenProfitTableHTML( )
{
printf( "<table border='1' bordercolor='#000000' cellspacing='0' cellpadding='3'style='border-collapse:collapse;'>\n" );
printf( "<tr bgcolor='#eeffee' >\n" );
Header = "Year," + MonthNames + ",Yr";
for ( Col = 0; ( Colname = StrExtract( Header, Col ) ) != ""; Col++ )
{
printf( "<td><b>" + Colname + "</b></td>" );
}
printf( "</tr>\n" );
for ( y = FirstYr; y <= LastYr; y++ )
{
//Color = ColorRGB( IIf( row == 0 || col == 0 || col == 13, 220, 255 ), 255, IIf( row % 2, 255, 220 ) );
// new row
if ( y % 2 )
printf( "<tr bgcolor='#ffffff'>\n<td bgcolor='#eeffff'>" );
else
printf( "<tr bgcolor='#ffffee'>\n<td bgcolor='#eeffee'>" );
printf( "<b>%g</b></td>", y );
for ( m = 1; m <= 12; m++ )
{
Chg = VarGet( "ChgMon" + y + "-" + m );
if ( NOT IsNull( Chg ) )
{
if ( Chg >= 0 )
printf("<td nowrap>" + NumToStr(Chg, 1.0,True) + "</td>");
else
printf("<td nowrap><font color='880000'>" + NumToStr(Chg, 1.0,True) + "</font></td>");
}
else
printf( "<td>N/A</td>" );
}
if ( y % 2 )
printf( "<td nowrap bgcolor='#eeffff'>" );
else
printf( "<td nowrap bgcolor='#eeffee'>" );
x = VarGet( "ChgYear" + y );
if ( x >= 0 )
printf("<b>" + NumToStr(x, 1.0,True) + "</b></td>");
else
printf("<font color='880000'><b>" + NumToStr(x, 1.0,True) + "</b></font></td>");
printf( "</tr>\n" ); // end row
}
printf( "<tr bgcolor='#eeffee' >\n" ); // new row
printf( "<td><b>Avg</b></td>" );
for ( m = 1; m <= 12; m++ )
{
x = Nz( VarGet( "SumChgMon" + m ) / VarGet( "SumMon" + m ) );
if ( x >= 0 )
printf("<td nowrap><b>" + NumToStr(x, 1.0,True) + "</b></td>");
else
printf("<td nowrap><font color='880000'><b>" + NumToStr(x, 1.0,True) + "</b></font></td>");
}
printf( "<td> </td>" );
printf( "</tr></table>\n" );
}
///////////////////////////
// This function checks if currently selected symbol
// is portfolio equity
//////////////////////////
function CheckSymbol()
{
if ( Name() != "~~~EQUITY" AND Name() != "~~~OSEQUITY" )
{
printf( "For accurate results switch to ~~~EQUITY symbol<br>" );
}
}
CheckSymbol();
////////////////////////////
// Main program
////////////////////////////
GenProfitTableHTML();
2 Likes
Much better now ;)))