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!
See more
See less

Partner 728x90

Collapse

How to get price data on chart at cursor

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

    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.

    #2
    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

    Comment


      #3
      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


        #4
        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
           }
        
        }
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          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


            #6
            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 Files
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GLFX005, Today, 03:23 AM
            0 responses
            1 view
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            11 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            6 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            14 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            3 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Working...
            X