• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Point type to Bars/Price converter?

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

    Point type to Bars/Price converter?

    Probably asked before but can´t find it:

    Is there a NinjaScript method or other easy solution for converting the .NET Point type to X/Y (Bars/Price) coordinates and vice versa?
    Last edited by FREEN; 10-19-2015, 02:14 PM.

    #2
    Hello,

    Thank you for the question.

    There are easy methods for this hidden in the ChartControl.

    For X coordinates by bar number, you can use:

    Code:
    ChartControl.GetXByBarIdx(BarsArray[0], 100)
    or for TIme:

    Code:
    ChartControl.GetXByTime(Time[0]);
    for Y:

    Code:
    ChartControl.GetYByValue(this, 2000);
    Depending on where these are used, ChartControl can be null so a null check is always recommended as well:

    Code:
    if(ChartControl != null)
    {
    //do stuff
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for revealing unsupported methods Jesse!

      So the null check is for checking for a chart instance, right?

      No "visible" chart == null ?

      //Fredrik
      Last edited by FREEN; 10-19-2015, 03:51 PM.

      Comment


        #4
        Hello,

        Correct, a Situation you often run into ChartControl being null would be in an indicator that is in the Market Analyzer. There is no chart so any ChartControl calls would be null.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          How do we convert back from the .NET x,y coordinates to NinjaTrader barnumber/price?


          So we might have something like

          double x = ChartControl.GetXByBarIdx(BarsArray[0], barnumber);
          double y = ChartControl.GetYByValue(this, pricevalue);

          //do some calculations using x,y and get updated values x1,y1

          //we then want

          int barnumber = GetBarNumber(x1);
          double priceval = GetPrice(y1);

          This is just dummy code but how would GetBarNumber(), GetPrice() be implemented?

          Comment


            #6
            Hello,

            Thank you for the question.

            For NT7 I would have no suggestion here as there are no exposed methods for this that I could relay. Going forward in NT8 the ChartControl and other chart-related coordinate methods have all been exposed so you can translate back and forth between coordinate and price/time.

            If any other NT7 users have custom solutions for this question an answer would be welcome for any undocumented/unsupported solutions.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by w0lverine, Yesterday, 11:28 AM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by calebsandfort, 12-07-2018, 09:54 PM
            2 responses
            19 views
            0 likes
            Last Post calebsandfort  
            Started by thuff, Today, 04:47 PM
            0 responses
            3 views
            0 likes
            Last Post thuff
            by thuff
             
            Started by herben31, Today, 03:00 PM
            0 responses
            24 views
            0 likes
            Last Post herben31  
            Started by BarzTrading, 12-07-2018, 09:26 PM
            1 response
            18 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X