Thanks.
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!
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
NinjaTrader
How to get price data on chart at cursor
Collapse
X
-
How to get price data on chart at cursor
I want to click at a certain point on the chart then get the price at that location so that I can use the data for some calculation. I imagine that would involve getting the location at mouse click and somehow get the mapping from point to price but I don't know how to do that.
Thanks.Tags: None
-
Hello emilien,
As a starting point I was able to locate the following post which could aid in getting the mouse X and Y values along with getting the mouse click:
To convert these values into prices or bar times, you could see the following methods:
One way to see this in action would be using the sample from the above post, you could use the following Print to test this:
Code:protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { if (clickSet) { [B]Print(chartScale.GetValueByY((float)clickPoint.Y));[/B] SharpDX.Vector2 ellipseVector = clickPoint.ToVector2(); newEllipses.Add(new SharpDX.Direct2D1.Ellipse(ellipseVector, 10f, 10f)); clickSet = false; }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
Ok, I got the conversion from X,Y values to price.
How do I access ChartControl from a strategy ? I see a sample code for Strategy that collects MouseDownPoint of the chart control inside an OnRender method. I want to take that MouseDownPoint value but not inside an OnRender, just in a method where I write the calculation logic for the strategy.
Comment
-
Hello emilien,
You should be able to access the ChartControl from a strategy basically in any method, you may need to check that it is not null though because Strategies do not always have a chart.
Code:protected override void OnBarUpdate() { if(ChartControl != null) { //do something with the ChartContol } }
JesseNinjaTrader Customer Service
Comment
-
I'm stuck at 2 points while writing code in a Strategy:
- How do I get to use GetValueByY method outside of OnRender() ? I can't do that with ChartScale.
- Is there a way to catch mouse events on ChartControl inside a Strategy ? For example, the strategy waits for user to choose a price level on the chart. After that happens it will do something.
Thanks.
Comment
-
Hello emilien and thank you for your questions.
To your first question, you will need to memoize this value during OnRender. Please follow the provided example.
To your second question, while you have correctly noted that Ninja's directly supported mouse event notifications do happen during OnRender, you can set up a background event handler which monitors this value here,
Please let us know if there are any other ways we can help.Attached FilesJessica P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Tim-c, Today, 02:10 PM
|
1 response
7 views
0 likes
|
Last Post Today, 02:52 PM | ||
Started by Taddypole, Today, 02:47 PM
|
0 responses
2 views
0 likes
|
Last Post
by Taddypole
Today, 02:47 PM
|
||
Started by chbruno, 04-24-2024, 04:10 PM
|
4 responses
50 views
0 likes
|
Last Post
by chbruno
Today, 02:38 PM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
10 responses
400 views
1 like
|
Last Post
by beobast
Today, 02:35 PM
|
||
Started by lorem, Yesterday, 09:18 AM
|
5 responses
25 views
0 likes
|
Last Post Today, 12:29 PM |
Comment