How to create your own exploration

AmiBroker 3.58 brings a new feature to Automatic Analysis window called "Exploration". Basically, an exploration works in a similar way to scan but instead of looking for and reporting just buy/sell signals it allows you to generate customizable screening (or exploration) report that can give you much more information than simple scan.

The idea behind an exploration is simple - one variable called filter controls which symbols/quotes are accepted. If "true" (or 1) is assigned to that variable for given symbol/quote it will be displayed in the report.

So, for example, the following formula will accept all symbols with closing prices greater than 50 :

filter = close > 50;

Note that exploration uses all range and filter settings that are also used by back-tester and scanning modes so you can get multiple signals (report lines) if you select "All quotations" range. To check just the most recent quote you should choose "n last quotations" and "n=1" as shown here:

Now, what about customizable reports?

Yes, exploration mode allows you to create and then export a report with completely customizable columns and it is quite simple to do.

All you have to do is to tell AmiBroker what columns do you want. This can be done by calling AddColumn function in your exploration formula:

AddColumn( Close, "Close" );

The first argument of AddColumn function is the data ARRAY you want to display, the second argument defines the column caption

If you now press "Explore" button in Automatic Analysis window you will get the result similar to this:

Note that there are actually 3 columns: predefined Ticker and Date column and one custom columnholding close price. Note that only tickers with close price greater than 50 are reported.

Now you can click "Export" and your exploration will be saved to CSV (comma separated values) file that could be easily loaded to any other program including Excel for further analysis.

Actually AddColumn function accepts more arguments to allow you to customize the output even more. The full syntax is:

AddColumn( array, name, format = 1.2, textColor = colorDefault, bkgndColor = colorDefault )

format parameter allows you to define the formatting applied to numbers. By default all variables are displayed with 2 decimal digits, but you can change this by assigning a different value to this variable: 1.5 gives 5 decimal digits, 1.0 gives no decimal digits. So, in our example, typing:

AddColumn( Close, "Close", 1.4 );

will give closing prices displayed with 4 decimal digits.
(Note for advanced users: the integer part of this number can be used to pad formatted number with spaces - 6.0 will give no decimal digits but a number space-padded upto 6 characters.)

There are also special format pre-defined constants that allow to display date/time and single character codes:

textColor and bkgndColor arguments allow you to produce colorful reports. By default result list is displayed using system color but you can override this behaviour providing your own colors.

For example, the code that displays close price in green color when 1 day rate of change is positive and otherwise uses red color:

AddColumn( Close, "Close", 1.4, IIF( ROC(C, 1 ) > 0, colorGreen, colorRed ) );

Examples

The exploration mode is extermely flexible: you can, for example, export the whole database to CSV file using the following formula:

filter = 1; /* all symbols and quotes accepted */

AddColumn(Open,"Open",1.4);
AddColumn(High,"High",1.4);
AddColumn(Low,"Low",1.4);
AddColumn(Close,"Close",1.4);
AddColumn(Volume,"Volume",1.0);

This one will show you only heavily traded securities:

filter = volume > 5000000; /* adjust this threshold for your own needs */
AddColumn(Close,"Close",1.4);
AddColumn(Volume,"Volume",1.0);

or...just show securities with volume being 30% above its 40-day exponential average

filter = volume > 1.3 * ema( volume, 40 );
AddColumn(Close,"Close",1.4);
AddColumn(Volume,"Volume",1.0);

With this one, you can export multiple indicator values for further analysis:

filter = close > ma( close, 20 ); /* only stocks trading above its 20 day MA*/
AddColumn( macd(), "MACD", 1.4 );
AddColumn( signal(), "Signal", 1.4 );
AddColumn( adx(), "ADX", 1.4 );
AddColumn( rsi(), "RSI", 1.4 );
AddColumn( roc( close, 15 ), "ROC(15)", 1.4 );
AddColumn( mfi(), "MFI", 1.4 );
AddColumn( obv(), "OBV", 1.4 );
AddColumn( cci(), "CCI", 1.4 );
AddColumn( ultimate(), "Ultimate", 1.4 );

One more example of color output:

Filter =1;

AddColumn( Close, "Close", 1.2 );
AddColumn( MACD(), "MACD", 1.4 , IIf( MACD() > 0, colorGreen, colorRed ) );
AddTextColumn( FullName(), "Full name", 77 , colorDefault, IIf( Close < 10, colorLightBlue, colorDefault ) );

Final tip

Please don't forget that you can sort the results of the exploration by any column by simply clicking on its header.