Looking for Help with Arrays

 
Hi,

I have some test code below and it is driving me crazy because it should work but doesn't, so I must not understand how arrays functions work in MQ4

What I think I am doing;

Create a Single Index array with 10 elements
Pass that array to a function
Resize the Global Array by 1 Index
Copy the passed Array to the Global Array
Do this 10 Times, so I should have 10 Indexes of 10 Elements each when I am done in the Global Array

But That is not what is happening after Index 0 and 1 starting on Index 2 the output from the Print statement shows empty values fro the Array.

Any Ideas?

Thanks
EK

//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

// This is a Test EA run it on the Back tester on any pair on anytime frame

int Counter = 0;
double GlobalArray[][10];
bool bRanOnce = False;
int Max = 10;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
   Counter = 0;
   return(0);
}

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   double MyArray[1][10];
   Counter = 0;
   
   while( Counter < Max && bRanOnce == False )
   {
      MyArray[0][0] = 1.0 * Counter;
      MyArray[0][1] = 2.0 * Counter;
      MyArray[0][2] = 3.0 * Counter;
      MyArray[0][3] = 4.0 * Counter;
      MyArray[0][4] = 5.0 * Counter;
      MyArray[0][5] = 6.0 * Counter;
      MyArray[0][6] = 7.0 * Counter;
      MyArray[0][7] = 8.0 * Counter;
      MyArray[0][8] = 9.0 * Counter;
      MyArray[0][9] = 10.0 * Counter;
      
      DoSomething(MyArray);
      Counter++;
   }
   
   if ( Counter == Max && bRanOnce == False )
   {
      int Index = 2;
      for(int i = 0; i < 10; i++)
         Print(GlobalArray[Index][i]);
      bRanOnce = True;
   }
   return(0);
}

void DoSomething(double& Arr[][])
{
   int Count = 0;
   int i = 0;
   
   Count = ArrayRange(GlobalArray,0);
   ArrayResize(GlobalArray, Count+1);
   ArrayCopy(GlobalArray,Arr,Count,0,0);
}
//+------------------------------------------------------------------+
 
We've changed sample in ArrayCopy topic in the new build. It was wrong.
  double array1[][6];
  double array2[10][6];
  // array2 is filled with some data
  ArrayCopyRates(array1);
  ArrayCopy(array2,array1,0,0,60);
  // array2 is having the first 10 bars from the history now (first bar considered as bar with index [Bars-1])
  ArrayCopy(array2,array1,0,Bars*6-60,60);
  // array2 is having the last 10 bars from the history now (last bar considered as current bar, bar wit index [0])



Use Count*10 or Count*ArrayRange(GlobalArray,1) for copying

 
Hello Slawa,

Thanks for the info.
This is what I have done and it works

ArrayCopy(GlobalArray,Arr,Count*ArrayRange(GlobalArray,1),0,Count*ArrayRange(GlobalArray,1));



Thanks this was driving me crazy for the past 3 days
EK

Reason: