[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Nearest price in an array



PureBytes Links

Trading Reference Links

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 -----
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

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___