• 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

  • FREEN
    started a topic Point type to Bars/Price converter?

    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.

  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • mballagan
    replied
    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?

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • FREEN
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by jrp2099, 01-19-2019, 11:20 AM
4 responses
25 views
0 likes
Last Post jrp2099
by jrp2099
 
Started by jxz1995, 12-23-2018, 10:44 PM
4 responses
25 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by sergey_z, Today, 03:42 AM
5 responses
11 views
0 likes
Last Post NinjaTrader_PaulH  
Started by U0000999, Today, 04:24 AM
0 responses
4 views
0 likes
Last Post U0000999  
Started by lehula, 01-18-2019, 08:13 PM
1 response
17 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X