Australian (ASX) Stock Market Forum

Amibroker

Joined
25 November 2016
Posts
8
Reactions
0
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
 
You probably need to use the SetSortColumns function in your AFL

SetSortColumns( col1, col2... ) with the column number (1, 2, 3 etc) or -1 for descending.
 
You probably need to use the SetSortColumns function in your AFL

SetSortColumns( col1, col2... ) with the column number (1, 2, 3 etc) or -1 for descending.

I think SetSortColumn is valid "only" for exploration result (order the column by number Col).
But I want in the selected watchlist (with afl and NOT manually added) the stocks ordered by price (not by symbol) from the lowest (the first) to the highest (latest).

I've tried the formula [below] follow AB Afl Guide, and assuming a list of stock to explore in a watchlist to test but there are 2 error:

1: rank (the lowest value must be the first in the rank)
2: I've added "CategoryAddSymbol( "", categoryWatchlist, 3 );" to add ordered by price symbol in wl3 but won't work.


Code:
--------------------
// watchlist should contain all symbols included in the test
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;

if( Status( "stocknum" ) == 0 )
{
    // cleanup variables created in previous runs (if any)
    StaticVarRemove( "rank*" );
    StaticVarRemove( "values*" );
    categoryList = ",";

    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {
        SetForeign( symbol );

        // use sectors for ranking
        category = sectorID();

        // add sector to the list
        if( ! StrFind( categoryList, "," + category + "," ) ) categoryList += NumToStr( category, 1, 0 ) + ",";

        // write our ranking criteria to a variable
        // in this example we will use 10-bar rate-of-change
        values = C;
      
        RestorePriceArrays();

        // write ranked values to a static variable
        StaticVarSet( "values" + category + "_" + symbol, values );

    }

    // generate separate ranks for each category from the list
    for( i = 1; ( category = StrExtract( categoryList, i ) ) != ""; i++ )
    {
        StaticVarGenerateRanks( "rank", "values" + category + "_", 0, 1224 ) ;     

    }
}

CategoryAddSymbol( "", categoryWatchlist, 3 );

category = sectorID();
symbol = Name();
m = Month();

values = StaticVarGet( "values" + category + "_" + symbol );
rank = StaticVarGet( "rank" + "values" + category + "_" + symbol );

// exploration code for verification
AddColumn( values, "values" );
AddColumn( rank, "rank" );
Filter = rank <= 200;

if( Status( "Action" ) == actionExplore )
SetSortColumns( 3 );

---------------------------
 
I think SetSortColumn is valid "only" for exploration result (order the column by number Col).
But I want in the selected watchlist (with afl and NOT manually added) the stocks ordered by price (not by symbol) from the lowest (the first) to the highest (latest).

I've tried the formula [below] follow AB Afl Guide, and assuming a list of stock to explore in a watchlist to test but there are 2 error:

1: rank (the lowest value must be the first in the rank)
2: I've added "CategoryAddSymbol( "", categoryWatchlist, 3 );" to add ordered by price symbol in wl3 but won't work.


Code:
--------------------
// watchlist should contain all symbols included in the test
wlnum = GetOption( "FilterIncludeWatchlist" );

---------------------------

Sorry previous code was my mistake...

follow the code below :

Code:
 List=CategoryGetSymbols(categoryAll,0);


 if ( Status("stocknum") == 0 ) // GENERATE RANKING WHEN WE ARE ON VERY FIRST SYMBOL
{
StaticVarRemove( "values*" );

for ( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
 
   {
      SetForeign( symbol );
      Values = LastValue (C);
      RestorePriceArrays();
      StaticVarSet( "values" + symbol, Values );
    }

// perform ranking
StaticVarGenerateRanks( "rank", "values", 0, 1224 );

}

CategoryAddSymbol("",categoryWatchlist,3);

symbol = Name();

values = StaticVarGet ( "values" +  symbol );
rank = StaticVarGet ( "rankvalues" +  symbol );

AddColumn ( values, "values" );
AddColumn ( rank, "rank" );


Filter = 1;

SetSortColumns( 3 );
 
Last edited:
Top