Hi All,
I am trying to adapt some code that I found on these boards that @portfoliobuilder had suggested back in 2019.
I am simply trying to total the number of stocks in a given watchlist tradiing above their 20 and 50day MAs.
Code seems to work fine on some watchlists but not others. Screenshots at bottom. You can see that it is picking up the correct number of symbols in the list but not providing the totals in all instances.
Wondering if someone is able to spot what is going wrong.
Thanks to @portfoliobuilder for the original code and to all who spend the time to read my query.
Thanks Dejaco
// select your WL in the Analysis window
wlnumber = GetOption( "FilterIncludeWatchlist" );
watchlist = CategoryGetSymbols( categoryWatchlist, wlnumber );
SymbolCount = StrCount(watchlist, ",") + 1;
AboveTwentyTotal = 0;
AboveFiftyTotal = 0;
TwentyEMA = EMA(Close,20);
FiftyMA = MA(Close,50);
for( num = 0; ( symbol = StrExtract( watchlist, num ) ) != ""; num++ )
{
SetForeign( symbol );
AboveTwenty = Close > TwentyEMA;
AboveTwentyTotal += AboveTwenty;
AboveFifty = Close > FiftyMA;
AboveFiftyTotal += AboveFifty;
RestorePriceArrays();
}
/// Exploration ///
Filter = Status("LastBarInRange") AND Status( "stocknum" ) == 0;
SetOption("NoDefaultColumns",True);
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn( AboveTwentyTotal, "Trading above 20EMA" , 1.0 );
AddColumn( AboveFiftyTotal, "Trading above 50MA" , 1.0 );
AddColumn( SymbolCount, "Total # of Symbols in WL", 1.0);