How to pass array to a function

 

hi, I had working mql4 expert, and after a new build it stopped to work as expected. Current build is 765

Namely, array passed to a function has no values.

Please see attached full code and of its execution output:

test.mq4

void OnTick()

{

ArrayResize(listOfLiveMNumbers,10,4);

ArrayResize(listOfStopMNumbers,10,4);

int resNums[][2];

ArrayResize(resNums,0);

Print("listOfLiveMNumbers");

ArrayPrintInt(listOfLiveMNumbers);

Print("listOfStopMNumbers");

ArrayPrintInt(listOfStopMNumbers);

ArrayMerge(listOfStopMNumbers, listOfLiveMNumbers, resNums);

}

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

int ArrayMerge(int &stopArray[][], int &liveArray[][], int &resultArray[][])

{

bool isfound=false;

int i=0,j=0,as=0;

if(ArraySize(liveArray)==0 || ArraySize(stopArray)==0)

{

Print("ArrayMerge: both arrays must have values");

Print("liveArray");

ArrayPrintInt(liveArray);

Print("stopArray");

ArrayPrintInt(stopArray);

return(-1);

}

..............[/CODE]

[CODE]

test EURCHF,M30: listOfLiveMNumbers

test EURCHF,M30: Array Size (ArrayPrintInt):20

test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )

test EURCHF,M30: listOfStopMNumbers

test EURCHF,M30: Array Size (ArrayPrintInt):20

test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )

test EURCHF,M30: ArrayMerge: both arrays must have values

test EURCHF,M30: liveArray

test EURCHF,M30: Array Size (ArrayPrintInt):0

test EURCHF,M30: Array ()

test EURCHF,M30: stopArray

test EURCHF,M30: Array Size (ArrayPrintInt):0

test EURCHF,M30: Array ()

Files:
test.mq4  4 kb
 
winters:
hi, I had working mql4 expert, and after a new build it stopped to work as expected. Current build is 765

Namely, array passed to a function has no values.

Please see attached full code and of its execution output:

test.mq4

void OnTick()

{

ArrayResize(listOfLiveMNumbers,10,4);

ArrayResize(listOfStopMNumbers,10,4);

int resNums[][2];

ArrayResize(resNums,0);

Print("listOfLiveMNumbers");

ArrayPrintInt(listOfLiveMNumbers);

Print("listOfStopMNumbers");

ArrayPrintInt(listOfStopMNumbers);

ArrayMerge(listOfStopMNumbers, listOfLiveMNumbers, resNums);

}

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

int ArrayMerge(int &stopArray[][], int &liveArray[][], int &resultArray[][])

{

bool isfound=false;

int i=0,j=0,as=0;

if(ArraySize(liveArray)==0 || ArraySize(stopArray)==0)

{

Print("ArrayMerge: both arrays must have values");

Print("liveArray");

ArrayPrintInt(liveArray);

Print("stopArray");

ArrayPrintInt(stopArray);

return(-1);

}

..............[/CODE]

[CODE]

test EURCHF,M30: listOfLiveMNumbers

test EURCHF,M30: Array Size (ArrayPrintInt):20

test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )

test EURCHF,M30: listOfStopMNumbers

test EURCHF,M30: Array Size (ArrayPrintInt):20

test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )

test EURCHF,M30: ArrayMerge: both arrays must have values

test EURCHF,M30: liveArray

test EURCHF,M30: Array Size (ArrayPrintInt):0

test EURCHF,M30: Array ()

test EURCHF,M30: stopArray

test EURCHF,M30: Array Size (ArrayPrintInt):0

test EURCHF,M30: Array ()

Your arrays are resized but not initialized with some values. You have to fill toyr arrays with some values

 
mladen:
Your arrays are resized but not initialized with some values. You have to fill toyr arrays with some values

Arrays are initialized with 0's this is what you can see in the output of the function ArrayPrintInt(listOfLiveMNumbers):

test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )

In the expert of course there are proper values, however behavior is the same ...

The same function prints "the same" array passed to the function and as a result - it does not have any elements.

test EURCHF,M30: stopArray

test EURCHF,M30: Array Size (ArrayPrintInt):0

test EURCHF,M30: Array ()
 
winters:
Arrays are initialized with 0's this is what you can see in the output of the function ArrayPrintInt(listOfLiveMNumbers).

In the expert of course there are proper values, however behavior is the same ...

The same function prints "the same" array passed to the function and as a result - it does not have any elements.

All is OK with the code you posted

Checked the attached : _test_array.mq4

Made some changes to initialize the array elements - so the error is not in the code of the "test.mq4"

Files:
 
mladen:
All is OK with the code you posted

Checked the attached : _test_array.mq4

Made some changes to initialize the array elements - so the error is not in the code of the "test.mq4"

Unbelievable .... ArraySize function does not return correct result !!! Thank you very much for your help !!!

 
winters:
Unbelievable .... ArraySize function does not return correct result !!! Thank you very much for your help !!!

Happy coding

Reason: