I’m trying to find a way to count the number of symbols in a watch list (the number of symbols will be dynamic), and if possible, I prefer to reference the watch list by name, rather than by the ordinal number of where the watch list falls in a list of watch lists.
I have found the example function below, but I think it references watch lists by the order in which they appear in a list, and I can’t be sure a given watch list will always be in the same order. Is there a way to evolve the code below so that I can count the number of symbols in a watch list by referencing the watch list by name?
function CategoryCountSymbols( category, number )
count = StrCount( list = CategoryGetSymbols( category, number ), ",");
return IIf( list == "", 0, count + 1 );
Title = "Symbols in watchlist 0: " + CategoryCountSymbols( categoryWatchlist, 0 );
Or is there an even more simple way to do without creating a function. Here’s a pseudo code scenario of what I’m trying to do:
… I should have mentioned, that the above code requires AB 6.17 to work properly (just because of the %s string specifier used in printf() line). If someone has an older version, he/she can replace the printf() line with (for example) this one:
@Milosz has given you one of many possible ways of counting the symbols in a WL. Like most things, AmiBroker can arrive at a solution in different ways. Regardless, you did mention your ultimate goal was
Have you reviewed this recent thread on the forum ?
Yes, of course I agree with you Larry ( @portfoliobuilder ). I have just shown an example code which might be used as a stand-alone solution to count any watchlist members providing its name.
But if @seaworthy wants to accomplish his goal, he rather needs to read about AddToComposite() function and Composites based on Static Variables - for example in this thread (with Tomasz’s remarks and suggestions to use StaticVarAdd() whenever possible):
@seaworthy I think @fxshrat and @Milosz posts should help to remind you and anyone else that there is already a wealth of information on this forum. You need to spend a little time searching and you will find either exactly what you were looking for, or a good beginning to your desired solution.
Considering the forum is only a few months old, I think that is a real testament to how great things have worked out since moving to Discourse.