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

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, 03: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, 04: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 maybeimnotrader, Yesterday, 05:46 PM
            1 response
            18 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Perr0Grande, Yesterday, 08:16 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by f.saeidi, Yesterday, 08:12 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by algospoke, Yesterday, 06:40 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by quantismo, Yesterday, 05:13 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X