Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Handling MouseDown Event and Session Boundaries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Handling MouseDown Event and Session Boundaries

    Let me preface my question with this caveat. I realize that handling mouse events on your own in custom Ninjascript indicators is unsupported.

    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.

    #2
    Actually, one clarification. The first time I try to call "GetBar(DateTime)", I'm still with in the mouse event handler and not within the OnBarUpdate method.

    Comment


      #3
      Originally posted by ATX_tdr View Post

      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.
      Any chance you would share the basic code of how to use the mouse to select a bar and use that bar number or DateTime value as input? Would be greatly appreciated.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by gravdigaz6, Today, 11:40 PM
      0 responses
      4 views
      0 likes
      Last Post gravdigaz6  
      Started by MarianApalaghiei, Today, 10:49 PM
      3 responses
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by XXtrader, Today, 11:30 PM
      0 responses
      4 views
      0 likes
      Last Post XXtrader  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      9 views
      0 likes
      Last Post funk10101  
      Working...
      X