I've been programming a long time and this is one of the most confusing bugs I've come across. It almost seems like a flaw in MT4 but I know from experience that it's most likely a mistake on my part. Try as I will, though, I can't for the life of me figure out what's wrong.
The offending indicator code is attached - BEWARE THAT IT WILL CRASH MT4!!
I've isolated the problem to line 107:
Code:
for (g = 0; g < dSmoothDomPeriod[k] / 2; g ++)
{I3 += Q3[g];}
It seems that MT4 gakks when I try to use the expression 'dSmoothDomPeriod[k] / 2' as a limit for the for() statement.
I tried putting the value into a separate variable of int type:
Code:
int temp = dSmoothDomPeriod[k] / 2;
for (g = 0; g < temp; g ++)
{I3 += Q3[g];}
But it didn't help.
I tried using the MathFloor() function to explicitly truncate the expression:
Code:
int temp = MathFloor(dSmoothDomPeriod[k] / 2);
for (g = 0; g < temp; g ++)
{I3 += Q3[g];}
Again, no dice.
I tried explicitly casting the value into an int type (rather clumsy):
Code:
int temp = StrToInt(DoubleToStr(MathFloor(dSmoothDomPeriod[k] / 2), 0));
for (g = 0; g < temp; g ++)
{I3 += Q3[g];}
Strike three.
If I replace the expression with a constant or with a variable loaded by a constant, everything is fine:
Code:
for (g = 0; g < 50; g ++)
{I3 += Q3[g];}
-->this works fine...
int temp = 50;
for (g = 0; g < temp; g ++)
{I3 += Q3[g];}
-->this also works fine...
But of course that's not what I need...
I even tried changing to a while() statement, using all the same variations as above:
Code:
int g = 0;
while (g < dSmoothDomPeriod[k] / 2)
{I3 += Q3[g];
g ++;}
Still no go.
Please take a look at the code and see if you can figure out what I need to get it to iterate using the results of the required expression without locking up the host application. This code is for a Hilbert Signal To Noise Ratio indicator, and if I can get it to work, it should be pretty cool... Seems like a very big if right now...
Z--