Looking for some feedback on this. The script just crashes. Too many series? Is there a better way to do this? Or should this work I am just doing it wrong?

Looking for best correlated pairs.

I would imagine the best answer is use R, matlab, or python. However there must be a way in Zorro.

Code
#define ASSET_NUM 5
function run() 
{
	set(LOGFILE);
	BarPeriod = 1440;
	LookBack = 100;
	StartDate = 2018;
	EndDate = 2019;
	
	assetList("AssetsIB_ETF");
	
	string a1;
	string a2;
	int cnt = 0;
	int i = 0;
	int j = 0;
	for(i = 0; i < ASSET_NUM; i++)
	{
		a1 = Assets[i];
		asset(a1);
		vars p1 = series(priceClose());
		for(j = 0; j < ASSET_NUM; j++)
		{
			a2 = Assets[j];
			cnt++;
			asset(a2);
			vars p2 = series(priceClose());
			var corr = Correlation(p1,p2,30);
			
			string pair = strcat(strcat(a1,"-"),a2);
			plot(pair,corr,LINE,BLACK);
		}
	}
	
}