Frequency Distribution Charts

At the end of the Charts page of the Backtest Report there are three frequency distribution charts, one each for Profit, MAE, and MFE. While the AFL and HTML for the other built-in chart and tables is included in the AmiBroker/Formulas/Report Charts directory, the code for these three charts is not.

I would like to create some very similar charts of my own, although the 3D effects are not necessary for my implementation (nice touch though, @Tomasz!) I know that I can use the Low-Level Graphics functions (Gfx*) to draw all the chart elements myself, but before I go down that road I am wondering if there are existing examples that do something similar.

Hi matt
Until someone answer the only place that I know is here, and in your hard drive :wink:

// without 3d effects
GfxGradientRect( xp, yp, xe , ye, coloryelow, coloryelow); 
function DrawBar( text, bar, numbars, y, Miny, Maxy )
 BarWidth = (Status("pxwidth") - 4 * XOffset )/( numbars + 1 ); 
 BarHeight = Status("pxheight") - 2 * YOffset;
 relpos = ( y - Miny ) / (Maxy - Miny );

 xp = XOffset + ( bar + 0.5 ) * BarWidth;
 yp = YOffset + BarHeight * ( 1 - relpos );
 xe = XOffset + ( bar + 1 ) * BarWidth;
 ye = YOffset + BarHeight * ( 1 - ( -miny )/( maxy - miny ) );
 if( y > 0 )
 GfxGradientRect( xp, yp, 
                  xe , ye,
                  coloryelow, coloryelow); //  without 3d effects
 GfxGradientRect( xp, ye, 
                  xe , yp,
                 colorblue, colorblue );  // without 3d effects
 GfxTextOut( text, xp, ye );
 GfxTextOut( StrFormat("%.2f", y ), xp, yp );
1 Like

Matt. How i forgot the exploration mode?

3 more examples here.

Old yahoo emails by Aron @aron look how he did the Gradient Window


Thanks @PanoS! I need to plot metrics at the end of a back test, but these are still good examples.

1 Like

Hi Matt,

I've recently done this for myself. How I did it was (using MFE as an example):

  1. Collect MFE: Using the CBT iterate through trades and store the MFE results into a matrix and assign it to a static variable,
  2. Bin the results: Create a new report chart that gets the MFE static variable and run it through a binning algorithm storing the frequency results into a matrix (hint: use two matricies or 1 matrix with two rows, 1 with the frequency, the other with the bin edges),
  3. Plot your data: Using low level graphics functions iterate through the frequencies (y values) and bin edges (x values).

The binning algorithm was a bit of a pain and I ended up using Sturge's Rule to get a bin count. It seems to work ok however you could also just specify a bin width yourself.

Regarding point 2 above, I actually created a function external to the report chart however this involves more passing around of static variables.

Here are some examples of my output.



1 Like

Thanks @rb250660. My steps are nearly identical to yours, except I started with Step 3 because that's the part I was least familiar with. And for Step 2 I will probably start by taking a shortcut and use predefined bins.

@mradtke here's a combo chart I've been working on this afternoon for a bit more inspiration.



Damn, thats a nice chart. I would be interested in paying for that code

@bing6 - did you read the first post in this thread? Profit distribution chart is INCLUDED in the backtest report (it is built-in)