CategoryGetSymbols
- retrieves comma-separated list of symbols belonging to given category

Information / Categories
(AmiBroker 4.50)


SYNTAX CategoryGetSymbols( category, index, mode = 0 )
RETURNS STRING
FUNCTION Retrieves comma-separated list of symbols belonging to given category Supported categories:
  • categoryMarket
  • categoryGroup
  • categorySector
  • categoryIndustry
  • categoryWatchlist
  • categoryFavorite
  • categoryIndex
  • categoryGICS
  • categoryICB
  • categoryAll (new in 5.50) - means all symbols in the database (
index is a market/group/industry/sector/watchlist number:
0..255 for categoryMarket, categoryGroup, categoryIndustry
0..63 for categorySector
no limit for categoryWatchlist.
ignored for categoryFavorite, categoryIndex

mode - (new in 5.50) mode parameter decides what field is retrieved:

  • 0 (default value) - ticker symbol
  • 1 - full name

The meaning of index parameter is different for GICS and ICB categories - the index for categoryGICS and categoryICB is actually GICS/ICB code. Such as 10 for energy sector or 351010 for "Health Care Equipment & supplies" industry. The codes are fixed even if new classifications are added at some point in the future. This means that you won't need to change AFL codes even if new classifications are added. But it is important to understand that these codes work in hierarchical way. So

GetCategorySymbols( categoryGICS, 10 )

will return all symbols belonging to energy sector, including those in 10101010 - Oil & Gas Drilling sector as well as 10102050 - Coal & Consumable Fuels; for example. See http://en.wikipedia.org/wiki/Global_Industry_Classification_Standard for more details on GICS system
http://en.wikipedia.org/wiki/Industry_Classification_Benchmark for more details on ICB system

Use StrExtract function to extract individual symbols from the list.

EXAMPLE /* note: if given watch list contains lots of symbols
** performance may be poor
** AVOID SUCH CODES IN REAL-TIME MODE !
*/

function CreateAverageForWatchList( listnum )
{
   
// retrive comma-separated list of symbols in watch list
   list =
CategoryGetSymbols( categoryWatchlist, listnum );

   Average =
0; // just in case there are no watch list members

   
for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
   {
      f =
Foreign( sym, "C" );
      
if( i == 0 ) Average = f;
      
else Average = Average + f;
   }
   
return Average / i; // divide by number of components
}

Plot( CreateAverageForWatchList( 1 ), "Avg of WL 1", colorGreen );

Example 2, retrieving all symbols tickers and full names // to get all ticker symbols
CategoryGetSymbols( categoryAll, 0 );
//to get full names of all symbols use:
CategoryGetSymbols( categoryAll, 0, 1 );

SEE ALSO GETCATEGORYSYMBOLS() function , StrExtract() function , INWATCHLIST() function , CategoryGetName() function

References:

The CategoryGetSymbols function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.