Function To Find Closest Bar Number for Given DateTime
Posted: May 09 2020
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.
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.