Blank Exploration Columns

Hi everyone,

I'm a newbie coming out of 6 hours of online AFL programming class and running into a dead end with some basic exploration code. I have been battling with the Ranking feature, specifically the StaticVarGenerateRanks function and related. I went through the Help files for said functions, coding examples in the Help file, this forum, articles from other AFL coding websites and forums. It has been over 72 hours fighting this code to no avail. So here I am.

My question: why is this simple code failing to populate the numerical Exploration columns?

I am getting the ticker column populated with each member from my list. That's great. But their assigned values ('factorA') and Rank columns remain blank no matter what I do.

I apologize if this is trivial but there is no moving forward from here if I can't figure this out. I am as much interested in the right code as I am in the 'why' my code failed.

Thanks in advance!

universe = "MyList";
StaticVarRemove( "factorA*");

for( i = 0; ( ticker = StrExtract( universe, i) ) != ""; i++)
{
    SetForeign( ticker);
    factorA = ROC( C, 50);
    RestorePriceArrays();
    StaticVarSet( "factorA" + ticker, factorA);
}     

StaticVarGenerateRanks( "rank", "factorA", 0, 1224);
factorA_values = StaticVarGet ( "factorA" + ticker);
factorA_rank = StaticVarGet ( "rankfactorA" + ticker);

Filter = 1;
AddColumn( factorA_values, "FactorA");
AddColumn( factorA_rank, "RankA", 1.0);
SetSortColumns(-4);


Replace this:

StaticVarGenerateRanks( "rank", "factorA", 0, 1224);
factorA_values = StaticVarGet ( "factorA" + ticker);
factorA_rank = StaticVarGet ( "rankfactorA" + ticker);

With this:

StaticVarGenerateRanks( "rank", "factorA", 0, 1224);
factorA_values = StaticVarGet ( "factorA" + Name());
factorA_rank = StaticVarGet ( "rankfactorA" + Name());

Thank you for answering. Unfortunately it still is not displaying anything.

Previously, I tried an implied version of what you recommended (as seen in this code piece here: Exploration Ranks) but it did not work either.

ticker = Name();
StaticVarGenerateRanks( "rank", "factorA", 0, 1224);
factorA_values = StaticVarGet ( "factorA" + ticker);
factorA_rank = StaticVarGet ( "rankfactorA" + ticker);

Does 'MyList' actually contain Symbols?

Are you running your Exploration over the same 'universe' Symbols?

If so please post up your full code.

Yes I am. The 'MyList' list is comprised of 9 tickers and stored as a Watch List.

Now the crazy part, if that can give you a better clue about what might be going on in the background, is that if I replace...

AddColumn( factorA_values, "factorA");

with...

AddColumn( factorA, "factorA");

then the 'factorA' column will populate with the related values for each ticker.
The 'RankA' column will never populate though no matter what I do.

Here is the full code below:

universe = "MyList";

StaticVarRemove( "factorA*");

for( i = 0; ( ticker = StrExtract( universe, i) ) != ""; i++)
{
    SetForeign( ticker);
    factorA = ROC( C, 50);
    RestorePriceArrays();
    StaticVarSet( "factorA" + ticker, factorA);
}     

StaticVarGenerateRanks( "rank", "factorA", 0, 1224);
factorA_values = StaticVarGet( "factorA" + ticker);
factorA_rank = StaticVarGet( "rankfactorA" + ticker);

Filter = 1;
AddColumn( factorA_values, "factorA");
AddColumn( factorA_rank, "RankA", 1.0);
SetSortColumns(-4);

Then 'universe' contains zero Symbols. It contains the string "MyList".

Use:

watchlistNumber = GetOption("FilterIncludeWatchlist");  
watchlist = CategoryGetSymbols(categoryWatchlist, watchlistNumber);

All of your ranking code should be inside a block like this:

if (Status("stocknum") == 0)
{
}

Otherwise you're redoing the ranking for every symbol that's processed.

Agreed. I saw this part in another topic but did not care to implement it yet since I wanted the code to work before making it more efficient.

I rewrote my code accordingly.


universe = "MyList";

if( Status( "stocknum" ) == 0 )
{
    StaticVarRemove( "factorA*");
 
    for( i = 0; ( ticker = StrExtract( universe, i) ) != ""; i++)
    {
    SetForeign( ticker);
    factorA = ROC( C, 50);
    RestorePriceArrays();
    StaticVarSet( "factorA" + ticker, factorA);
    }     

    StaticVarGenerateRanks( "rank", "factorA", 0, 1224);
}

ticker = Name();

factorA_values = StaticVarGet( "factorA" + ticker);
factorA_rank = StaticVarGet( "rankfactorA" + ticker);

Filter = 1;
AddColumn( factorA_values, "factorA");
AddColumn( factorA_rank, "RankA", 1.0);
SetSortColumns(-4);

Unfortunately, the output remains identical. Blank columns except for tickers and dates.

Screenshot

I will try what TrendSurfer suggested now. The ticker list is named as 'MyList' in Amibroker's Watch List folder. So I remain confused out to why the output would still return each ticker from said list if 'Universe' does indeed reference to a string showing zero symbol... But I guess I misunderstood.

Yes, the latest post from @TrendSurfer is definitely key. Right now you just have the name of the watchlist rather than the content (symbol list) of the watchlist.

Ok, it is working. Thank you very much @TrendSurfer and Matt for helping out.

For any beginner visiting the thread in the future, here is how I solved it using dummy language.

  • I had created a list named 'MyList' in Amibroker's Watch List folder that the code was supposed to pull tickers from.
  • You need to know that each one of your custom watch list is automatically attributed a number starting at 0 from the top upon creation. I was not aware of that. 'MyList' was the first one, hence referenced to with number 0.
  • On top of your code, you should not reference a variable pointing to your watch list name as I initially did it. Rather, you should declare your list name straight up without ' ' and reference it to its number like so.
MyList = CategoryGetSymbols(categoryWatchlist, 0);

The categoryWatchlist argument points to the folder where your list should be stored. You should change the number (here it is 0) with your watch list number as ranked in your Watch List folder.

For some reason, I did not need to use the following code line that was expected to go first. In fact, it threw in an error code when compiling it. I could not explain why.

watchlistNumber = GetOption("FilterIncludeWatchlist");

The rest of the code shown above is correct except for this line.

for( i = 0; ( ticker = StrExtract( MyList, i) ) != ""; i++)

Your user account isn't marked with License verified badge. Did you purchase AmiBroker license?

Only users with License verified badge are allowed to post on this forum.

So before posting, make sure you verify your license as explained here.

1 Like

Closed until user proves valid license