Author Topic: AA Sorted (by price) stock sent to watchlist.  (Read 1253 times)

kiss.sphinx

  • Newbie
  • *
  • Posts: 2
    • View Profile
AA Sorted (by price) stock sent to watchlist.
« 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

Peter5510

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: AA Sorted (by price) stock sent to watchlist.
« Reply #1 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 );
}
« Last Edit: January 08, 2019, 09:10:34 pm by administrator »

Maziarz

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: AA Sorted (by price) stock sent to watchlist.
« Reply #2 on: January 15, 2019, 06:39:11 am »
Is it important to clear the watchlist before the exploration btw?

Peter5510

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: AA Sorted (by price) stock sent to watchlist.
« Reply #3 on: February 06, 2019, 07:35:54 pm »
If you do not clear the old tickers from the watchlist, new tickers will be appended to the watchlist. You can try by comment out(//) the clear watchlist code.