English

## ArrayMaximum() has generic error ?

 4 hopedslee123 2016.02.08 04:33   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=0b_oprice = [2], 111.200b_oprice = [1], 111.300b_oprice = [0], 111.100 <---- wrongMin value = 121.1 at index=1s_oprice = [2], 121.300s_oprice = [1], 121.100 <---- corrects_oprice = [0], 121.200
 Moderator3404 GumRai 2016.02.08 06:38 #   ```         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
 4 hopedslee123 2016.02.08 09:01 #   GumRai: you don't assign a value other than 0 to maxValueIdxOoops ! The value was incorrct. Thanks GumRai !
 4 hopedslee123 2016.02.09 04:44 #   hopedslee123: 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(){    double b_oprice[100], s_oprice[100];        ArrayInitialize(b_oprice,0);        ArrayInitialize(s_oprice,0);          int minIdx = 0, MaxIdx = 0, buycnt=0, sellcnt=0;           b_oprice[0] = 111.1;     b_oprice[1] = 111.3; //maximum    b_oprice[2] = 111.2;            s_oprice[0] = 121.2;    s_oprice[1] = 121.1; // miniimum    s_oprice[2] = 121.3;        buycnt=3; sellcnt=3;        for(int i=0; i
 Moderator3404 GumRai 2016.02.09 07:48 #   It does as I expectEMPTY_VALUE is 2147483647.0 , so is larger than any of the 3 numbers0 is smaller than any of the 3 numbers
12985
WHRoeder 2016.02.09 15:02 #

1.  Play video Please edit your post. For large amounts of code, attach it.

2. 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?
 4 hopedslee123 2016.02.10 05:17 #   GumRai: It does as I expectEMPTY_VALUE is 2147483647.0 , so is larger than any of the 3 numbers0 is smaller than any of the 3 numbers Dear GumRai,I found the resolution.Inspite of using WHOLE_ARRAYMaxIdx=ArrayMaximum(b_oprice,WHOLE_ARRAY,0);minIdx=ArrayMinimum(s_oprice,WHOLE_ARRAY,0);use real array size  MaxIdx=ArrayMaximum(b_oprice,buycnt,0);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=12016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: s_oprice = [2], 121.3002016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: s_oprice = [1], 121.1002016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: s_oprice = [0], 121.2002016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: Max value = 111.3 at index=12016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: b_oprice = [2], 111.2002016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: b_oprice = [1], 111.3002016.02.10 13:15:30.193 FunctionTest GBPJPY,M1: b_oprice = [0], 111.100GumRai, Thank your reponse.