Errors, bugs, questions - page 2493

 
Сергей Таболин:

Where to dig?

Need to wait - cubicle is busy (data was not calculated at the time of contact)

 
Comments not related to this topic have been moved to "Questions from MQL5 MT5 MetaTrader 5 beginners".
 
Comments not related to this topic have been moved to "Questions from MQL5 MT5 MetaTrader 5 beginners".
 

Caught an error

...tested with error "critical runtime error 502 in OnTester function (array out of range, module ....ex5, file ....mqh, line 237, col 51...

Here is the code itself:

//+-------------------
   // коррекция
   int      correcton_index[3];
            correcton_index[0]   = 1;
            correcton_index[1]   = (int)MathRound(balance_arr_size / 2);
            correcton_index[2]   = balance_arr_size;
   int      correcton_index3[5];
            correcton_index3[0]  =  1;
            correcton_index3[1]  = (int)MathRound(correcton_index[1] / 2);
            correcton_index3[2]  = correcton_index[1];
            correcton_index3[3]  = (int)MathRound((balance_arr_size - correcton_index[1]) / 2);
            correcton_index3[4]  = balance_arr_size;
   int      correcton_index7[9];
            correcton_index7[0]  = 1;
            correcton_index7[1]  = (int)MathRound(correcton_index3[1] / 2);
            correcton_index7[2]  = correcton_index3[1];
            correcton_index7[3]  = (int)MathRound((correcton_index3[2] - correcton_index3[1]) / 2);
            correcton_index7[4]  = correcton_index3[2];
            correcton_index7[5]  = (int)MathRound((correcton_index3[3] - correcton_index3[2]) / 2);
            correcton_index7[6]  = correcton_index3[3];
            correcton_index7[7]  = (int)MathRound((balance_arr_size - correcton_index3[3]) / 2);
            correcton_index7[8]  = balance_arr_size;
   
   double   correcton   = NormalizeDouble((balance_arr[correcton_index[2]-1] / balance_arr[correcton_index[1]-1]) / (balance_arr[correcton_index[1]-1] / balance_arr[correcton_index[0]-1]),8);
   double   correcton3[3];
   double   correcton7[7];
   double   crr         = 1;
   ArrayInitialize(correcton3,EMPTY_VALUE);
   ArrayInitialize(correcton7,EMPTY_VALUE);
   for(int i = 0; i < 3; i++)
   {
      correcton3[i]  = NormalizeDouble((balance_arr[correcton_index3[i+2]-1] / balance_arr[correcton_index3[i+1]-1]) / (balance_arr[correcton_index3[i+1]-1] / balance_arr[correcton_index3[i+0]-1]),8);
      crr            = NormalizeDouble(crr * correcton3[i],8);
   }
   correcton         = NormalizeDouble(correcton * crr,8);
   crr               = 1;
   for(int i = 0; i < 7; i++)
   {
      correcton7[i]  = NormalizeDouble((balance_arr[correcton_index7[i+2]-1] / balance_arr[correcton_index7[i+1]-1]) / (balance_arr[correcton_index7[i+1]-1] / balance_arr[correcton_index7[i+0]-1]),8);
      crr            = NormalizeDouble(crr * correcton7[i],8);
   }
   correcton         = NormalizeDouble(correcton * crr,8);

When i = 6,correcton_index7[i+2] (i+2=8) cannot well gobeyond the array's limits. All the more so because the previous loop didn't generate the same error. What am I missing?

 
Сергей Таболин:

Caught an error

Here is the code itself:

When i = 6,correcton_index7[i+2] (i+2=8) cannot well go beyond the array's limits. All the more so because the previous loop didn't generate the same error. What am I missing?

Incorrecton3[3]; you specify three items.
And the loop is called four times.

In
correcton7[7]; you specify seven elements.
And run the loop eight times
.

 
Roman:

Incorrecton3[3]; you specify three elements.
And you run the loop four times.

In
correcton7[7 ]; you specify seven elements.
And you execute the loop eight times.

Let's count on our fingers: i=0 and it is incremented by 1 with each loop. It works until i<7. The question for you (count on your fingers) is how many times the loop will be executed?

 
Yes, sorry, I didn't see that there is no loop in the condition =

Can't be a problem here ?
correcton_index[0]   = 1;
correcton_index3[0]  = 1;  
 correcton_index7[0]  = 1;
You specify zero elements and assign a value there.
 
Roman:
Yes, sorry, did not see that in the condition of the cycle does not =

Can't be a problem here ?
You specify zero elements and assign a value there.

Thanks for your willingness to help, but first, sort out the arrays yourself. )))

 
Сергей Таболин:

Thanks for your willingness to help, but start by sorting out the arrays yourself. )))

Array declaration and iteration over array elements are different )))

 
Roman:

Array declaration and iteration over array elements are different ))

   int      correcton_index7[9];        // объявление
            correcton_index7[0]  = 1;   // присвоение значения
            correcton_index7[1]  = (int)MathRound(correcton_index3[1] / 2);
Roman, before you lecture, learn how to do it yourself.
Reason: