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

ChartControl.MouseDown Returns Incorrect Coordinates

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

    ChartControl.MouseDown Returns Incorrect Coordinates

    The attached file demonstrates an issue with the coordinates returned by ChartControl.MouseDown when clicking in the Time Axis.

    Steps to reproduce.

    1) Add a new chart.
    1) Load the attached indicator on the chart.
    2) Click somewhere in the middle of the Time Axis. The coordinates MouseDown returns are not correct. (e.g. Mouse Down Point:0,0)
    3) Click somewhere on the Chart area with the Chart Bars. MouseDown returns the correct coordinates. (e.g. Mouse Down Point:510,650)
    4) Click on the same location in the Time Axis again. MouseDown returns the same coordinates as in step 3. (e.g. Mouse Down Point:510,650)

    It appears clicking on the Time Axis does not change the MouseDown coordinates, and the prior coordinates are returned instead, or Point 0,0 if this is the first MouseDown event.

    Thanks,
    Greg
    Attached Files
    The Trading Mantis
    NinjaTrader Ecosystem Vendor - The Trading Mantis

    #2
    Hello TheTradingMantis,

    Mouse coordinates are not directly usable in NinjaScript, you need to convert them before they can be used. You can see an example in the following link:



    In your sample you are also not using the event mouse position so that may also be contributing to the issue. The property you are using would need to be used from OnRender.

    There is a sample which gets the mouse position and does the correct conversion in the following post: https://ninjatrader.com/support/foru...868#post820868
    JesseNinjaTrader Customer Service

    Comment


      #3
      In the test script I originally attached, I did not use ChartingExtensions.ConvertToHorizontalPixels or ChartingExtensions.ConvertToVerticalPixels, as the values returned by the ChartingExtensions were the same as the MouseDownPoint (at least on my dev computer). The revised test script I have attached includes printouts for both.

      If I understand you correctly, MouseDownPoint only works in OnRender? Yet it seems to work just fine in my custom MouseDown event, except when clicking in the Time Axis. I'm guessing the DrawingTool.OnMouseDown event is not triggered when clicking in the Time Axis, so the MouseDownPoint is not updated.

      In my application I am identifying when someone clicks in the Price Scale. The event args GetPosition method does return a Point wherever I click on the chart (including the Time Axis). The coordinates returned appear to include the chart frame. I am uncertain how to calculate where the Price Scale begins since ChartControl.CanvasRight excludes the chart frame width and so I cannot use it with the GetPosition coordinates. Do you have any suggestions on how I might determine the X coordinate of the Price Scale using the event args GetPosition?
      Attached Files
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment


        #4
        Hi Jesse,

        You can disregard the questions in my last post. Chelsea's script in the post you referenced helped me figure out how to convert the mouse event args GetPosition to the ChartControl coordinates I needed.

        Appreciate the support!
        The Trading Mantis
        NinjaTrader Ecosystem Vendor - The Trading Mantis

        Comment


          #5
          Hello TheTradingMantis,

          The sample that I linked shows the correct way of getting the mouse position and converting the x/y values using WPF events. It uses OnMouseMove but you can also use that code in OnMouseDown. The properties you are using in your original sample would have been for use in OnRender and the MouseDownPoint property. OnRender is called very frequently and that property is the last known position. https://ninjatrader.com/support/help...MouseDownPoint

          Keep in mind you can't do anything within the scales areas so if you are using a position that is outside the general chart area that will be invalid X/Y points. You would only be able to use X/Y from inside the chart panel area minus the Time axis scale and minus the Price axis scale. The W and H bounds you have access to already exclude those areas. https://ninjatrader.com/support/help...chartpanel.htm

          For example to get the width of the chart would be ChartPanel.X + ChartPanel.W and the height would be ChartPanel.Y + ChartPanel.H

          If you can provide more specific details on what you are trying to do with the XY coordinates that may help to provide better guidance here.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NM_eFe, Today, 10:13 AM
          0 responses
          4 views
          0 likes
          Last Post NM_eFe
          by NM_eFe
           
          Started by hdge4u, Yesterday, 12:23 PM
          1 response
          10 views
          0 likes
          Last Post hdge4u
          by hdge4u
           
          Started by 1001111, Today, 09:45 AM
          0 responses
          12 views
          0 likes
          Last Post 1001111
          by 1001111
           
          Started by DTSSTS, 01-28-2024, 12:07 PM
          11 responses
          560 views
          0 likes
          Last Post bmo111
          by bmo111
           
          Started by Torontobluejays, Today, 08:43 AM
          0 responses
          3 views
          0 likes
          Last Post Torontobluejays  
          Working...
          X