Download MetaTrader 5
To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
Lines_ss
57
Lines_ss 2014.04.04 09:18 

Hello,

am not sure whether I understood the function ArrayCompare right or not. From my understanding I thought I could compare the content of 2 Array.

I tried the following code:

extern int MaxWorkingOrders = 1;

// Global variable

int array_buyTicket[];

int array_sellTicket[];

int array_toCompare[];

// During inititalization:

ArrayResize(array_buyTicket,MaxWorkingOrders);

ArrayResize(array_buyTicket,MaxWorkingOrders);

ArrayResize(array_toCompare,MaxWorkingOrders);

ArrayInitialize(array_toCompare, 0);

// Somewhere in the code:

// force an error

array_buyTicket[0] = 397;

Print("array_buyTicket_",0," = ",array_buyTicket[0]);

// force an error end

int Array_BuyTicketIsEmpty = ArrayCompare(array_buyTicket,array_toCompare,0,0,WHOLE_ARRAY);

Print("Array_BuyTicketIsEmpty: ",Array_BuyTicketIsEmpty);

int Array_SellTicketIsEmpty = ArrayCompare(array_sellTicket,array_toCompare,0,0,WHOLE_ARRAY);

Print("Array_SellTicketIsEmpty: ",Array_SellTicketIsEmpty);

The result which I get during execution is:

11:08:57 2010.01.18 11:00 Forex_ORB-v1.10.1 GBPJPY,M5: array_buyTicket_0 = 0

11:08:57 2010.01.18 11:00 Forex_ORB-v1.10.1 GBPJPY,M5: array_sellTicket_0 = 0

11:08:57 2010.01.18 11:00 Forex_ORB-v1.10.1 GBPJPY,M5: array_buyTicket_0 = 397

11:08:57 2010.01.18 11:00 Forex_ORB-v1.10.1 GBPJPY,M5: Array_BuyTicketIsEmpty: 0

11:08:57 2010.01.18 11:00 Forex_ORB-v1.10.1 GBPJPY,M5: Array_SellTicketIsEmpty: 0

So my question now: Why do I get the value Array_BuyTicketIsEmpty: 0 even the arrays are not equal. Does the function ArrayCompare only compare the size of the array but not the content of the array?

Thanks in advance!

qjol
3243
qjol 2014.04.04 09:44  

ArrayCompare

Returned value

·-1, if array1[] less than array2[]

·0, if array1[] equal to array2[]

·1, if array1[] more than array2[]

·-2, if an error occurs due to incompatibility of the types of compared arrays or if start1, start2 or count values lead to falling outside the array.

Lines_ss
57
Lines_ss 2014.04.04 11:43  
qjol:

ArrayCompare

Returned value

·-1, if array1[] less than array2[]

·0, if array1[] equal to array2[]

·1, if array1[] more than array2[]

·-2, if an error occurs due to incompatibility of the types of compared arrays or if start1, start2 or count values lead to falling outside the array.

As u can see from my code i loade the array_buyTicket with a value of 397, array_toCompare has still the value 0. So the array content is not equal. Does ArrayCompare only compare the size and not the content?
Alain Verleyen
Moderator
28669
Alain Verleyen 2014.04.04 11:49  
Lines_ss:

Hello,

am not sure whether I understood the function ArrayCompare right or not. From my understanding I thought I could compare the content of 2 Array.

...

Thanks in advance!

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

qjol
3243
qjol 2014.04.04 11:54  
Lines_ss:


Does ArrayCompare only compare the size and not the content?


that's right
Lines_ss
57
Lines_ss 2014.04.04 11:57  
angevoyageur:
Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

Sorry, next time I will remember. It's my first time I used the forum.
Alain Verleyen
Moderator
28669
Alain Verleyen 2014.04.04 12:02  
Lines_ss:
Sorry, next time I will remember. It's my first time I used the forum.
Don't worry, this is why I explain that to you.
Lines_ss
57
Lines_ss 2014.04.04 12:04  
qjol:

that's right
@qjol: U are my hero ;-) Mql documentation was quite miss understanding for me.But now I understand the problems in my EA.
qjol
3243
qjol 2014.04.04 12:07  
If you want to compare arrays what they contain, use a for loop
Lines_ss
57
Lines_ss 2014.04.04 12:15  
qjol:
If you want to compare arrays what they contain, use a for loop
Thanks for ur help, that's the way I will now implement the compare function.
/
To add comments, please log in or register