Thank you once again Keith for your help. A quick follow up if you don't mind: This looks like it combines both jscript code (e.g. AB.Stocks) and AFL language...do you run it as a jscript file or an AFL? When I've tried to use some AFL code within a jscript previously it has not worked. Clearly, I am quite ignorant when it comes to programming...so am just trying to get a better handle on the 'rules' of combining the two. Thus far, I have only successfully run AFL files from a .js.
________________________________ From: Keith McCombs <[email protected]> To: [email protected] Sent: Fri, May 14, 2010 7:43:07 PM Subject: Re: [amibroker] Programmatically Add New Symbol to Database B S -- Code snippit below works for me. AB = CreateObject( "Broker.Applicat ion"); ASS = AB.stocks; // add all stocks in list to database DBAstkcnt = 0; // used later for how many fh1 = fopen(filename, "r"); if(fh1){ while(!feof( fh1)){ line = fgets(fh1); if(StrLen(Line)>1){ symbol = StrExtract(line, 0); // _TRACE("line1: " + Line); ASS.Add(symbol) ; // add symbol to database, even if already there ++DBAstkcnt; StaticVarSet( "DBAStockCount" , DBAstkcnt); } } fclose(fh1); If symbol is already in data base, no problem. A second copy is NOT added. -- Keith On 5/14/2010 11:10, B S wrote: >Hi- > >Below is a simplified version of an afl that I am using to write tickers from >a text file into a watchlist. Everything works fine, except that some of the >tickers in the text file are not already in the database. As I've found out, >if they are not already in the database, they do not get added. It's a >realtime database, so I believe that I only need to add the symbol in there >and the next day the appropriate fields will populate. Does anyone know of a >way that I can first add symbols to the database through afl? Or a .js file? >(This afl actually gets called in a .js file that runs nightly) > >Appreciate any suggestions. Thanks. > >//////////// ///////// ///////// ///////// ///////// ///////// ///////// >/////// >Path = "C:\\Scans\\ "; >WL = "DC_SYMBOLS"; >WLnumber = CategoryFind(WL,categoryWatchlist); >fh = fopen(Path+WL+".txt","r"); >if(fh) >{ >while(!feof(fh)) >{ >Line = fgets(fh); >Ticker = StrLeft( Line, StrLen(Line)-1); >CategoryAddSymbol(Ticker,categoryWatchlist,WLnumber); >} >fclose(fh); >} >else >{ >_TRACE("ERROR: "+WL+" does not exist"); >} >
