I am attempting to code a ranking/rotation strategy that uses a form of probability momentum. The concept is:

- CAR/SD = % chg (lookback) / Relative standard deviation (close, lookback)
- Normdist (CAR/SD)
- Normdist ((ticker CAR - Average Sector CAR)/Standard Deviation (Average CAR of sector))
- Rank Score averages 3+4

My apologies for again asking the incredibly generous folks of this forum for their guidance. In spite of rereading documentation+ other forum posts, I am stuck in two areas.

a) Using the "if ( Status( "stocknum" ) == 0 )" and inner watchlist loop

"for( i = 0; ( symbol= StrExtract( symlist, i ) ) != ""; i++ ) " , some steps require creating averages & totals, then working off those intermediate summation measures within the next steps. I am struggling to understand best practice in storing/retrieving these measurements â€“ where in the loop structure, as the â€śfinalâ€ť results only occur after the last symbol is complete, but those measures are needed in the subsequent calculation steps for each symbol. In the pasted code I calculate the # of active tickers per bar (StaticVarAdd( "~Symctact", Symctact ), and total ROC (StaticVarAdd( "~Roc1fil", Roc1fil )), and use that to calc average ROC across all symbols that bar. I use the StaticVarGet within the loop as this seems to grab the â€śfinal totalsâ€ť results accurate, but not sure why/how. Problem: I attempt to staticvarset & StaticVarGet the core variable â€ś~PctAvgROCxâ€ť (where x is different attempt types), however values are not getting extracted. Viewing the trace, I see the values are getting set here, so I need to change something.

b) The formula I am working towards calls for calculating Standard Deviation across the different tickers, bar by bar. I canâ€™t figure out how to load in a cross sectional array of values to feed into Standard Deviation. I suspect a custom loop is needed â€“ any examples would be appreciated.

Thank again.

Scott

