SetIndexBuffer in the for loop

 

Dear Community,

is there a possibilty to set the Index Buffer in a for loop? Something like this:

   for(int i=1;i<40;i++){
      SetIndexBuffer(i,HighLineBuffer&i);   
   }

Unfortunately, the code will not compile. Do I really need to write everything individually?



Thank you for your help

 
user_123:

Dear Community,

is there a possibilty to set the Index Buffer in a for loop? Something like this:

Unfortunately, the code will not compile. Do I really need to write everything individually?



Thank you for your help

Yes it's possible but not this way. You have to use an array, but as a buffer as already an array and SetIndexBuffer doesn't allow multidimensional array :

struct Buffer
  {
   double buffer[];
  };

Buffer indi[40];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   for(int i=1;i<40;i++){
      SetIndexBuffer(i,indi[i].buffer);   
   }   
//...
  }
Reason: