Problems when backtesting for a wide range of years

Hello,

I have some problems when backtesting a large number of symbols for a wide range of years. As an example, please consider the following system:

SetOption("CommissionAmount", 0.00);
SetOption("InitialEquity", 10000);
SetOption("MaxOpenshort", 0 );
SetOption("MaxOpenLong", 5);
SetOption("MaxOpenPositions", 5);
SetOption("WorstRankHeld", 5);
SetOption("AllowPositionShrinking", True);
SetPositionSize(20, spsPercentOfEquity);
SetTradeDelays(0, 0, 0, 0);
SetOption("HoldMinBars", 1);
SetBacktestMode(backtestRegular);
RoundLotSize = 1;
BuyPrice = Close;
SellPrice = Close;

WLNUMBER = GetOption("FilterIncludeWatchlist");
LIST = CategoryGetSymbols(categoryWatchlist, WLNUMBER) ; 

if (Status("Stocknum") == 0 )
	{ 
	StaticVarRemove("VALUE_CLENOW_US*" ); 
	for (n = 0;(SYMBOL = StrExtract(LIST, n)) != ""; n++) 
		{ 
		SetForeign (SYMBOL);
		SLOPE = (exp(LinRegSlope(ln(C), 20))^52) - 1;
		RSQ = (Correlation(Cum(1), C, 20))^2; 
		SCORE = Max(0,SLOPE * RSQ);  
		RestorePriceArrays(); 
		StaticVarSet ("VALUE_CLENOW_US" + SYMBOL, SCORE); 
		} 
	StaticVarGenerateRanks("RANK","VALUE_CLENOW_US", 0, 1224); 
	} 

VALUE = StaticVarGet ("VALUE_CLENOW_US" + Name()); 
RANK = StaticVarGet ("RANKVALUE_CLENOW_US" + Name());

Buy = RANK < 5;
Sell = RANK >= 6; 
PositionScore = VALUE;

It works properly for 10 symbols from 1996 to 2017, as shown in the following image:

Backtest - 10 Stocks

However, it does not work properly for 100 symbols (including the previous 10 symbols) from 1996 to 2017, it is not until 2005 that the systems starts to trade.

Backtest - 100 Stocks

What is the problem? Is there any limit to the number of static variables stored? How could I have it solved?

Thank you in advance for your help.

Hi JP

I would start here: How do I debug my formula?

In particular inspect the array values with Explore, and the trade entries and exits with the Detailed Log. Those two things should help you to nut out why you have that blackout period.

One thing it definitely shouldn’t be is any kind of limitation of the static variables.

And check your data. You may simply not have data for all those symbols back to 1996 and your formula may be expecting to have them.

1 Like

I have the same problem. It seems that the first symbol in the back test dictates what the data range will be. How do I get around this so that I can back test the full range of my data?

I solved it! The data has to be padded for the whole range of dates the analysis. In Analysis, select Settings, then check "Pad and align all data to reference symbol: " and select a symbol whose data has the date range of the analysis.

1 Like

you have worstrankhelp in regular backtest. that's odd.