But I was hoping that maybe someone in the community has come across a similar issue and maybe has some ideas.
Let me just setup the problem.
I have a custom NinjaScript indicator where I select a bar on a chart as input using the mouse. I do this by hooking the ChartControl.ChartPanel.MouseDown event. I then use the selection coordinates to figure out the DateTime (as the "x coorid") of the bar selected on the chart. This isn't that complicated and there are plenty of examples on how to do this throughout the forums.
Then I can save this DateTime value to an internal variable in my script and when OnBarUpdate is called, check to see if this value has been set which triggers other logic that happens on a tick by tick basis. So, this maybe a key point...this internal variable has a scope of the whole script, but its being set in a mouse event handler and then accessed in the OnBarUpdate method.
This works flawlessly pretty much 99.999% of the time (using intraday charts). I've recently found an edge case that seems to create problems for me. This edge case occurs when the bar I'm trying to select falls on a overlapping boundary between two sessions.
Suppose I have a session for an instrument defined as follows:
Sunday 5pm to Monday 9am
Monday 9am to Monday 5pm
Monday 5 pm to Tuesday 9am
Tuesday 9am to Tuesday 5pm
etc....
My problem occurs when the bar I want to select is the bar that ends at 9am. I am able to correctly select this bar and get the correct DateTime of this bar and set this to my internal variable; however, when I go to use that DateTime in a call to "GetBar(DateTime)" I don't get the data for the selected bar, I get the data for the next bar (say 9:25 am bar, if the chart interval is 5 min).
Anyone ever had an issue like this? If its hard to understand, I can create a mock indicator with the code of interest as an example.
Comment