Download MetaTrader 5

Array Help

To add comments, please log in or register
Chris
65
Chris  

I have tried the search function but I dont know how to word it. 

 

 I want to load the previous 5 bars into an array for calculations later on in the program. I have the below so far but it does not work. So the data should be collected at the start of the new bar. These arrays have sent my head into a spin, when I hit debug it keeps saying array out of range.

 

If I get this working how do I then compare the data values loaded. ie Price closed outside of the bollinger bands? 

ArraySetAsSeries(arrayBBLOW,true);
ArrayFree(arrayBBLOW);

for(int l = current + 1; l < 5; l++)
          {   
      arrayBBLOW[l] = iBands(NULL,0,20,2.5,0,PRICE_CLOSE,2, l);
          }
 
/////////////////// Bollinger Bands High ///////////////////


  
ArraySetAsSeries(arrayBBHIGH, true);
ArrayFree(arrayBBHIGH); 

for(int h = current + 1; h < 5; h++)
          {   
      arrayBBLOW[l] = iBands(NULL,0,20,2.5,0,PRICE_CLOSE,1, h);
          }   
   
   
////////////////// Bar Close ///////////////////////////////////////////

   
ArraySetAsSeries(arrayclose,true);
ArrayFree(arrayclose);

for(int c = current + 1; c < 5; c++) 
      {
        arrayclose[c] = iClose(NULL,0,c);
        
       } 
Keith Watford
Moderator
10568
Keith Watford  
Using ArrayFree sets the array size to zero, so of course you get the "array out of range" error.
Chris
65
Chris  

Ok but how do I fix it?

 

Any help on the other questions? 

Keith Watford
Moderator
10568
Keith Watford  
   double arrayBBLOW[5];
   static datetime bar_time=0;

   if(Time[current]!=bar_time)
     {
      bar_time=Time[current];
      for(int x=0;x<5;x++)
        {
         arrayBBLOW[x]=iBands(NULL,0,20,2.5,0,PRICE_CLOSE,2,current+1+x);
        }
      if(Close[current+1]<arrayBBLOW[0] && Close[current+2]<arrayBBLOW[1])
        {
         //Do stuff
        }
     }
This may give you some pointers
To add comments, please log in or register