Page 1 of 1

Function To Find Closest Bar Number for Given DateTime

Posted: May 09 2020
by dataheck
I need to be able to make some historical queries for some of my other projects, and so I need to access a bar somewhere deep in my data series. Unfortunately MultiCharts .NET does not have a built-in feature for this, so I built a function that does this using a binary search.

It's pretty quick (well, since it uses binary search its O(log(N))), and it avoids recalculating if it already found the answer for a given target date.

e: 2020-05-10 modified to take into consideration MaxBarsBack, it's up to you to ensure the function will have enough data to find the answer. It should throw an exception if it doesn't have enough.

Re: Function To Find Closest Bar Number for Given DateTime

Posted: May 12 2020
by Emmanuel
Hoaw !! very interesting and helpful !!!!

This is a good idea !!!

I was looking for this function !!!!!!

Thank you Mat for this excellent function !!!!

Re: Function To Find Closest Bar Number for Given DateTime

Posted: Dec 20 2022
by rc76
Will there be any chance to create a version for regular MC as well?

This function will be super useful!

Thank you sir in advance!