Well, I have solved something... I just noticed that the error I was getting with my zScore
was because some candles before this error I was getting something like #INF00 error, and I assumed that there was a division by zero somewhere. And yes, in fact there's a division of the two price series.
It turns out that priceClose() sometimes returns zero. Don't ask me why, because I think it shouldn't. So I've just coded an indicator to eliminate these zeroes:
var myFilter(var* Data, double number)
{
int __i = 0;
while (Data[__i] == number) __i++;
if (Data[__i] != number) return(Data[__i]);
}
Passing the price series as first parameter and 0.0 as second parameter I have solved this error of zero division.
Also, I had a lot of outliers in the zScore, maybe due to incredibly huge gaps in history or just due to flash crashes. To eliminate these outliers, I've written another function:
var removeOutliers(var* Data, double number)
{
int __i = 0;
while (abs(Data[__i]) >= abs(number)) __i++;
if (abs(Data[__i]) <= abs(number)) return(Data[__i]);
}
being "number" the outlier level you want to chop off. Previously I had seen in a chart what I had in Data, in order to see intuitively where I should set the threshold for the outliers.
I'm happier now, after having found a solution to some of my problems.
I will keep on my research with Zorro Trader, I think it is one the best options I have for doing multiasset backtests...