```
_SECTION_BEGIN("Rank Loop");
symlist=WatchLSz = NoS = numberOfSymbols = Symctact= 0;
// ----------------------------------------------------------------------------------------------
wlist = GetOption("FilterIncludeWatchlist");
symlist = CategoryGetSymbols( categoryWatchlist, wlist ) ;
numberOfSymbols = StrCount( symlist, "," ) + 1;
WatchLSz = NoS = numberOfSymbols;
// "stocknum" - gives you the ordinal number of currently analyzed symbol - hence runs on once at start of backtest only
if ( Status( "stocknum" ) == 0 )
{
ProbLB=CondOptimize("Prob Lookback",60,5,80,5);
// fill input static arrays Every symbol in watchlist --------------------------------
for( i = 0; ( symbol= StrExtract( symlist, i ) ) != ""; i++ ) // Here i=1 symbol - looping through every symbol in watchlist of symbols
{
SetForeign(symbol);
// ---------------------
StaticVarAdd( "~SymbolCount", 1 ); // Should be same as WatchLSz = "~SymbolCount" is new static variable, Counting # of active symbols on 1 bar
Symctact = iif(V>0,1,0); // Testing for activity V = volume C= CLOSE = closing price
StaticVarAdd( "~Symctact", Symctact ); // # active ticker on that bar = works
ROClb = ROC(C,ProbLB); // Individual CAR - roc = rate of change = 20 day % chg
StDevval = (stdev( close, ProbLB )/ma(close,ProbLB))*100; // Individual Relative SD %
CARSD = ROClb/StDevval;// Individual CAR/SD
NDCARSD = NormDist(CARSD, 0, 1, True ); // IND Norm Dist of CAR/SD = indicatical to Excel = time array
Roc1fil = iif(V>0,ROClb,0); // filtered individual CAR
StaticVarAdd( "~Roc1fil", Roc1fil ); // store Total ROC of tickers in watchlist
SDfil = iif(V>0,StDevval,0); // filtered ind SD
StaticVarAdd( "~SDfil", SDfil ); // store Total SD
ActiveTicka = StaticVarGet ( "~Symctact" ); // get # active tickers
ROC1TOTa = StaticVarGet ( "~Roc1fil" ); // get Total filtered ROC
if( DBVOn ) _TRACE(" ROC1TOTa + sym " + ROC1TOTa + " " + symbol);
PctAvgROCnoget = (Roc1fil/Symctact) ;
if( DBVOn ) _TRACE(" PctAvgROCnoget + sym " + PctAvgROCnoget + " " + symbol);
PctAvgROC = (ROC1TOTa/ActiveTicka) ; // % AVg ROC for the watchlist that day - This seems to work, as CARDIFF seems right - but can't get this to output
if( DBVOn ) _TRACE(" PctAvgROC + sym " + PctAvgROC + " " + symbol);
staticvarset("~PctAvgROC3 " ,PctAvgROC);
CARDiff = ROClb - PctAvgROC; // Ind Car diff vs the avg ROC
SDAVGROC = stdev( (PctAvgROC) , ProbLB); // Std Dev of Avg ROC time array but not between tickers/symbols
NDProbM= NormDist( (CARDiff/SDAVGROC) , 0, 1, True ); // IND Norm Dist
Ratingf = round((NDProbM + NDCARSD)/2 )*10;
/* Objective:
SDWLROC = stdev(ROClb OR Roc1fil, across/between all tickers in the watchlist loop);
How to read in each ticker value in current bar as an array?
Is matrix processing necessary here?
Matrix = mult dimensional */
RestorePriceArrays();
staticvarset("~PctAvgROC " ,PctAvgROC); // all symbols store % AVg ROC
staticvarset("~PctAvgROCg " + symbol ,PctAvgROC); // all symbols store % AVg ROC
staticvarset("~ROClb" + symbol,ROClb); // Individual CAR
staticvarset("~StDevval" + symbol ,StDevval); // Individual SD
staticvarset("~CARSD" + symbol,CARSD); // Individual CAR/SD
staticvarset("~NDCARSD" + symbol,NDCARSD); // IND Norm Dist of CAR/SD
staticvarset("~CARDiff" + symbol,CARDiff); // store CAR Diff vs avg
staticvarset("~SDAVGROC" + symbol,SDAVGROC); // Std Dev of Avg ROC
staticvarset("~NDProbM" + symbol,NDProbM); // store Norm Dist of Car
staticvarset("~RatingP" + symbol,RatingP); //
staticvarset("~Ratingf" + symbol,Ratingf); //
StaticVarSet( "Ratingf" + symbol, Ratingf);
}
StaticVarGenerateRanks( "rank","Ratingf", 0, 1224 );
}
_SECTION_END();
// ============================== end of Rank Loop =====================================
_SECTION_BEGIN("Extract & Manage Ranks");
symbol = Name();
SymbolCountg = StaticVarGet ( "~SymbolCount" );
Symctactg = StaticVarGet ( "~Symctact" );
ROCLBg = StaticVarGet ( "~ROClb" + symbol );
StDevvalg = StaticVarGet ( "~StDevval" + symbol );
CARSDg = StaticVarGet ( "~CARSD" + symbol );
NDCARSDg = StaticVarGet ( "~NDCARSD" + symbol );
ROC1TOTa2 = StaticVarGet ( "~Roc1fil" );
PctAvgROC2 = StaticVarGet ( "~PctAvgROC" );
PctAvgROCg = StaticVarGet ( "~PctAvgROCg" + symbol );
PctAvgROC3 = StaticVarGet ( "~PctAvgROC3" );
NDProbMg = StaticVarGet ( "~NDProbM" + symbol );
CARDiffg = StaticVarGet ( "~CARDiff" + symbol );
SDAVGROCg = StaticVarGet ( "~SDAVGROC" + symbol);
Ratingpg = StaticVarGet ( "~Ratingp" + symbol);
Ratingfg = StaticVarGet ( "~Ratingf" + symbol );
Var1 = StaticVarGet ( "Ratingf"+ symbol );
// extract rank value
rank1o = StaticVarGet ( "rankRatingf"+ symbol );
rank1 = (WatchLSz +1) - rank1o;
_SECTION_END();
```