Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Convert Context Menu Cursor to DateTime/Value

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

    Convert Context Menu Cursor to DateTime/Value

    When handling
    Code:
    void ChartControl_ContextMenuOpening(object sender, ContextMenuEventArgs e)
    in an indicator, how would you convert the passed e.CursorTop and e.CursorLeft into the corresponding bar DateTime and Value that was clicked over?

    #2
    Hello,

    Thank you for the question.

    If you have an x or y position, there are some methods to convert to price or bar values.

    Here is one for Time by X value:


    Additional documentation:



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, I am aware of those routines, but was not getting correct values when I use them.

      For example, if I call
      Code:
      ChartControl.GetTimeByX((int)e.CursorLeft)
      I am getting back a DateTime that is a fair amount left of the actual click point. When I get a Y value using CursorTop, I get a value that is logically above the click point.

      It seems like the coordinate system needs to be shifted.

      This is running on RC2.

      Comment


        #4
        Hello Aslane,

        Thank you for your response.

        You would need to use MouseDownPoint: http://ninjatrader.com/support/helpG...edownpoint.htm

        Comment


          #5
          Well, the MouseDownPoint yields the same value as the event Cursor values (which is good). However, they return the wrong values.

          Attached is a simple indicator that shows the issue. The indicator adds a context menu item to the top of the context menu with the text showing the date and value that were clicked on. Use the crosshair, and you will see the values are clearly wrong.

          Running with RC2.

          Edit: I was able to get the correct price values by calling the GetValueByYWpf() routine instead of GetValueByY(). I do not see anything similar for the GetTimeByX() routine.

          Can you explain the difference between the Wpf and non-Wpf routine. The doc does not help in this regard. Thanks.
          Attached Files
          Last edited by aslane; 10-17-2016, 12:50 PM.

          Comment


            #6
            Any update on last post? GetTimeByX is still failing in example given.

            Comment


              #7
              Hello,

              I reviewed the sample but I do see the correct bar being listed in most cases, I had noted that depending on where in the bars slot you select it may select the current bar or the prior bar, is this what you are seeing as well?

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                No, I see cases where it is off by 10-12+ bars, not even close. After trying a few bars, it is fairly close when you are near the left side of the chart, but when you click on the right side it is really off.

                I am running on a 4K display, so this is likely some kind of DPI issue.

                Also, what is the difference between the Wpf and non-Wpf GetValueByY routines? One of those routines returns the correct value and the other does not (similar to the GetTimeByX routine being wrong).

                Comment


                  #9
                  Hello,

                  Potentially the dpi is to blame, are you using something other than the standard 100% setting? Also are you able to see the crosshair tool working accurately? If so this would tell me that the methods being used here are to blame for the result.

                  Regarding the difference in the methods, both are documented and have descriptions:




                  The major difference is that the WPF methods utilize WPF coordinates rather than Chart specific pixel coordinates.

                  For the time being, I am unsure there would be a correct way to access the Time of the bar due to the nature of the methods being used. There have been other questions posed around this subject and there has been changes with this in the current internal build. There will be an additional method GetBarIdxByX which will return a bars specific index similar to how the crosshair tool picks data. This could be used to get a bars specific index and from that a time as the id of the bar would be known. I believe for the use case, this would likely be the best approach.

                  In the current internal build I can see the following working regardless of where i select the bar:

                  Code:
                  int cursorDateTime = ChartBars.GetBarIdxByX(ChartControl, X);
                  DateTime customTime = ChartBars.GetTimeByBarIdx(ChartControl, cursorDateTime);
                  Unfortunately I am unsure when the release with this change would come out, on that note I will continue to track this topic until the release with this change exists to confirm this resolved the problem.


                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jesse View Post
                    Potentially the dpi is to blame, are you using something other than the standard 100% setting? Also are you able to see the crosshair tool working accurately? If so this would tell me that the methods being used here are to blame for the result.
                    Yes, I use a different DPI setting (125%). This is exactly what I was trying to get at. The coordinate system is not being properly mapped back to the user. When the coordinates are exposed back to the user, the X/Y should really be relative to the ChartControl or raw WPF pixels, and then the ninjaScript user can use the appropriate routine to get back to DateTime/Price. That is why the GetValueByYWpf works correctly.

                    It is critical that functions like this work correctly with different DPIs, as high res monitors are quickly becoming the norm.

                    Comment


                      #11
                      Originally posted by aslane View Post
                      No, I see cases where it is off by 10-12+ bars, not even close. After trying a few bars, it is fairly close when you are near the left side of the chart, but when you click on the right side it is really off.

                      I am running on a 4K display, so this is likely some kind of DPI issue.

                      Also, what is the difference between the Wpf and non-Wpf GetValueByY routines? One of those routines returns the correct value and the other does not (similar to the GetTimeByX routine being wrong).
                      Aslane,

                      You can try something like:

                      ChartControl.GetTimeByX(e.CursorLeft.ConvertToHori zontalPixels(ChartControl.PresentationSource));

                      Thanks
                      ArtSenior Software Developer

                      Comment


                        #12
                        The following
                        Code:
                                    cursorDateTime = ChartControl.GetTimeByX(e.CursorLeft.ConvertToHorizontalPixels(ChartControl.PresentationSource));
                        produces a time under the cursor (not a bar time 7:27:53 vs 7:30:00)

                        The following
                        Code:
                                    int slotIndex = (int)Math.Round(ChartControl.GetSlotIndexByX(e.CursorLeft.ConvertToHorizontalPixels(ChartControl.PresentationSource)),0);
                                    
                                    cursorDateTime = ChartControl.GetTimeBySlotIndex(slotIndex);
                        produces the bar time. Note that the slot index is a double, and has to be rounded back to an int in order to get the bar DateTime.

                        It would be nice if this detail was hidden from the NinjaScript user (i.e. GetBarDateTimeFromX), but its working!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by frankthearm, Yesterday, 09:08 AM
                        14 responses
                        47 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by gentlebenthebear, Today, 01:30 AM
                        2 responses
                        13 views
                        0 likes
                        Last Post gentlebenthebear  
                        Started by Kaledus, Today, 01:29 PM
                        2 responses
                        8 views
                        0 likes
                        Last Post Kaledus
                        by Kaledus
                         
                        Started by PaulMohn, Today, 12:36 PM
                        2 responses
                        16 views
                        0 likes
                        Last Post PaulMohn  
                        Started by Conceptzx, 10-11-2022, 06:38 AM
                        2 responses
                        56 views
                        0 likes
                        Last Post PhillT
                        by PhillT
                         
                        Working...
                        X