January 5, 2008
Deleting Tickers and Composites
Creating composites is a lot of fun and can provide useful information about market and sector movements. However, when creating many composites, you will sooner or later find that your database is bloated with obsolete composites. The first requirement is to create a function to delete composites. Dingo kindly provided the following example code, which will be used to provide a variety of other useful functions. Note that the functions below can be used to delete both tickers and composites; the procedure is the same. The formula is designed to be run as an indicator but can be adapted to run in a scan, etc.
Deleting a list of Tickers or Composites
1 2 3 4 5 6 7 8 9 10 11 12 | DeleteTickers = ParamTrigger("Delete Tickers", "Click Here To Delete Tickers"); TickerList = ParamStr("Tickers to Delete","ALY,CALM,FCX,GLF,PNCL,RS,SCHN,STLD,WNR,X"); if ( DeleteTickers ) { oAB = CreateObject( "Broker.Application" ); oStocks = oAB.Stocks(); for( n=0; (Ticker=StrExtract( TickerList, n))!= ""; n++) { oStocks.Remove( Ticker ); } oAB.RefreshAll(); } |
When testing this code be sure to use a test database to prevent deleting important tickers. It is always best to develop code that creates and deletes tickers on a test database. To test the above code create a new test database and copy-n-paste the TickerList into a Watchlist using Symbol -> Watchlist -> Type in Symbols. There is no need to backfill the tickers with data. Next open your workspace and display the Watchlist. Next, if you click Click Here To Delete Tickers, you’ll see the ticker disappearing from your Symbol Workspace.
Deleting a Single Ticker or Composite
The above code can easily be trimmed to provide a function to delete a single ticker:
1 2 3 4 5 6 7 8 9 10 11 | function DeleteComposite( CompositeName ) { oAB = CreateObject( "Broker.Application" ); oStocks = oAB.Stocks(); oStocks.Remove( CompositeName ); oAB.RefreshAll(); } DeleteTicker = ParamTrigger("Delete Ticker", "Click Here To Delete Ticker"); Ticker = ParamStr("Ticker to Delete","ALY"); if( DeleteTicker ) DeleteComposite( Ticker ); |
Deleting All Tickers in a Watchlist
A slight modification of the above code will let you delete all tickers in a Watchlist:
1 2 3 4 5 6 7 8 9 10 11 12 13 | WatchListNum = Param("Watchlist Number",0,0,64,1); DeleteTickers = ParamTrigger("Delete Tickers in Watchlist", "Delete Tickers"); TickerList = GetCategorySymbols( categoryWatchlist, WatchListNum ); if ( DeleteTickers ) { oAB = CreateObject( "Broker.Application" ); oStocks = oAB.Stocks(); for( n=0; (Ticker=StrExtract( TickerList, n))!= ""; n++) { oStocks.Remove( Ticker ); } oAB.RefreshAll(); } |
Deleting all Composites in Group 253
Composites are normally stored in Group 253. To delete all composites in this group replace the categorywatchlist with categorygroup:
1 2 3 4 5 6 7 8 9 10 11 12 13 | GroupNum = Param("Group Nbr",253,0,255,1); DeleteTickers = ParamTrigger("Delete Composites", "Click Here To Delete Composites"); TickerList = GetCategorySymbols( categoryGroup, GroupNum ); if ( DeleteTickers ) { oAB = CreateObject( "Broker.Application" ); oStocks = oAB.Stocks(); for( n=0; (Ticker=StrExtract( TickerList, n))!= ""; n++) { oStocks.Remove( Ticker ); } oAB.RefreshAll(); } |
OLE Code written by dingo.
Filed by Herman at 8:08 pm under Using the AddToComposite()


These are very useful examples to have. Kudos to dingo and Herman for posting them!
IMO, some of this is working-around yet-to-be implemented features of the AB UI.
In particular, I’d suggest that it would be very helpful if we could right-click on any symbol or composite and either
a) copy it’s name (to be pasted into code such as the lists used above), or
b) delete it from the database directly (why jump thru hoops?)
Thanks for the feedback Progster. The functions in this post allow non-OLE programmers to add them to an Include file and call them without leaving the familiar AFL environment. Eventually we will be able to set a default Include file that will automatically add many such functions to the AmiBroker list of AFL functions. Perhaps, but this might be wishful thinking, the AmiBroker Help could be extended to include custom-Help for custom functions found in the default include file.
AmiBroker’s design philosophy is that functions that can easily be implemented in OLE will not be implemented in AFL. In this context the above functions may not be temporary “work-arounds”.
“Jumping through hoops” is a common practice when you design real-time automated trading systems. In real-time trading you may create/delete 100s, or even 1000s, of composites during the day that would be impossible to delete manually. Remember that at this point in time Composites are the only way to implement Static Arrays.
Thanks for your additional comments - very insightful! Certainly I’m all for programmatic access, and I realize that there are scenarios where manual deletion would be highly burdensome. I suppose what I meant is that there are some scenarios where a little bit of easily applied manual deletion would be ideal, and I’d like to see the UI (rather than AFL) support these to make day-to-day life as simple as possible.
I think the goal of a big-honkin’ default include file(s) is a good one. This is exactly the sort of thing AB seems very well-designed to accommodate.
The kind of approach to docs taken by Doxygen and other similar packages seems like it could be adopted to achieve the “included Help” that you mention (if TJ thinks enough of the idea to help it along). The Help system could parse designated include file(s) for specially formatted comments and incorporate them into the Help index and Help presentation. I think that would be very useful as part of the open-ended expansion of AB into the future.
I would be at a loss without the ATC function. Right now, I use 5 separate ATC afl for my dailey market review. What would be a great convenience though is to use a script to automate all 5 afl. Perhaps the Amibroker UKB can offer up a tutorial for scripting writing and processing multiple afl.
As for the GUI: you can of course right click on any composite and delete it (from the symbol tree) already. You can also delete all composite tickers at once. Go to Symbol->Organize assigments, pick Group 253, select all from left side (using SHIFT key) and press “DELETE”.
So the GUI functionality is there and there is no need to write AFLs for that, except if you want non-GUI solution (as static arrays example mentioned above).
Jim, please provide more details about your needs and post your request on the main AmiBroker list. We have more sdripting expertise there.