Try this:

dA=abs(Open - ArrayA);
dB=abs(Open - ArrayB);
dC=abs(Open - ArrayC);

Mindiff=Min(Min(dA,dB),dC);

NearestValue=iif(Mindiff == dA, ArrayA,  iif(Mindiff == dB,  ArrayB,  ArrayC));

When the differences are equal NearestValue will get set to the first Array 
that matches in the iif statement.

More complex logic would be required if you have preference for, for instance, 
the lower Array price when differences are equal
unless your BuyPrices are consistently ordered.  Then all you have to do is 
order the tests in the iif statement according to the
Array you want to give preference to.

Regards,

Bob

  ----- Original Message ----- 
  From: dralexchambers 
  To: [email protected] 
  Sent: Wednesday, April 04, 2007 11:33 AM
  Subject: [amibroker] Nearest price in an array


  I have a variety of prices in arrays:

  ArrayA = BuyPricesA
  ArrayB = BuyPricesB
  ArrayC = BuyPricesC

  How do I find which of these is closest to each bar's open price, eg:

  ArrayA[20] = 20.04
  ArrayB[20] = 19.55
  ArrayC[20] = 24.00

  Open[20] = 18.76

  Therefore, NearestValue[20] = Arrayb[20] = 19.55

  Many thanks,
  Alex



   

Reply via email to