Array Search function for Horizontal lines?

 

Hey everyone....

 I have an indicator that draws specially calculated lines 1000pips up and 1000 pips down from the current price.

It calculates from a base 1.1000 on the EUR/USD. 

The absolute fibonacci framework its called. (google it)

 

Id like to know if theres an array search function of sorts that can help with finding the three array indexes closes to price, in an array of probably 1000 values.

Id like to have the start of everyday find the 3 lines above price, and the 3 lines below price.

Anyideas how I can do this??

 
There's no such function by default. Its something you'll want to create.
 
ubzen:
There's no such function by default. Its something you'll want to create.


So what should I do.

 Right now I have the array, and I have all the values, Im just having trouble searching the array for the current price, and returning the closest values.

When I found the ArrayBSearch function I was all excited because it said it would find the closes matching search value.

Which was perfect for what I needed.....But alas.....its not working.

the getcloseline int is just returning 0 index.....no matter what I put in the search variable; 

 

double newarray[] = {1.2000, 1.2104, 1.2234, 1.2459 etc etc}

double search=Ask; // Or any other double, Ive tried search for the values in the array example 
           above, and still returns 0 even though I can clearly see that they are in the array with my eyes. 

int getcloseline = ArrayBSearch(newarray, search, WHOLE_ARRAY,0,MODE_DESCENDS);

  

Anybody know what the deal is?

Can we even search for doubles in an array? 

WHY IS THIS NOT WORKING!!?? lol 

 
holoverse:


Anybody know what the deal is?

Can we even search for doubles in an array? 

WHY IS THIS NOT WORKING!!?? lol 

Maybe it is working,  if your Ask value were 1.2 or lower 0 would be the correct value.

Post your test script/Indicator/EA

By the way, this line is wrong  . . .

int getcloseline = ArrayB  S   earch(newarray, search, WHOLE_ARRAY,0,MODE_DESCENDS);
 
holoverse: WHY IS THIS NOT WORKING!!?? lol
  1. Did you sort the list before calling bsearch as required?
  2. double newarray[] = {1.2000, 1.2104, 1.2234, 1.2459} <- Ascending values
    ArrayBSearch(newarray, search, WHOLE_ARRAY,0,MODE_DESCENDS);
    Does your DESCENDS match the order in the array?
 
WHRoeder:
  1. Did you sort the list before calling bsearch as required?
  2. Does your DESCENDS match the order in the array?

I didn't sort the array....because the values being put in, sequentially.

Do I still need to sort, even though they are technically in perfectly ascending order???

Also, the reason I had MODE_DESCENDS was cause all the values closer to the price are near the 'top' of the array, so I wanted to search top down.

am I assuming the wrong thing for the MODE_DESCENDS call?

 
  1. how they are put in is irrelevant. There is no other way to fill an array but sequentially.
  2. Did your bother to read the documentation in the link I posted? What part of "Binary search processes only sorted arrays," was not understandable?
  3. "I wanted to search top down." bsearch doesn't search top down or down up. It does a Binary search.
  4. Ascending values and MODE_DESCEND is mutually exclusive.
Reason: