@Munichtrader I don't have data holes (that I know of) so I can't really test anything that helps. But you might consider adding a condition that prevents bars without data from being added. Perhaps something like,
StaticVarAdd( "~ROCCount", NOT IsNull( RSIBelow ) );
But your initial post was about the RSI and I think you were directed here by @Milosz to see the code and modify it to suit your needs.
Below I have made an attempt to use StaticVarAdd to create a count of number of symbols in a WL that meet a threshold for being below a certain RSI level. Test it out and see if it is accurate.
// Building a composite RSI reading for a WL
// Using StaticVarAdd and instead of SCAN, run EXPLORE
// Compare it to Herman's 2002 document on using AddToComposite
// pick watchlist in AA window
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, wlnum );
TestLevel = 20; // Param("TestLevel", 20, 5, 35, 1);
if( Status( "stocknum" ) == 0 )
// cleanup variables created in previous runs (if any)
StaticVarRemove( "~RSI*" );
StaticVarRemove( "~RSICount*" );
for( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
SetForeign( symbol );
RSIVal = RSI( 3 ); // put in the RSI you are interested in
//TestLevel = 20; // this line seems to work here or above - see line 8
RSIBelow = RSIVal < TestLevel;
StaticVarAdd( "~RSIBelow", RSIBelow );
StaticVarAdd( "~RSICount", NOT IsNull( RSIBelow ) );
svRSIBelow = StaticVarGet( "~RSIBelow" );
svRSICount = StaticVarGet( "~RSICount" );
PercentBelow = ( svRSIBelow / svRSICount ) * 100;
Filter = 1;
AddColumn( RSI( 3 ), "RSI3", 1.2, colorBlack, IIf( RSI( 3 ) < TestLevel, colorLime, colorDefault ) );
AddColumn( svRSIBelow , "Stocks with RSI Below ", 1.0 );
AddColumn( svRSICount, "Total Number of Stocks", 1.0 );
AddColumn( PercentBelow, "PercentBelow", 1.1, colorDefault, colorLightYellow );
Plot( PercentBelow, "PercentBelow", colorRed, styleThick );
The output I get looks like this on today's Dow 30 stocks.
If you find something useful for building a trading signal from this, I'd be interested in hearing back from you. Good luck.
P.S. @Tomasz look at the odd result for DD ? If anyone can explain that to me I would love to hear it.