Save watchlist after explore

I am using code from help to save explore results to watchlist, but the stocks in the list are not saved when i exit, i tried to find a function call to save the results but couldn't. I saved before exiting, that too didnt work.

What can i do to save the watchlist contents?


listnum = 29; // we use watchlist 10 for storing results

// erase the watchlist when we process very first symbol
if ( Status( "stocknum" ) == 0 )
{
    // retrieve watchlist members
    oldlist = CategoryGetSymbols( categoryWatchlist, listnum );

    // iterate through the list and remove tickers
    for ( i = 0; ( sym = StrExtract( oldlist, i ) ) != ""; i++ )
    {
        CategoryRemoveSymbol( sym, categoryWatchlist, listnum );
    }
}

Diff = abs(UB-LB);
FC1 = Diff / pp < 0.001; // previous value was .001
FC2 = Close > 50;
FC3 = MA(V, 10) > 1000000;
Filter = FC1 AND FC2 AND FC3;
AddColumn(High, "High", 1.2);
AddColumn(Low, "Low", 1.2);

// check how many times Filter variable was true in the tested range
// if non-zero value detected, add current symbol to a watchlist
if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) )  )
    CategoryAddSymbol( "", categoryWatchlist, listnum );

@erukumk, please, check the last line of code.

CategoryAddSymbol() first parameter should be the current ticker - i.e. Name() - (not an empty string).

2 Likes

Thank you @beppe, Still same result, only current symbol is present in the watchlist, rest all are gone.

if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) )  )
    CategoryAddSymbol( Name(), categoryWatchlist, listnum );

Are you saying that after you run your AFL script there are multiple symbols in that particular watchlist and then when you close and re-open AmiBroker that same watchlist symbols have changed?

What data provided are you using?

1 Like

@erukumk, please, verify that when setting the "filter" for your exploration you are using DIFFERENT watchlist than the one assigned to listnum (in your example #29).

Anyway, the easiest way to clear and save exploration results is using the "batch" functionalities that were added to Amibroker in 2019 (specifically CHANGES FOR VERSION 6.31.0)

See this thread: AmiBroker 6.35.0 BETA released

  1. Batch: added "add results to watchlist" action / WatchlistAddResults
  2. Batch: added "clear watchlist" action / WatchlistClear
1 Like

Please read documentation.
Empty string does mean that current symbol is used!

1 Like

@fxshrat, thanks, I missed that. I will take note.

So, maybe, the issue is the one I indicated in my second post.

1 Like

@TrendSurfer Yes, when i run the AFL, i have 12 symbols in the list 29, but when i exit and open AmiBroker again, i am seeing only the current symbol.

Yahoo EOD data only.

@beppe I am running the exploration on all symbols excluding indices.

I will go through the batch functionalities, thank you!!

Used batch to add results to watchlist, but still having same issue, zero symbols are saved to watchlist.

Batch1.abb:

<?xml version="1.0" encoding="ISO-8859-1"?>
<AmiBroker-Batch CompactMode="0">
<Step>
<Action>WatchlistClear</Action>
<Param>Intraday</Param>
<Param2/>
</Step>
<Step>
<Action>WatchlistAddResults</Action>
<Param>Intraday</Param>
<Param2/>
</Step>
</AmiBroker-Batch>

This code does not throw error but still does not save to watchlist.

if( ParamTrigger("batch", "run me" ) )
{
    ShellExecute( "runbatch", "C:\\Program Files\\AmiBroker\\Formulas\\Custom\\Batch1.abb", "" );
}

This throws up multiple batch1.abb tabs and runs endlessly.

if ( Status( "stocknum" ) == 0 ) 
{
	ShellExecute( "runbatch", "C:\\Program Files\\AmiBroker\\Formulas\\Custom\\Batch1.abb", "" );
}

Please help!!, I do not know what is happening.

@erukumk, modify your formula to include ONLY the lines used to create an exploration (delete the logic to clear/add to a watchlist). Apply it to the exploration and set the required parameter/filter etc.

Run the exploration and be sure that the report is listing all the symbols you expect.

Then "Save as" the exploration and its current settings settings as a new "project" (.apx).

Then create/modify a "batch" (.abb) including the following steps:

  1. "Load Project" (select the saved project)
  2. "Explore"
  3. "Clear watch list" (enter the number of the watchlist you want to reset)
  4. "Add results to watch list" (enter again the number of the watchlist you want now to fill)

Run the "batch" from the user interface.

1 Like

If you add symbols to the watchlist manually do they hold between AmiBroker sessions?

Have you seen this behaviour with any other of your watchlists?

@beppe, thanks the list is now saved.

@TrendSurfer, when i add manually the list is saved, as expected. This behavior is only when i try to save it using AFL.

1 Like

Is there further line/s of code or a different AFL script or batch interfering with that particular watchlist?

Create a new watchlist (assign that watchlist number to your script) and see if you have the same issue?

@TrendSurfer This is the first time i am trying to add explore results to a watchlist, i did not use batches too earlier. No other AFL is interfering with this watchlist too.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.