minValueIdx=ArrayMaximum(b_oprice,WHOLE_ARRAY,0); Print("Max value = ",b_oprice[maxValueIdx]," at index=",maxValueIdx);you don't assign a value other than 0 to maxValueIdx
you don't assign a value other than 0 to maxValueIdx
Ooops ! The value was incorrct.
Thanks GumRai !
Ooops ! The value was incorrct.
Thanks GumRai !
I correct the code as GumRai told.
But, the result is not as expected. It varies by ArrayInitializd(array, EMPTY_VALUE / 0)
int start()
when use EMPTY_VALUE
ArrayInitialize(b_oprice,EMPTY_VALUE);
ArrayInitialize(s_oprice,EMPTY_VALUE);
2016.02.09 12:34:35.480 Expert Array GBPJPY,M1: removed
2016.02.09 12:34:35.477 Array GBPJPY,M1: uninit reason 0
2016.02.09 12:34:35.477 Array GBPJPY,M1: ExpertRemove function called
2016.02.09 12:34:35.477 Array GBPJPY,M1: Min value = 121.1 at index=1
2016.02.09 12:34:35.477 Array GBPJPY,M1: s_oprice = [2], 121.300
2016.02.09 12:34:35.477 Array GBPJPY,M1: s_oprice = [1], 121.100
2016.02.09 12:34:35.477 Array GBPJPY,M1: s_oprice = [0], 121.200
2016.02.09 12:34:35.477 Array GBPJPY,M1: Max value = 2147483647.0 at index=3
2016.02.09 12:34:35.477 Array GBPJPY,M1: b_oprice = [2], 111.200
2016.02.09 12:34:35.477 Array GBPJPY,M1: b_oprice = [1], 111.300
2016.02.09 12:34:35.477 Array GBPJPY,M1: b_oprice = [0], 111.100
2016.02.09 12:34:35.341 Array GBPJPY,M1: initialized
2016.02.09 12:34:34.319 Expert Array GBPJPY,M1: loaded successfully
When use 0 value.
ArrayInitialize(b_oprice,0);
ArrayInitialize(s_oprice,0);
2016.02.09 12:36:18.990 Array GBPJPY,M1: Min value = 0.0 at index=3
2016.02.09 12:36:18.990 Array GBPJPY,M1: s_oprice = [2], 121.300
2016.02.09 12:36:18.990 Array GBPJPY,M1: s_oprice = [1], 121.100
2016.02.09 12:36:18.990 Array GBPJPY,M1: s_oprice = [0], 121.200
2016.02.09 12:36:18.990 Array GBPJPY,M1: Max value = 111.3 at index=1
2016.02.09 12:36:18.990 Array GBPJPY,M1: b_oprice = [2], 111.200
2016.02.09 12:36:18.990 Array GBPJPY,M1: b_oprice = [1], 111.300
2016.02.09 12:36:18.990 Array GBPJPY,M1: b_oprice = [0], 111.100
2016.02.09 12:36:18.083 Array GBPJPY,M1: initialized
2016.02.09 12:36:16.329 Expert Array GBPJPY,M1: loaded successfully
It does as I expect
EMPTY_VALUE is 2147483647.0 , so is larger than any of the 3 numbers
0 is smaller than any of the 3 numbers
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- GumRai is correct. The smallest of {121.200, 121.100, 121.300, 0, 0, ...} is zero. The smallest of {121.200, 121.100, 121.300, 2147483647, 2147483647, ...} is 121.100. Why would you expect anything else?
It does as I expect
EMPTY_VALUE is 2147483647.0 , so is larger than any of the 3 numbers
0 is smaller than any of the 3 numbers
Dear GumRai,
I found the resolution.
Inspite of using WHOLE_ARRAY
minIdx=ArrayMinimum(s_oprice,WHOLE_ARRAY,0);
use real array size
minIdx=ArrayMinimum(s_oprice,sellcnt,0);
Then, it returned real max and min value as below.
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: Min value = 121.1 at index=1
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: s_oprice = [2], 121.300
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: s_oprice = [1], 121.100
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: s_oprice = [0], 121.200
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: Max value = 111.3 at index=1
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: b_oprice = [2], 111.200
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: b_oprice = [1], 111.300
2016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: b_oprice = [0], 111.100
GumRai, Thank your reponse.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I wish to get Max and Min value in arrays.
But I failed to get maximum value using ArrayMaximum using below source code.
Does anybody help me?
int start()
{
double b_oprice[3], s_oprice[3], Bprofit=0, Sprofit=0;
int Bcount=0, Scount=0;
int Distance = 10;
ArrayInitialize(b_oprice,0);
ArrayInitialize(s_oprice,0);
int minValueIdx = 0, maxValueIdx = 0;
b_oprice[0] = 111.1; // minimum
b_oprice[1] = 111.3;
b_oprice[2] = 111.2;
s_oprice[0] = 121.2;
s_oprice[1] = 121.1;
s_oprice[2] = 121.3; // maximum
for(int i=0; i<3; i++)
{
printf("b_oprice = [%d], %.3f", i, b_oprice[i]);
}
minValueIdx=ArrayMaximum(b_oprice,WHOLE_ARRAY,0);
Print("Max value = ",b_oprice[maxValueIdx]," at index=",maxValueIdx);
for(int i=0;i<3; i++)
{
printf("s_oprice = [%d], %.3f", i, s_oprice[i]);
}
minValueIdx=ArrayMinimum(s_oprice,WHOLE_ARRAY,0);
Print("Min value = ",s_oprice[minValueIdx]," at index=",minValueIdx);
return(0);
}
Experts results are as below.
Max value = 111.1 at index=0
b_oprice = [2], 111.200
b_oprice = [1], 111.300
b_oprice = [0], 111.100 <---- wrong
Min value = 121.1 at index=1
s_oprice = [2], 121.300
s_oprice = [1], 121.100 <---- correct
s_oprice = [0], 121.200