Metatrader Code Error. Please help.

 

Hello everyone,

I tried to improvise the SuperSR 6 a little bit. However, when I insert my code, the Metatrader stop working. I struggle with this problem for a while now, yet no idea why. Please help me.

Here is the part has error:

   double gap;
   double contract=(Contract_Step + Precision) * Point;
   int i=Bars;
   int shift;
   bool fractal;
   double price;
   int Rcount;
   while(i>=0)
     {
      shift=i + Shift_Bars;
      // Resistance
      price=High[shift+3];
      fractal=price>=High[shift+4] &&
      price>=High[shift+5] &&
      price > High[shift+2] &&
      price > High[shift+1] &&
      price > High[shift];
      gap=v1[i+1] - price;
      if (fractal && ((gap>=contract && Rcount >= 10) || gap < 0) )
        {
         if(gap>=contract)
         {
            v1[i]=price + (15 * Point);
            Rcount=1;
            r[i] = Rcount;
         }
         else
         {//This is the source of error. I'm sure

            for(int num_se_dot = Rcount; i + num_se_dot < Bars;num_se_dot += r[num_se_dot]) //r[] is the buffer contain the current # of dot of Resistance. Rcount is # of red dot right now. I'm sure those two work perfectly.
            {
               if(price >= v1[i + num_se_dot])
               {
                  break;
               }
            
            }
            v1[i]= v1[i + num_se_dot];
            Rcount=1;
            r[i] = 1;
         }
}

 

Thank you guys.

 

I think you have an endless loop:

 while(i>=0) { .. }

where do you decrease i like i--;

It might help if you put - if possible - i right behind while(i>=0) { i--;  //This works here as Bars-1 is the first bar

or use for(i=Bars-1;i>=0;i--){..}

 
Oh, I did decrease i at the bottom. I think the problem is something has to do with the way I access the buffer value.
 

hmm - do you use #property strict?

If so you should get an error at:  price=High[shift+3];  !!

Guess why ;)

 
No I don't use strict property.
 

well you do

i=Bars;
...
shift=i + Shift_Bars;
..
shift + 3; // now you are no where, beyond Bars!
the biggest accessible bar is Bars-1.
Reason: