Count Active Symbols Per Bar - Not Capturing Full History

exploration
Tags: #<Tag:0x00007f2d7a6e32b0>

#1

My objective is to track for each bar how many symbols in a watchlist were active (price >0), to be used to adjust # of positions to hold in a later step. I tweaked code from this forum, below, however the array "~Symctact" only starts counting several years after the 1st available symbol with data in the watchlist, testing with exploration. I tried with and without pad/align to the oldest symbol. Perhaps there is a needed code change, setting or simpler way to do this?

Thanks very much for the help.

Symctact = 0;

Filter    = 1   ;

 
wlist = GetOption("FilterIncludeWatchlist"); 
			symlist = CategoryGetSymbols( categoryWatchlist, wlist ) ; 
			numberOfSymbols = StrCount( symlist, "," ) + 1;
			WatchLSz = NoS  = numberOfSymbols;

// 
if (Status("stocknum") == 0)
{
StaticVarRemove("~SymbolCount");
StaticVarRemove("~Symctact");


for ( i = 0; ( symbol= StrExtract( symlist, i ) ) != ""; i++ )
{
	SetForeign(symbol); 
	
   		 Symctact = iif(c>0,1,0);
		 StaticVarAdd( "~SymbolCount", 1 );
          StaticVarAdd( "~Symctact", Symctact );
		
 	RestorePriceArrays();
	 
}		
}

	Var1 = StaticVarGet ( "~Symctact" );
	Var2 = StaticVarGet ( "~SymbolCount" );	
		AddColumn(c, "c");
		AddColumn( var1, "Symctact");
		Addcolumn(  Var2,"SymbolCount" );  
		Addcolumn(  WatchLSz,"WatchLSz" ); 

#2

Just bumping this up; anyone have any ideas, or is there other information I can provide to help clarify. Thanks!


#3

@swalk10 sorry to say but I too found your code to run into the same limitations. I tried a couple of things and I am guessing it is something we are setting incorrectly. But I have been looking through the user guide and can't figure it out. I bet its simple but just can't find it.

Hope some of the more knowledgeable users help out.


#4

Thanks man – much appreciated


#5

For what it is worth AmiBroker DOES NOT allow prices to be equal zero (or negative). ASCII importer will NOT import such data (unless you force ALLOWNEG) and all our plugins will NOT give prices = 0, so I don't see the point of doing what you are doing since in proper database there are NO symbols with price = 0.


#6

Tomasz,
Thanks for the note. To clarify, I am not testing for zero prices, I am testing for prices that are above zero using this formula

Symctact = iif(c>0,1,0);

That was my attempt to capture the # of "actively" traded symbols on that bar; I would be much obliged if you could point how to better get this done.
Scott


#7

@swalk10, just a thought, but would Volume be a better item to check?

Off the top of my head, I think "pad and align" would distort your data. Not sure what it does to volume.


#8

Thanks for that idea; I will try volume and report back today.
Note - turning on/off pad aligned to the oldest tickers did not seem to change the outcome.
Calc seems to count accurately both active tickers and total # of tickers in watchlist; problem is that is starts the "active ticker" count several years after the 1st ticker has data, no matter the start of the date range in the settings. However, other fields populate correctly on the 1st bar of the range.


#9

I tweaked the code to test for volume above 0; outcome is the same. I am also including picture of the output.
Code:

Symctact = 0;

Filter    = 1   ;
 
wlist = GetOption("FilterIncludeWatchlist"); 
			symlist = CategoryGetSymbols( categoryWatchlist, wlist ) ; 
			numberOfSymbols = StrCount( symlist, "," ) + 1;
			WatchLSz = NoS  = numberOfSymbols;

// 
if (Status("stocknum") == 0)
{
StaticVarRemove("*");

for ( i = 0; ( symbol= StrExtract( symlist, i ) ) != ""; i++ )
{
	SetForeign(symbol); 
	
		 StaticVarAdd( "~SymbolCount", 1 );  // Should be same as WatchLSz
		 
   		 Symctact = iif(V>0,1,0);  // Testing for activity
		 StaticVarAdd( "~Symctact", Symctact );
		
 	RestorePriceArrays(); 
}		
}

	Var1 = StaticVarGet ( "~Symctact" );
	Var2 = StaticVarGet ( "~SymbolCount" );	
		AddColumn(c, "c");
		AddColumn(v, "volume");
		AddColumn( var1, "Symctact");
		Addcolumn(  Var2,"SymbolCount" );  
		Addcolumn(  WatchLSz,"WatchLSz" );

Gap%20in%20Counting


#10

@swalk10, looking at the help on StaticVarAdd, the only suggestions I have (but can't currently test) are:

Make sure nothing in your Watchlist is in Group 253

Try adding the "default" values of keepall (TRUE) and persistant (FALSE) to your StaticVarAdd code.

Just grasping at straws here, but might be worth a look.


#11

FIXED

I setup a new clean database with just these symbols, using the volume trigger and now pad/align to oldest symbol does the trick. Not 100% sure which combination of things were necessary (clean database or volume trigger).

Thanks so much for everyone's help.