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; }
Forum on trading, automated trading systems and testing trading strategies
Hello,
Please EDIT your post and use the SRC button when you post code.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all,
I'm trying to move one buffer into another. The buffer idea is:
buffer2[0] = buffer1[0]
buffer2[1] = buffer1[0]
buffer2[2] = buffer1[1]
buffer2[3] = buffer1[1]
buffer2[4] = buffer1[2]
buffer2[5] = buffer1[2]
buffer2[6] = buffer1[3]
buffer2[7] = buffer1[3]
etc...
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?
Below and attached the code.
#property copyright "Copyright 2017"
#property link ""
#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);
}