Download MetaTrader 5

a bug in arrayminimum?

To add comments, please log in or register
Dua Yong Rew
5436
Dua Yong Rew 2013.09.11 17:43 
void OnTick()
  {
//---

   double   Bar_Close[];

   ArraySetAsSeries(Bar_Close, true);

   if(CopyClose(Symbol(), 0, 0, 3, Bar_Close) <= 0) return;

   int Shift = ArrayMinimum(Bar_Close, 2, 3);

   Print(Bar_Close[Shift]);

//---
  }

is there a bug here in the arrayminimum?

i copy 3 slots only but when i call arrayminimum with start pos at 2 for 3 count it can still return something... 

Documentation on MQL5: Array Functions / ArrayMinimum
Documentation on MQL5: Array Functions / ArrayMinimum
  • www.mql5.com
Array Functions / ArrayMinimum - Documentation on MQL5
Alain Verleyen
Moderator
31090
Alain Verleyen 2013.09.11 18:14  
doshur:

is there a bug here in the arrayminimum?

i copy 3 slots only but when i call arrayminimum with start pos at 2 for 3 count it can still return something... 

And where is the bug ? You have 3 elements with index 0, 1, 2. ArrayMinimum takes only the index 2 into account and always return Bar_Close[2].
Dua Yong Rew
5436
Dua Yong Rew 2013.09.12 04:05  
angevoyageur:
And where is the bug ? You have 3 elements with index 0, 1, 2. ArrayMinimum takes only the index 2 into account and always return Bar_Close[2].

start pos is 2 meaning index 1 right?

I was thinking it will read to index 3 but there is no error generated. 

Alain Verleyen
Moderator
31090
Alain Verleyen 2013.09.12 10:11  
doshur:

start pos is 2 meaning index 1 right?

Not right.

I was thinking it will read to index 3 but there is no error generated. 

Your Bar_Close has 3 values Bar_Close[0] which is current candle close as you are using ArraySetAsSeries (true). Bar_Close[1] and Bar_Close[2].

You search the minimum starting with 2, and count 3. So it search within Bar_Close[2], Bar_Close[3], Bar_Close[4], but indices 3 and 4 doesn't exist so you always get Bar_Close[2] as result. There is no error, no bug.

Dua Yong Rew
5436
Dua Yong Rew 2013.09.12 10:38  
angevoyageur:
Not right.

Your Bar_Close has 3 values Bar_Close[0] which is current candle close as you are using ArraySetAsSeries (true). Bar_Close[1] and Bar_Close[2].

You search the minimum starting with 2, and count 3. So it search within Bar_Close[2], Bar_Close[3], Bar_Close[4], but indices 3 and 4 doesn't exist so you always get Bar_Close[2] as result. There is no error, no bug.

Understand. Thanks.

but why is there still a return from the arrayminimum if I use this

int Shift = ArrayMinimum(Bar_Close, 5, 3); 

Simon Gniadkowski
Moderator
18002
Simon Gniadkowski 2013.09.12 10:46  
doshur:

Understand. Thanks.

but why is there still a return from the arrayminimum if I use this

Print() Bar_Close[0], Bar_Close[1], Bar_Close[2], Bar_Close[3], Bar_Close[4], Bar_Close[5], Bar_Close[6], Bar_Close[7]  and find out what is going on. 
Alain Verleyen
Moderator
31090
Alain Verleyen 2013.09.12 10:51  
RaptorUK:
Print() Bar_Close[0], Bar_Close[1], Bar_Close[2], Bar_Close[3], Bar_Close[4], Bar_Close[5], Bar_Close[6], Bar_Close[7]  and find out what is going on. 
He can't print Bar_Close[3] and superior, they don't exist and he will receive an "array out of range" error.
Alain Verleyen
Moderator
31090
Alain Verleyen 2013.09.12 10:52  
doshur:

Understand. Thanks.

but why is there still a return from the arrayminimum if I use this

LOL, you are searching a bug ? I check...
Maxim Khrolenko
7233
Maxim Khrolenko 2013.09.12 10:54  
void OnTick()
  {
//---
   double   Bar_Close[];

   if(CopyClose(_Symbol, 0, 0, 3, Bar_Close) <= 0) return;
   ArraySetAsSeries(Bar_Close, true);

   int Shift = ArrayMinimum(Bar_Close, 0, 2);

   Print("Minimal close price = ",Bar_Close[Shift]," for ",Shift," bar");
//---
  }
You copy 3 elements starting from element with index 0 (zero), so 1st element have index 0 in array Bar_Close, 2nd element = index 1, and finally 3rd = index 2.
Maxim Khrolenko
7233
Maxim Khrolenko 2013.09.12 10:57  
Dua Yong Rew
5436
Dua Yong Rew 2013.09.12 11:54  
angevoyageur:
LOL, you are searching a bug ? I check...
I discovered this when I'm trying something out. At least it should give me some warnings but there isn't.
12
To add comments, please log in or register