Alternate to GETCATEGORYSYMBOLS()

Is there an alternate function to GETCATEGORYSYMBOLS() function so as to handle huge number of ticker symbols so as to increase performance during optimization.
using getcategorysymbol() is very time consuming.
TIA.

What exactly are you trying to accomplish? It’s hard to say whether alternatives exist when we don’t know what your goal is.

thanks for replying…
see my goal is to run for loop for all symbols and for that I am using strextract function whose last value is determined by getcategorysymbol function.
this reference need to be done again again since I am optimizing my afl.
and I have checked code check and profile which is showing that max time is utilised by this function
so I am trying to figure out as to how to make it efficient

@manan.singhal I don't know what your code looks like, maybe for example you abuse CategoryGetSymbols() and call it too often, but you can assign its value only once (in this or another code) to a Static Variable. For example:

TickersFromWatchList3 = CategoryGetSymbols(categoryWatchlist, 3, 0);
StaticVarSetText("TickersFromWatchList3", TickersFromWatchlist3, persist = True);

StaticVarGetText("TickersFromWatchList3"); 

Przechwytywanie

In this example using StaticVarGetText() instead of CategoryGetSymbols() is about 55 times faster.

thanks for replying…
but is it possible to call this function only once while doing optimization too as symbols will remain same for all combinations of optimization

For time consuming work use a trigger to call once and store it to Static var.

SymList = CategoryGetSymbols( categoryWatchlist, 0 );
symcnt = StrCount( symlist, "," ) + 1;

If( ParamTrigger( "Iterate symbols", "Click HERE" ) ) {	
	
	cs = 0;
	for( i = 0; ( symbol = StrExtract( SymList, i ) ) != ""; i++ )	{
		SetForeign( symbol );
		cs += C;
		RestorePriceArrays();		
	}
	
	StaticVarSet( "SumOfSymbols", cs);
}

symavg = StaticVarGet( "SumOfSymbols" ) / symcnt;

Plot( symavg , "SymAvg", colorDefault, styleLine );

In Analysis do iteration just at first symbol:

If( status( "stocknum" ) == 0 ) {
	// do something
}

@fxshrat @Milosz @mradtke
thanks for replying…

but is it possible to call this function only once while doing optimization too as symbols will remain same for all combinations of optimization
[/quote]

@fxshrat @Milosz @mradtke

my query is this code will run again and again in optimization window with different set of parameters and by doing this , the call to categorygetsymbols() will be made again and again resulting in slowing down the process .
so is there a way that the function can be used only once at first set of optimization parameter and let all successive combinations of optimization parameter work on same set of symbols and not call the function again.

That’s what @fxshrat just showed you how to do…

If you assign such ticker list to a Static Variable, you will be able to use it as many times as you wish without calling CategoryGetSymbols() again. If it is persistent Static variable, you can even use it for the next couple of years :wink: (until you reinstall AB or remove this Static variable using StaticVarRemove ).

http://amibroker.com/guide/afl/staticvarset.html
http://amibroker.com/guide/afl/staticvarsettext.html