Array inside Array is correct?

 

Hi, I'm trying to figure out if what I've written is correct or not, could I have some help?
The variable int O has [13] Array, so is it correct to skip it in the Y loop? Is it correct to insert Array O [Y] into Array Time []? Is also correct to assign to K = O [Y] ;?

I apologize for these trivial questions but I have some doubts about it.

Thank you




//Global scope
int O[13];    //Array for Index
int Y; int K; //Variable

// My code....
if(....){
  //Variables with Array for loop Y
  O[1]=i-3; O[2]=i-5; O[3]=i-8;  O[4]=i-11; O[5]=i-13; O[6]=i-15;O[7]=i-20; 
  O[8]=i-25;O[9]=i-30;O[10]=i-35;O[11]=i-40;O[12]=i-45;O[13]=i-50;
}

for(Y=13; Y>=1; Y--){
                       
   if(Time[O[Y]] <= Time[Max]) 
                          
     K=O[Y];
     ..........}


 
fly7680:

Hi, I'm trying to figure out if what I've written is correct or not, could I have some help?
The variable int O has [13] Array, so is it correct to skip it in the Y loop? Is it correct to insert Array O [Y] into Array Time []? Is also correct to assign to K = O [Y] ;?

I apologize for these trivial questions but I have some doubts about it.

Thank you





n-sized arrays are indexed from 0 to n-1.  

In your case -

 

Thank you for the reply! I understand that I have to initialize the Array but I did not understand it well.

Initialize the Array O [] but then inside the Array Time [] what do I insert?




//Global scope
int O[13];    //Array for Index
int Y; int K; //Variable

// My code....
if(....){
  //Variables with Array for loop Y
  O[1]=i-3; O[2]=i-5; O[3]=i-8;  O[4]=i-11; O[5]=i-13; O[6]=i-15;O[7]=i-20; 
  O[8]=i-25;O[9]=i-30;O[10]=i-35;O[11]=i-40;O[12]=i-45;O[13]=i-50;

  ArrayInitialize(O,0);ArrayInitialize(O,1); //...ecc

}

for(Y=13; Y>=1; Y--){
                       
   if(Time[O[Y]] <= Time[Max]) 
                          
     K=O[Y];
     ..........}
 

You got it wrong.

Array O[13] has elements with indices 0 to 12. 



//Global scope
int O[13];    //Array for Index
int Y; int K; //Variable

// My code....
if(....){
  //Variables with Array for loop Y
  O[0]=i-3; O[1]=i-5; O[2]=i-8;  O[3]=i-11; O[4]=i-13; O[5]=i-15;O[6]=i-20; 
  O[7]=i-25;O[8]=i-30;O[9]=i-35;O[10]=i-40;O[11]=i-45;O[12]=i-50;  // Note changed indices here

  // No need for this --> ArrayInitialize(O,0);ArrayInitialize(O,1); //...ecc

}

for(Y=12; Y>=0; Y--){
                       
   if(Time[O[Y]] <= Time[Max]) 
                          
     K=O[Y];
     ..........}


You should read array basics in the MQL4 documentation

Variables - Language Basics - MQL4 Reference
Variables - Language Basics - MQL4 Reference
  • docs.mql4.com
Variables - Language Basics - MQL4 Reference
 

Ok I understand now, so please confirm that Array in Array Time is correct?

if(Time[O[Y]] <= Time[Max]) 
 
fly7680:

Ok I understand now, so please confirm that Array in Array Time is correct?


O[Y] is an integer value, and it can be used as an array index, so it will work providing that you have enough values in the Time[] array.

As I see in your code, you are looking up to 50 bars back, so you must be sure that you have more than 50 bars on the chart.

 
Perfect thanks to the help!
Reason: