Find Max value

 

Hello,

I have a number of variables like:

int v1=1;

int v2=0;

 

...

int v40=65;


I want to find the 1st, and 2nd minimum value of these variables.

The ArrayMinimum[40]={v1...v40} return error of "constant expression required"

 

Can you help me to solve this problem?

Thank you,

SCFX 

 

Why not assign the values directly to an array?.

int v_array[40];
v_array[0]=1;
v_array[1]=0;
//

v_array[39]=65;
 
GumRai:

Why not assign the values directly to an array?.

Thanks GumRai,

So here what I do, following your suggestion. It works. I just wonder if it is the good way to get the job done?

SCFX 

double end_array[8]; 


end_array[0]=end1; end_array[1]=end2; end_array[2]= end3; end_array[3]= end4; end_array[4]= end5; end_array[5]= end6; end_array[6]= end7; end_array[7]= end8; 

 

int    min1_end_array=ArrayMaximum(end_array,WHOLE_ARRAY,1);

buy1[i]=end_array[min1_end_array]; 
 

The reason I do not assign is that the value change from bar to bar.

Somehow the code above run without error but return no value.

Is there anything wrong in that one?

Thanks,

Scfx 

 
end1=123;
end_array[0]=end1;

Your code should work, but why use the intermediary variables end1 etc, why not assign the value directlly to the array? Do you need to use the values elsewhere later?

//end1=123;
end_array[0]=123;


int    min1_end_array=ArrayMaximum(end_array,WHOLE_ARRAY,1);

Why search in the array without element 0?

min1_end_array suggests that you are looking for a minimum, but you are searching for the maximum.

If you are not going to use the values in the array for anything else, you could simply use ArraySort.

Then array[0] will be the minimum, [1] the 2nd lowest,  [2] the 3rd etc

With MODE_DESCEND, the [0] will be the maximum.

Reason: