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
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
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
-
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
-
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:
Code:int cursorDateTime = ChartBars.GetBarIdxByX(ChartControl, X); DateTime customTime = ChartBars.GetTimeByBarIdx(ChartControl, cursorDateTime);
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
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
-
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
Code:cursorDateTime = ChartControl.GetTimeByX(e.CursorLeft.ConvertToHorizontalPixels(ChartControl.PresentationSource));
The following
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 cmtjoancolmenero, Today, 02:31 PM
|
4 responses
8 views
0 likes
|
Last Post Today, 03:13 PM | ||
Started by mintos, 04-02-2024, 08:22 PM
|
2 responses
17 views
0 likes
|
Last Post
by mintos
Today, 03:11 PM
|
||
Started by Taddypole, Today, 02:25 PM
|
1 response
5 views
0 likes
|
Last Post Today, 02:58 PM | ||
Started by Graci117, Yesterday, 11:40 PM
|
3 responses
20 views
0 likes
|
Last Post Today, 02:58 PM | ||
Started by tradebot, Today, 01:25 PM
|
2 responses
11 views
0 likes
|
Last Post
by tradebot
Today, 02:36 PM
|
Comment