# Moving average buffer - array out of bounds

12

Hi all,

‌‌I'm trying to move one buffer into another. The buffer idea is:

b‌uffer2[0] = buffer1[0]‌
b‌uffer2[1] = buffer1[0]

b‌uffer2[2] = buffer1[1]
b‌uffer2[3] = buffer1[1]

b‌uffer2[4] = buffer1[2]
b‌uffer2[5] = buffer1[2]

b‌uffer2[6] = buffer1[3]
b‌uffer2[7] = buffer1[3]

e‌tc...

‌‌For some or other reason I get an array out of bound error, which doesn't make sense (to me). Does anyone know why this happens?

B‌elow and attached the code.

#property version   "1.00"

//--- indicator handles

int MA_handle;

//--- indicator buffers

double         MA_buffer1[];

double         MA_buffer2[];

int counter=0;

//+------------------------------------------------------------------+

//| Initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

{

MA_handle=iMA(_Symbol,PERIOD_H1,7,0,MODE_EMA,PRICE_CLOSE);

if(CopyBuffer(MA_handle,0,0,1000,MA_buffer1)<0){

return(0);

}

for(int i=0; i<10000; i++)

{

MA_buffer2[counter] = MA_buffer1[i];

MA_buffer2[counter+1] = MA_buffer1[i];

counter=counter+2;

}

//---

return(INIT_SUCCEEDED);

}‌

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
• www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Indicators Lines - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
MA.mq5 1 kb
Moderator
33271

```   if(CopyBuffer(MA_handle,0,0,1000,MA_buffer1)<0){
return(0);
}

for(int i=0; i<10000; i++)
{
MA_buffer2[counter] = MA_buffer1[i];
MA_buffer2[counter+1] = MA_buffer1[i];
counter=counter+2;
}
```
Moderator
33271