View Full Version : GetBar() performance
aslane
10-31-2009, 08:10 AM
I wanted to use GetBar() in an indicator that I am working on, and was wondering if this is an efficient function (i.e. is is using a binary serach to find the bar) as I might be calling it frequently?
Ralph
10-31-2009, 09:57 AM
I do not use this method. Instead of searching for a timestamp in the past I prefer to store the desired value/values when they are processed in OnBarUpdate().
Regards
Ralph
NinjaTrader_Ben
10-31-2009, 10:14 AM
Hello,
I am sorry, you will need to test GetBar() and determine its efficiency. I do not know.
aslane
10-31-2009, 11:57 AM
I do not use this method. Instead of searching for a timestamp in the past I prefer to store the desired value/values when they are processed in OnBarUpdate().
Yes, I generally do this as well, but sometimes you don't know what you need until you know what you need.
aslane
10-31-2009, 12:54 PM
Ok, I ran a quick test over 40000 bars, comparing GetBar(), a simple binary search, and a simple linear search. Granted, my methods are a little rough, but thankfully the results show that GetBar is not a linear search. The results also showed that a simple binary search would be upto 6X faster depending what you are looking for (always looked at indexes that were worst case for bin search). That being said, I think the Ninja version is adequate, but I will write my own version to maximize perf.
Ralph
10-31-2009, 02:01 PM
...sometimes you don't know what you need until you know what you need.
That happens to me frequently.
And GetBar() requires an DataTime object as parameter. These instantiations are expensive operations.
Regards
Ralph