void ChartControl_ContextMenuOpening(object sender, ContextMenuEventArgs e)
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Convert Context Menu Cursor to DateTime/Value
Collapse
X
-
Convert Context Menu Cursor to DateTime/Value
When handling
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?Code:Tags: None
-
Thanks, I am aware of those routines, but was not getting correct values when I use them.
For example, if I call
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.Code:ChartControl.GetTimeByX((int)e.CursorLeft)
It seems like the coordinate system needs to be shifted.
This is running on RC2.
Comment
-
Hello Aslane,
Thank you for your response.
You would need to use MouseDownPoint: http://ninjatrader.com/support/helpG...edownpoint.htm
Comment
-
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 FilesLast edited by aslane; 10-17-2016, 12:50 PM.
Comment
-
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
-
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:
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.Code:int cursorDateTime = ChartBars.GetBarIdxByX(ChartControl, X); DateTime customTime = ChartBars.GetTimeByBarIdx(ChartControl, cursorDateTime);
I look forward to being of further assistance.
Comment
-
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.Originally posted by NinjaTrader_Jesse View PostPotentially 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.
It is critical that functions like this work correctly with different DPIs, as high res monitors are quickly becoming the norm.
Comment
-
Aslane,Originally posted by aslane View PostNo, 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).
You can try something like:
ChartControl.GetTimeByX(e.CursorLeft.ConvertToHori zontalPixels(ChartControl.PresentationSource));
ThanksArtSenior Software Developer
Comment
-
The following
produces a time under the cursor (not a bar time 7:27:53 vs 7:30:00)Code:cursorDateTime = ChartControl.GetTimeByX(e.CursorLeft.ConvertToHorizontalPixels(ChartControl.PresentationSource));
The following
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.Code:int slotIndex = (int)Math.Round(ChartControl.GetSlotIndexByX(e.CursorLeft.ConvertToHorizontalPixels(ChartControl.PresentationSource)),0); cursorDateTime = ChartControl.GetTimeBySlotIndex(slotIndex);
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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
656 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
371 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment