I have been using premium data for several years. I have one strategy where I have to loop through all constituaents of the S&P 500 Current and Past. My backtest is extremely slow.... can anyone look at the code and see if there is a way to speed this up.... Here is what the code does

Backtest back to 1991

If the stock is in S&P500 at the time IIf(NorgateIndexConstituentTimeSeries("$SPX")

Set Yield Variable... Set DivYears (# of years of constant or increasing divs)

I then rank on yield variable
Finally I have filters and buy logic to buy on volatility..... my problem is the slow speed it loops through the watchlist.... im hoping there is a way to speed this up... thanks.. here is my code for the watchlist loop....
if ( GetOption( "ApplyTo" ) == 2 )
{
wlnum = GetOption( "FilterIncludeWatchlist" );
List = CategoryGetSymbols( categoryWatchlist, Wlist ) ; //************S&P 500 HISTORICAL CONST CONFIRM WATCHLIST **************************
}
else
if ( GetOption( "ApplyTo" ) == 0 )
{
List = CategoryGetSymbols( categoryAll, 0 );
}
else
{
//Error( "The formula works fine if your ApplyTo setting is 'Filter' or 'All' " );
}
if ( Status("stocknum") == 0 ) // GENERATE RANKING WHEN WE ARE ON VERY FIRST SYMBOL
{
StaticVarRemove( "values*" );
StaticVarRemove( "DivYrs1*" );
for ( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{
SetForeign ( symbol );
ODIV = NorgateAllDividendsTimeSeries(1);
Bars0a = BarsSince(Odiv);
Bars1a = Ref(bars0a,1);
B1a = bars1a+2;
Bars2a = Ref(bars0a,b1a);
B2a = B1a+bars2a+1;
Bars3a = Ref(bars0a,b2a);
B3a = B2a + bars3a+1;
Bars4a = Ref(bars0a,b3a);
Bars12a = bars1a+bars2a+bars3a+bars4a;
Div252a = Sum(ODIV,bars12a);
AnnualDividend = IIf(ODIV>0,div252a,Ref(div252a,Bars0a));
DivRise = AnnualDividend>0 AND AnnualDividend>= Ref(AnnualDividend*.99,bars1a);//Dividend Increase Years//////////////////////////////////////////
DivFall = AnnualDividend<Ref(AnnualDividend*.99,bars1a);
DivRise = ExRem(DivRise,Divfall);
DivFall = exrem(DivFall,DivRise);
DivIncreaseYrs = BarsSince(DivRise)/250;
Yield=IIf(DivIncreaseYrs<YrsDiv,100,AnnualDividend/Close);
values = IIf(NorgateIndexConstituentTimeSeries("$SPX"),yield,100);
DivYrs1 = IIf(NorgateIndexConstituentTimeSeries("$SPX"),DivIncreaseYrs,0);
RestorePriceArrays();
StaticVarSet ( "values" + symbol, values );
StaticVarSet ( "DivYrs1" + Name() , DivYrs1 );
_TRACE( symbol );
}
StaticVarGenerateRanks( "rank", "values", 0, 1224 );
}
symbol = Name();
values = StaticVarGet ( "values" + symbol );
rank = StaticVarGet ( "rankvalues" + symbol );
// FILTERS
Capitalization = GetFnData("SharesOut")*Close;
DailyDollar = MA(Volume*Close,252);
VolFilter1 = Capitalization < 500000000;
dollarFilter = dailydollar < 250000;
VolFilter = Volfilter1 OR dollarfilter;//
RankFilter = rank > 100;
Volatility =IIf(volfilter,100,IIf(rankfilter,100,StDev((CRef(C,1))/Ref(C,1),Volper)*100));
VolAvg = IIf(NorgateIndexConstituentTimeSeries("$SPX"),Volatility,100);
VolAvg = IIf(IsFinite(Volavg),Volavg,100);
ScoreAvg = WMA(volavg,20);
Score= 100scoreavg;
PositionSize = 100/Totalpositions;
PositionScore = Score;
PositionScore = IIf(PositionScore < 0, 0, PositionScore);
PositionScore = IIf(Rebalance, PositionScore, scoreNoRotate);
Filter = Rebalance;