Count Symbols (with conditions) by date

I am trying to learn how to count the total symbols with or without conditions on each day.

I have learned from past posts this simple code to get the total symbols and the total symbols which close above $100:

Filter=1; 
AddColumn(1, "Symbol Count"); 
AddColumn(C>100, "above$100");
AddSummaryRows( 1, 1.0 ); 

it produces the results I want for visualization purposes (see picture), but I can't figure out how to get the those numbers for further analysis or backtesting. I refer to this past post Number of symbols above MAs, was: Watchlist Inconsistency - AFL Programming - AmiBroker Community Forum

Could you @portfoliobuilder kindly let me know if your code in the link is the full code or partial code? I copied/modified it and was not able to produce any results, it was blank with only the column names after I press "explore". I know I need to learn a lot more, can anyone please kindly help?

Thank you very much

I guess that with "backtesting" you mean that you want to get that statistic calculated on EVERY HISTORICAL BAR separately.

This can be done using either composites AFL Function Reference - ADDTOCOMPOSITE or static variables AFL Function Reference - STATICVARADD

Example codes are in the manual that I provided links to.

In newest AmiBroker (>6.40) you can use sequence to automate scan and exploration runs necessary to first calculate multiple security stats and later display them.

Press "SEQUENCE" button in the Analysis window to run the code below.

#pragma sequence(scan, explore)

Version(6.40);
if( GetOption("PadAndAlignToReference") == False ) Error("This code must be run with Pad and Align turned ON");
 
if( status("action") == actionScan )
{
  if( status("stocknum") == 0 )
  {
       // remove any earier composite values
     StaticVarRemove("~Composite");
  }
  
  StaticVarAdd( "~Composite", C>100 ); 
  _exit();
}



Filter = Status("stocknum") == 0;

SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date/Time", formatDateTime );
AddColumn( StaticVarGet("~Composite"), "Count" );
2 Likes

Yes Tomasz, that's what I wanted to do, thank you so much.
By the way, could you please explain to me why Pad and Align needs to turn on? What happen if I use N-Bar Stop, how can I identify the artificially added bars and discount them when applying N-Bar stop? Thank you again!

@Tomasz, this GetOption() fieldname seems not to be documented in the 6.90 help files (for now I only installed the 32-bit version). It is only in the release notes.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.