2 similar numbers from the list
I have 16 numbers, which are fields in my database (8 for high: h0, h1, h2, h3, h4, h5, h6, h7 and 8 for low: l0, l1, l2, l3, l4, l5, l6, l7) and they appear in every record. These numbers are previous swing highs and previous swing lows.
Another important field is price.
So what I need. In that list of 16 numbers - 1) find the nearest two (or more) similar numbers above the price and 2) find the nearest two (or more) similar numbers below the price.
By saying "similar", I say that they cannot be different by more than 0,5% (.005).
I count that difference between two numbers with such formula: If (Max (h0; h1) < Min (h0; h1) * 1,005; Max (h0; h1);
But trying to check all the possible combinations would take 28 If statements and that's not what I want.
so, let's say, for the above_price field: if the price is 130,21 and h3 = 130,55 and h4 = 130,58, it would return 130,58, which is greater of two similar number that are above the price.
and for below_price field: if price is same 130,21 and l2 = 129,12 and h5 = 129,61, it would return 129,61, which is greater of two similar number that are below the price.
So how do I calculate above_price and below_price numbers from 16 fields I mentioned previously plus the price?