Download MetaTrader 5
To add comments, please log in or register
Use the Pocket to paste your content. It is convenient!
Gruwel
12
Gruwel 2017.03.10 09:44 

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 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);

  }‌

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
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
Alain Verleyen
Moderator
30635
Alain Verleyen 2017.03.10 09:46  
   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;
     }
Alain Verleyen
Moderator
30635
Alain Verleyen 2017.03.10 09:47  
/
To add comments, please log in or register