a bug in arrayminimum?

 
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
 
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].
 
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. 

 
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.

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

 
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. 
 
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.
 
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...
 
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.
 
 
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.
Reason: