Function To Find Closest Bar Number for Given DateTime

User avatar
dataheck
Posts: 30
Joined: Nov 19 2019
Location: Amherst, Nova Scotia
Been thanked: 5 times
Contact:

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.
Attachments
BarNumberForDateTime.pln
(1.44 KiB) Downloaded 330 times

Emmanuel
Posts: 355
Joined: May 21 2009
Has thanked: 109 times
Been thanked: 28 times

May 12 2020

Hoaw !! very interesting and helpful !!!!

This is a good idea !!!

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

Thank you Mat for this excellent function !!!!

rc76
Posts: 51
Joined: Oct 14 2020
Has thanked: 17 times

Dec 20 2022

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!