StockInfo and WatchlistBits

I can see WatchlistBits in StockInfoFormat4 but there isn't in StockInfo. Why?
Is it possible to use StockInfoFormat4 in newest version of AmiBroker?

WatchListBits is legacy field from times when only 32 watch lists were supported.
Watch list memebership info in newest versions is not stored in this field.
New versions should use simple text files (ticker lists .TLS) in "Watchlists" folder under database

Is it only one way to automatically update watchlist (exluding OLE)?

  1. Run Exploration and update results to Watchlist via AFL script.
  2. If the source is external than Amibroker can pull in the data via OLE.
    I use option 2 since my source is external.

Watchlists can be updated automatically directly from AFL using Category functions

and more

Fine, but from StockInfo we can set MarketID, GroupID, IndustryID, GICS but not WatchList witch was in StockInfoFormat4.
When we make complex plugin, we don't want refer to afl. I care about functionality, and I don't want say to my client "and now open AFL to get actual watchlists", when we can have "all in one".
Furthemore, there is a problem with release COM object when we use OLE, and proces Broker.exe may stay still run after closed Amibroker.

Mr. Tomasz, I'm asking for new functionality: WatchlistBits and WatchlistBits2 in StockInfo.

As I wrote these fields are legacy / obsolete and support only first 64 watch lists.
The functionality that you are asking for already exists has been removed. Obviously it was limited to just first 64 watch lists. Now unlimited watch lists are possible and old mechanism was not capable of handling that. If you are making plugin and you insist on using those old fields you can. You use InfoSite interface. It has two functions, AddStock and AddStockNew.

The first function is legacy one and it returns StockInfoFormat4 that has those two fields and you can use legacy AddStock function and WatchListBits/2 field already

New designs should consider writing watch lists files directly.

As to COM you need to release handle that you were using to properly shut down the server. Broker.exe can not close if client OLE handle is not released.

UPDATE: Sorry, but WatchListBits field functionality was removed quite some time ago. It only works in ancient versions like 5.26 or earlier

1 Like

Tomasz, I have problem with set WatchListBits.
Do I have to set Flags or MoreFlags?

What kind of problem exactly? Flags and MoreFlags should not be touched. To assign symbol to Nth watch list you need to do this:

// SOMETHING LIKE 5.26 or ealier
// C/C++ code for plugin (this is not AFL)
// this code uses OBSOLETE fields for watch lists 
// it is recommended just to write .TLS files in watchlist subdirectory of DB
PLUGINAPI int Configure( LPCTSTR pszPath, struct InfoSite *pSite )
        struct StockInfoFormat4 *si = pSite->AddStock( symbol );

        int iWatchListNum = 15;

        if( iWatchListNum < 32 )
             si->WatchListBits |= ( 1L << iWatchListNum );
             si->WatchListBits2 |= ( 1L << ( iWatchListNum - 32 ) );

	return 1;

I used exactly this example and it doesn't set watchlist for symbol.
I can't set e.g. AliasName etc. also.
I can set only FullName.
I tried on AmiBroker 6.16.0 and 6.30.4

OK, I checked actual code (previously I was speaking from my, apparently failing, memory) and found that support for it was removed quite some time ago and in all currently supported versions (>= 6.0) only FullName, Flags and MoreFlags, IndustryID are copied from old structure to new.

The code above would only work in ancient versions (5.26 or earlier)

So sorry, no-go. And as I wrote, this is not going to be supported since it does not make sense to support only 64 watch lists while currently unlimited watch lists are possible.

Mayby you can add only Watchlistbits/2?
For simply speed update 64 watch lists are enough :slight_smile:

No, I would rather add completely new functions that are capable of handling unlimited watch lists than try to revive old code that won't work properly for all watch lists. And quite frankly since watch lists are now plain text files, the whole thing can be handled by directly writing ticker files inside Watchlist subdirectory. And the only function really needed is "re-read" watch lists.

1 Like

...Without rerun AmiBroker :slight_smile:

As I wrote, you don't need to re-run AmiBroker to read the watch lists. You only need to OPEN DATABASE. Watch lists are read when you are opening database. You don't need to re-run program. Simple call to LoadDatabase from OLE does that.

Also the function to re-load watch lists without re-opening database already exits, it is called LoadWatchlists:

// JScript code
AB = new ActiveXObject("Broker.Application");
AB.LoadWatchlists(); // reloads watch lists from DB

Be aware is that it overwrites all watch lists, so if user in the meantime modified watchlists, his changes will be lost, which may be confusing to the user, see this: Norgate database maintenance may (and will) overwrite watch lists

Any add-on that messes up with watch lists should inform the user about what is going to happen and get consent. Or at least SaveDatabase prior to doing any modifications to watch lists.

1 Like

Please update
Great, but it is still OLE which working only with one instance of AmiBroker.
Thanks anyway.

That is far from being precise. If you call OLE from within AmiBroker (plugin would do that), it will refer to current (correct) instance even if multiple ones are running. So technically there is absolutely no obstacle to use it in multiple instance setup.

FWIW: Users guide is now updated to include LoadWatchlists method.

Make sure you take into consideration notes about overwriting of user watchlists StockInfo and WatchlistBits
It may be highly undesirable and surprising for the user to have their watch lists lost/changed without warning by plugin or other external tool.


You have to tell us how do that, becouse when I create two instances of AmiBroker, second istance Broker.Application refer to first instance of AmiBroker, and accidentally I can update Watchlist in other database than I intended.

Not in my testing. When I do this from AFL

AB = CreateObject("Broker.Application");

it works on current instance

Yes, from AFL it works for me, but from plug-in not (at two instances).