Array out of range error build 600>. (EA to find peaks valleys)

 

Hi all!

I am developed an EA to find peaks and valleys.

It worked well its job, but when the mt4 build 600> appeard i tried to make it in new language, but i cant realize the problem of array out of range, and the debugger is showing stupid things :(

If somebody smarter programmer than me :) could solve this problem, i would be happy!

I attached the part of EA (there is nothing stuff to trade just the finding method of peaks valleys).

Somebody please help me!!! :)

Sorry for my poor english!

Files:
 
I'm Not going to figure out what's going on in 500 lines of your code. Start adding print statements at beginning and end of routines and bisect it down to the line and your variable values so you find out why.
 
Kajos2250:

Hi all!

I am developed an EA to find peaks and valleys.

It worked well its job, but when the mt4 build 600> appeard i tried to make it in new language, but i cant realize the problem of array out of range, and the debugger is showing stupid things :(

If somebody smarter programmer than me :) could solve this problem, i would be happy!

I attached the part of EA (there is nothing stuff to trade just the finding method of peaks valleys).

Somebody please help me!!! :)

Sorry for my poor english!

If you have Bars count in a chart, candles are enumerated from 0 to Bars-1.

      for(i=firstBars-1; i>=0; i--)

You are using an dynamic array, which size is 0 :

      Print("Size peakPrice = ",ArraySize(peakPrice));
      if(High[ii]>peakPrice[0]) // peak increasing               Out of range, size is 0, element 0 doesn't exist
 
angevoyageur:

If you have Bars count in a chart, candles are enumerated from 0 to Bars-1.

You are using an dynamic array, which size is 0 :


You are Genius! :)

Thank you very much your fast answer, i didnt think it will be so fast :)

 
Kajos2250:


You are Genius! :)

Thank you very much your fast answer, i didnt think it will be so fast :)

You are welcome.
 
angevoyageur:

If you have Bars count in a chart, candles are enumerated from 0 to Bars-1.

      for(i=firstBars-1; i>=0; i--)

You are using an dynamic array, which size is 0 :

   Print("Size peakPrice = ",ArraySize(peakPrice));
      if(High[ii]>peakPrice[0]) // peak increasing
I missed the for loop starting at Bars, but when you change the for loop you must also change the following if
      for(i=firstBars; i>=0; i--)
        {
         if(i==firstBars)           {
            peakCnt=makeNewPeak(peakTime,peakPrice,peakFibo,
                                valleyTime,valleyPrice,valleyFibo,
                                Time[i],High[i]);
I discounted peakPrice[0] since the first call to makeNewPeak resizes the arrays.
 
WHRoeder:
I missed the for loop starting at Bars, but when you change the for loop you must also change the following if I discounted peakPrice[0] since the first call to makeNewPeak resizes the arrays.

Right. I didn't check all the code, just the "array-out-of-range" error.

Thank you for correcting me.

 

Thank you guys again, you are really smart and skilled programmers :)

I have to practice more debuging, but hope i will be getting better!

Have a good day!

 

Hi Guys again!

Is it possible even there are some bug in new MT4?

That discoussed peakPrice[0] must be good! Before some rows the makeNewPeak procedure would add value to it!

But the array out of range error msg is comeing... :(

Do you have some idea?

And if there is no this error, i print by Comment() the element of arrays and i can see the values is incorrect. It would have to be some price (GU 1.66547 but there are some 4.12145..e-314)...

Under the oldest MT4 was everithing correct, but last week i lost much money caouse of this :(

Please help me if you can!

int makeNewPeak(datetime &peakTime[],double &peakPrice[],double &peakFibo[],

datetime &valleyTime[],double &valleyPrice[],double &valleyFibo[],

datetime time,double price)

{

int peakCnt=ArraySize(peakTime);

ArraySetAsSeries(peakTime,true);

ArraySetAsSeries(peakPrice,true);

ArraySetAsSeries(peakFibo,true);

//ArraySetAsSeries(peakSR, true);

//ArraySetAsSeries(peakSRTime, true);

int aTmp=ArrayResize(peakTime,peakCnt+1,1000);

ArrayResize(peakPrice,peakCnt+1,1000);

ArrayResize(peakFibo,peakCnt+1,1000);

//ArrayResize(peakSR, peakCnt+1);

//ArrayResize(peakSRTime, peakCnt+1);

ArraySetAsSeries(peakTime,false);

ArraySetAsSeries(peakPrice,false);

ArraySetAsSeries(peakFibo,false);

//ArraySetAsSeries(peakSR, false);

//ArraySetAsSeries(peakSRTime, false);

peakTime[0]=time;

peakPrice[0]=price;

//peakFibo[0] = percent((peakPrice[1]-valleyPrice[0]),(peakPrice[0]-valleyPrice[0]));

return(peakCnt+1);

}

 

Sorry, i think it was my fault, i used wrong reserve_size of the ArrayResyze()...

 
But at least i learnd to use the debugger :)
Reason: