Inconsistent series populated by several for loops - how to fix?

Posted By: Mucko

Inconsistent series populated by several for loops - how to fix? - 11/14/16 19:36

I have several for loops that look at the last 10 bars for a high/low pattern. One loop records a high values if high pattern found, another loop records the low value if pattern found.

This data is then put into a WMA function for the last x values.

However, I am getting Error 041:Inconsistent Series! error. I believe the issue is that the arrays are not populated with the same length nor at the same time.

I am not sure how to fix this error - any help would be appreciated.

Code snippet (for High):

if (Close[1] > Open[1] and Close[0] < Open[0]) {
double u11 = High[1];

for (qq=1;qq<=len; qq++)
if (qq <= ttfinal)
qqtot+= u11;
else
qqtot += (High[qq - (ttfinal -1)]);


vars u1 = series((qqtot/len));
qqtot = 0;
hcount +=1;
}
vars upp = series(WMA(u1,len));
Posted By: Mucko

Re: Inconsistent series populated by several for loops - how to fix? - 11/15/16 05:07

Solved - I think

I think I have solved it with a bit of added code. Still need to test if it gives the same result as the original code (ported from MC/TS), but it does not give inconsistent errors any longer and can plot values which appear correct from initial appearances.

Here is what I had to add, removing the series function from inside the for loop but still inside the if conditional. Rather than loop I simply manually populate and increment.

This is defined outside the conditional:
q = series();

this is inside the conditional:
q[hcount] = (qqtot/len);
hcount +=1;
qqtot = 0;
© 2024 lite-C Forums