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 ETFVoyageur, Today, 07:55 PM
|
0 responses
6 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:55 PM
|
||
Started by janio973, Today, 07:24 PM
|
1 response
7 views
0 likes
|
Last Post Today, 07:35 PM | ||
Started by aligator, 01-06-2022, 12:14 PM
|
4 responses
242 views
0 likes
|
Last Post
by john_44573
Today, 06:11 PM
|
||
Started by reynoldsn, Today, 05:56 PM
|
0 responses
13 views
0 likes
|
Last Post
by reynoldsn
Today, 05:56 PM
|
||
Started by bortz, 11-06-2023, 08:04 AM
|
51 responses
1,996 views
0 likes
|
Last Post
by aligator
Today, 05:50 PM
|
Comment