hknight:
Did you mean remove ? or did you mean replace ? what you are doing is replacing. When you replace the minimum value with 0 it is still likely to be the minimum. Instead replace the two minimums with x[ArrayMaximum(x)] + 1 and then replace the 4 maximums. If you mean remove then that is a more complex task.
How can I remove the two lowest and the two highest values from an array? The problem with the code below is that 0 gets removed twice instead of the real second lowest value.
Clever, thanks for the idea. This does what I need:
x[ArrayMinimum(x)] = 999999; x[ArrayMinimum(x)] = 999999; x[ArrayMaximum(x)] = 0; x[ArrayMaximum(x)] = 0; x[ArrayMaximum(x)] = 0; x[ArrayMaximum(x)] = 0;
hknight:
How can I remove the two lowest and the two highest values from an array? The problem with the code below is that 0 gets removed twice instead of the real second lowest value.
What about something like this:
double x[15] = {9, 100, 9, 200, 9, 9, 9, 9, 9, 9, 1, 9, 2, 9, 9}; ArraySort(x); ArrayResize(x, ArraySize(x) - 2); ArraySort(x, WHOLE_ARRAY, 0, MODE_DESCEND); ArrayResize(x, ArraySize(x) - 2); // check to see if the result is correct for (int i = 0; i <= ArraySize(x) - 1; i++) { Print ("i: ", i, " and v: ", x[i]); }
Or, you can try using a combination of ArraySort() and ArrayCopy():
double x[15] = {9, 100, 9, 200, 9, 9, 9, 9, 9, 9, 1, 9, 2, 9, 9}; double y[]; ArraySort(x); ArrayCopy(y, x, 0, 2, ArraySize(x) - 4); // verify correct results for (int i = 0; i <= ArraySize(y) - 1; i++) Print ("i: ", i, " and v: ", y[i]);
Thirteen, thanks for your ideas. That does seem like the proper way to do this.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How can I remove the two lowest and the two highest values from an array? The problem with the code below is that 0 gets removed twice instead of the real second lowest value.