• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to convert mouse point to chart point

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

    How to convert mouse point to chart point

    What is the procedure for converting the mouse location to a proper chart location? I want to be able to tell when the mouse is over a drawing object in the chart.

    I have tried the following:

    Code:
    ChartControl.MouseMove += ChartMouseMove;
    
    private void ChartMouseMove(object s, MouseEventArgs e)
    {
        var pos = e.GetPosition(ChartControl);
        // or var pos = e.GetPosition(ChartControl.OwnerChart);
    }
    The resulting point is not corresponding with drawing objects on the chart.

    Thanks.

    #2
    Hello wbennettjr,

    You can convert a price to a y value and time/barSlot to x and vice versa.

    Below is a link to an example.
    http://ninjatrader.com/support/forum...684#post499684

    http://ninjatrader.com/support/helpG...ntalpixels.htm
    http://ninjatrader.com/support/helpG...calpixels2.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea,

      Based on the links you provided, I changed the code to

      Code:
      ChartControl.MouseMove += ChartMouseMove;
      
      private void ChartMouseMove(object s, MouseEventArgs e)
      {
          var pos = e.GetPosition(ChartControl);
          pos.X = ChartingExtensions.ConvertToHorizontalPixels(pos.X, 
      ChartControl.PresentationSource);
          pos.Y = ChartingExtensions.ConvertToVerticalPixels(pos.Y, ChartControl.PresentationSource);
      }
      Works like a charm!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by dariuszszyc, Today, 09:08 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_JoshG  
      Started by Sadat, Today, 09:09 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_JoshG  
      Started by login_dejavu, Today, 07:57 AM
      4 responses
      19 views
      0 likes
      Last Post login_dejavu  
      Started by Lender, Yesterday, 05:15 PM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by rcmcd, Today, 07:52 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Working...
      X