Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 18

 
Artyom Trishkin:
That's not very good. Did you probably get warnings at compile time? You need to get rid of the causes of the warnings in such cases, not #property strict
When #property strict was written, the compiler gave errors in each for() loop that the variables must have a type, so I had to write int i and int p in each loop. After that the compiler didn't generate errors, but the line didn't build. When I removed #property strict, the compiler no longer required to declare the type in each cycle, and the line was built.
 

I have topped up my balance and now I can't find the terminal with the real account.

 
Timur1988:
When #property strict was spelled out, the compiler generated errors in every for() loop that variables must have a type, so I had to write int i and int p in every loop. After that the compiler didn't generate errors, but the line didn't build. When I removed #property strict, the compiler did not require to declare the type in each loop, and the line was built.

A typical case of exploiting implicit errors in logic. Once the compiler has become "stricter", the self-deception is slowly disappearing.

I was wondering why there were so many identical loops?

And why don't you bother in any way with the error "out of array" when running the indicator on the chart?

For example, here:

    for(int i=1; i<n; i++)
      {    
      for(int p=0; p<m; p++)
         {  
         sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];                                        
         sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
         }        
      }
 
7u6y5t4r3e2w1q:

I have topped up my balance and now I can't find the terminal with the real account.

The terminal is the same, you just need to re-login to a real account. How to do it: File - Connect to trading account - specify the account number, password and server in the window that appears. All these data was given by the DC, in case of anything ask them.
 
Timur1988:
When #property strict was spelled out, the compiler gave errors in every for() loop that variables must have a type, and so I had to spell int i and int p in every loop. After that the compiler didn't generate errors, but the line didn't build. When I removed #property strict, the compiler no longer required to declare the type in each cycle, and the line was built.

the answer is very simple - you have a trivial array overrun - and your indicator stops working because of this error

    for(int i=1; i<n; i++)
      {    
      for(int p=0; p<m; p++)
         {  
         sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];                                        
         sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
        
         }        
      }
  
   for(int i=1; i<n; i++)
      {    
      for(int p=0; p<m; p++)
         {      
         Mx[i][p]=sum_x[p+1][m-1]/(n-1);  
         My[i][p]=sum_y[p+1][m-1]/(n-1);

you can see this error at runtime - start the indicator and look at the log file on the Terminal - Experts tab:

 
Vitalie Postolache:

This is a typical case of exploiting implicit logical errors. ...

Overriding an array is a gross error in logic -- and one cannot call such an error "implicit".
 
Vitalie Postolache:

A typical case of exploiting implicit errors in logic. Once the compiler has become "stricter", the self-deception is slowly disappearing.

I kept wondering, why are there so many identical loops?

And why don't you bother in any way with the error "out of array" when running the indicator on the chart?

For example, here:

    for(int i=1; i<n; i++)
      {    
      for(int p=0; p<m; p++)
         {  
         sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];                                        
         sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
         }        
      }


How to calculate the sum of closing prices in each dimension?
As for the same cycles, I, because of my limited knowledge of programming and algorithms, have not thought of anything better to select the element of the array from the required dimension, which was necessary for substitution in the formula.
 
Andrey F. Zelinsky:

the answer is very simple - you have a trivial array overrun - and your indicator stops working because of this error

    for(int i=1; i<n; i++)
      {    
      for(int p=0; p<m; p++)
         {  
         sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];                                        
         sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
        
         }        
      }
  
   for(int i=1; i<n; i++)
      {    
      for(int p=0; p<m; p++)
         {      
         Mx[i][p]=sum_x[p+1][m-1]/(n-1);  
         My[i][p]=sum_y[p+1][m-1]/(n-1);

you can see this error at the execution stage - start the indicator and look at the log file on the Terminal tab - Experts:

Could you please tell me how to fix this error?
 
Timur1988:
Then how do you calculate the sum of the closing prices in each dimension???
As for the same cycles, due to my limited knowledge of programming and algorithms, I couldn't think of anything better to select that element of the array from the desired dimension, which was needed to substitute in the formula.

For example, like this:

     for(int i=1; i<n; i++)

      {    
      for(int p=1; p<m; p++)
         {   
         sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];                                        
         sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
         }         
      }
 
Timur1988:
Can you please tell me how to fix this error?

To correct this error, you need to understand your formula - what, why and how you are counting.

And only then you will be able to work out your algorithm and eliminate the error outside the array.

By "gut feeling" method and not understanding your formula - you will eliminate error, but you will make wrong calculation.

p.s. Explain in detail what you are calculating -- comment on your code in detail -- and then we will understand how to fix the error.

Reason: