Amibroker Forum (Unofficial)

General Category => General Discussion => Topic started by: kiss.sphinx on October 14, 2018, 07:36:19 am

Title: AA Sorted (by price) stock sent to watchlist.
Post by: kiss.sphinx on October 14, 2018, 07:36:19 am
How I can send stock in a selected watchlist "ordered by price (from the lowest to the highest)" using AFL after an exploration?

if anyone reply me I explain better my question. (I have AB 6.20)

Thanks in advance
Kiss
Title: Re: AA Sorted (by price) stock sent to watchlist.
Post by: Peter5510 on January 01, 2019, 09:26:02 pm
Use this code to clear the watchlist before the exploration i.e. put it at the top of the AFL script.
Put the watchlist name that you intend to update in the place where indicated and include the double quotes.
Code: [Select]
//Get watchlist number for update
listnum = CategoryFind("Put your watchlist name here", categoryWatchlist);
// 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 );
    }
}
Your exploration script goes here. Use SetSortColumn(Column number) to sort your exploration results.
Column number is for the column that you intend to sort and it should be from 1 to any number.
Positive number for ascending order, and negative for descending.

Put the script for updating the watchlist after exploration here. Update your watchlist name.
Code: [Select]
if ( Filter ==1 ) {
for( i = 0; CategoryGetName( categoryWatchlist, i ) != ""; i++ ) {
if ( CategoryGetName( categoryWatchlist, i ) == "Your Watchlist name here" ) {
listnum = i;
}
}
if ( LastValue( Cum( Filter AND Status( "barinrange" ) ) )  )
CategoryAddSymbol( "", categoryWatchlist, listnum );
}
Title: Re: AA Sorted (by price) stock sent to watchlist.
Post by: Maziarz on January 15, 2019, 06:39:11 am
Is it important to clear the watchlist before the exploration btw?