Fastest way to search back with only date and time.

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
bowlesj3
Posts: 2108
Joined: 21 Jul 2007
Has thanked: 201 times
Been thanked: 420 times

Fastest way to search back with only date and time.

Postby bowlesj3 » 05 Jul 2008

Hi,

See most recent version of binary search at
viewtopic.php?f=5&t=7749
It has one for seconds bars and minute bars as well as test scripts. It properly handles maxbarsback. This thread may be of some value but I have removed the zip file so people only use the zip file from the above thread.

ORIGINAL POST BEGINS HERE:
I have some EL code in a study that is executed only in the last bar in the chart which gets a date and time from somewhere (GV, arrow placement on the chart, whatever). This date and time is not the current bars date and time but rather a historic bar. The study needs to use this date and time to get the high and low of that historic bar. I am looking for the fastest way to get this to execute. I have scanned all the functions in the reference and unless I missed it, there appears to be no function for this. Is there an existing function for this? I searched the forum and nothing is found.

To save reading, I did write the binary search and it works. It is limited to a certain number of bars back. You can play with it if you want.

Thanks,
John.
Last edited by bowlesj3 on 04 Sep 2010, edited 7 times in total.

fs

Postby fs » 05 Jul 2008

I don't really understand what you mean when you say: "I have some EL code in a study that is executed only in the last bar in the chart which gets the date and time and needs to go back and get the high and low of a previous bar that has this date and time.

How can a previous bar has the same date and time than the last bar on the chart?

Either way, binary search is only useful when the list of data is sorted. If you try to find a value in an unsorted list, you will need to look at each value.

bowlesj3
Posts: 2108
Joined: 21 Jul 2007
Has thanked: 201 times
Been thanked: 420 times

Here is the code.

Postby bowlesj3 » 05 Jul 2008

See most recent version of binary search at
viewtopic.php?f=5&t=7749
It has one for seconds bars and minute bars as well as test scripts.
Last edited by bowlesj3 on 07 Jul 2008, edited 5 times in total.


Return to “User Contributed Studies and Indicator Library”