Seriously pesky bug!! :(

 

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:

for (g = 0; g < dSmoothDomPeriod[k] / 2; g ++)

{I3 += Q3[g];}

[/CODE]

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:

int temp = dSmoothDomPeriod[k] / 2;

for (g = 0; g < temp; g ++)

{I3 += Q3[g];}

[/CODE]

But it didn't help.

I tried using the MathFloor() function to explicitly truncate the expression:

int temp = MathFloor(dSmoothDomPeriod[k] / 2);

for (g = 0; g < temp; g ++)

{I3 += Q3[g];}

[/CODE]

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--

Files:
 

several small bugs; the main one concerns indeed the line:

for (g = 0; g < dSmoothDomPeriod[k] / 2; g ++) I3 += Q3[g];[/PHP] which should be (I think):[PHP]for (g = 0; g < dSmoothDomPeriod[k] / 2 && k+g < Bars; g ++) I3 += Q3[k+g];

Attached is the fixed version.

Files:
 

maybe you have a divide by zero in there crashing it all

 

You have:

double dSmoothDomPeriod[];[/CODE]

should be

int dSmoothDomPeriod[];

or

[CODE]double dSmoothDomPeriod[];

....

int x=dSmoothDomPeriod[k]/2;
 

Perhaps the bug would go away if you added "SetIndexEmptyValue(1,0);" to the init() method.

My guess is that without this, dSmoothDomPeriod[k] may be a quite large number for some k. Then the Q array becomes too large for the computer memory and bad things happen.

 

I tryed to realized your logic and couldn't. Lots of uncertainty as a:

I1[k] = dDeTrend[k + 3].

if k=Bars-6, you don't know dDeTrend[k + 3] because you didn't calculate it yet.

 

I'm putting my money on Michel, he's a good coder.

 

Yes, Michel gets the nod. I had already noticed that I needed to use Q3[k + g] and not just Q3[g], but I hadn't realized that the algorithm was invalid at some values of k + g. Michel's fix did the trick, and now the whole world can easily determine the signal to noise ratio of their favorite charts...

Thanks, Michel!!

 

a quick question

A quick coding question whilst everyone is around if that is ok.

I want my ea to take a trade every time the price is at a round number for example 1.4000 and when that trade is complete wait for the price to reach another round number to initiate another trade.

So its not a grid which is easy but I need the ea to recognise the price ends in 00.

I have tried using a few different things, I am even dividing the price by 100 and counting the length of the answer using stringlen() but the string function keeps adding zeros to the price.

Many thanks

 
bool IsRoundPrice = MathMod(Bid/Point,100) < 1;
Reason: