Watchlist loop automatically

Is it possible to watchlist select themselves automatically one by one like watchlist loop?

Yes sure,

Watchlists are simple text files located within AB database's Watchlist folder.
C:\Program Files\AmiBroker\<Your AB Database Name>\WatchLists

To play with the external text files, you would need to go through the "File Input/Output functions" section from Categorized list of functions.

Once done, get acquainted with the example shown for CategoryGetSymbols.

I bet you will enjoy the satisfaction of finally able to accomplish it.....

Cheers !

1 Like

In watchlist loop I got some problem .I will attached my code and image for your reference .In watchlist I have 5 watchlist but code only working 3 watchlist .Any Idea ?

for( i = 0; CategoryGetName( categoryWatchlist, i )!= ""; i++ ) 
{ 
	if( InWatchList( i ) ) 
	{
		listname = CategoryFind(CategoryGetName( categoryWatchlist, i ), categoryWatchlist );
		List = CategoryGetSymbols(categoryWatchlist, listname );
		NumberOfTickers = StrCount( List, "," ) + 1;
		printf(CategoryGetName( categoryWatchlist, i)+"  "+NumberOfTickers+"\n");
		_TRACE(CategoryGetName( categoryWatchlist, i)+"  "+NumberOfTickers);
	}		
}

WatchList

@Ambi123 try this:

lastWatchlistNo = 120; // set it to your last defined watchlist 
                       // could be greater;  will get empty watchlists

for( i = 0; i <= lastWatchlistNo; i++ )
{
    listName = CategoryGetName( categoryWatchlist, i );
    tickerList = CategoryGetSymbols( categoryWatchlist, i);
    if (StrTrim(tickerList, " ", 3) != "") {
		numberOfTickers = StrCount( tickerList, "," ) + 1;
		_TRACE("#" + i + ") " + listname + ", " + NumberOfTickers );
    }
}

If you need to loop over only a certain number of contiguous watchlists you can change the loop initializer:

for( i = 3; i <= 7; i++ )
     // etc.

Or better, instead of hardcoding numbers (that will make your code not very robust and hard to maintain), you could use the CategoryFind() function to find by name the number of the first and last watchlist to include in your loop initializer.