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

x and y value

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

    x and y value

    I can get the Y value using int yByValue = chartScale.GetYByValue(foundIndex); or float chartScaleYValue = chartScale.GetYByValue(foundIndex);

    But how do i get my X value?

    float startX = chartControl.GetXByBarIndex(ChartBars, yByValue);
    float endX = chartControl.GetXByBarIndex(ChartBars, yByValue);

    There is no explanation in the tutorial to how position your line according to the Y and X. Other than
    SharpDX.Vector2startPoint=newSharpDX.Vector2(ChartPanel.X,ChartPanel.Y);
    SharpDX.Vector2endPoint=newSharpDX.Vector2(ChartPanel.X+ChartPanel.W,ChartPanel.Y+ChartPanel.H);



    TY

    #2
    Hello frankduc,

    But how do i get my X value?

    float startX = chartControl.GetXByBarIndex(ChartBars, yByValue);
    float endX = chartControl.GetXByBarIndex(ChartBars, yByValue);
    What you have provided is how to get an X value by a bars index, do you have a specific question surrounding this syntax and how it is used?

    To use this, you would need to supply a bars index to this method so that it can return an x value. This is similar to the syntax you had used in your other posts "GetBarIdxByX" but would be the reverse as you are now using an index instead of an X value and returning an X value instead of an index.

    There is no explanation in the tutorial to how position your line according to the Y and X. Other than
    SharpDX.Vector2startPoint=newSharpDX.Vector2(Chart Panel.X,ChartPanel.Y);
    SharpDX.Vector2endPoint=newSharpDX.Vector2(ChartPa nel.X+ChartPanel.W,ChartPanel.Y+ChartPanel.H);
    The SharpDX and OnRender samples will assume that you already have a good foundation on C# before attempting to use this code. There will not be much documentation for this topic and will rely on your development skills and understanding of concepts like using X/Y coordinates to plot in a graph. The methods which are exposed NinjaScript like GetXByBarIndex or GetYByValue can be used to generate X and Y values which could later be used in other rendering tasks. These are also not well documented as they are considered advanced tasks, I could suggest using Print statements here and starting as simple as possible to identify how to use the syntax you are asking about and also the values it returns. This will help your understanding of what the syntax is doing.

    Please let me know if I may be of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      My variable is foundIndex and it returns a bar in the chart. I want to draw the vertical line at that bar position.

      To get its position in the chart i need int yByValue = chartScale.GetYByValue(foundIndex); or float chartScaleYValue = chartScale.GetYByValue(foundIndex); both using Print() return the same position in the chart 31768
      Chart Panel.X,ChartPanel.Y return position 0,0 and produce a blue line crossing the chart. i have no problem with that. that part works for me.


      The way i see it 31768 is the exact point where is my bar in the chart. My vector should return something like this according to NT tutorial.

      SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX,chartScaleYValue);
      SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue);
      chartScaleYValue is the Y position (my variable at 31768) right?


      For startX and endX i am missing something, they are coming from :




      float startX = chartControl.GetXByBarIndex(ChartBars, ??);
      float endX = chartControl.GetXByBarIndex(ChartBars,???)
      As you can see on the attach chart where is the X position how do i get that number? Is there a 2nd Y position?

      If i get the X position will it draw a vertical line from the top of the chart to position 31768 or will it continu down to the bottom?

      You were talking about supllying a bars index i suppose you mean barIndex. So
      float startX = chartControl.GetXByBarIndex(ChartBars, barIndex); or like in the tutorial
      floatstartX=chartControl.GetXByBarIndex(ChartBars,ChartBars.FromIndex);




      But its not working and not returning a vertical bar. There is a loop in the exemple, do i need a loop?

      I know its suppose to be advance stuff but the information is scattered and partial. Just a little bit more info and you could avoid a lots of annoying questions from newbies like me.
      Attached Files

      Comment


        #4
        Hello frankduc,


        As you can see on the attach chart where is the X position how do i get that number?
        This takes a bar index, so however you are picking the target bar is how you would get the index. All I can say here is that you need a bar index to complete this syntax. You mentioned 31768, however you picked that you would need to pass the index to the method to get the X return.

        Is there a 2nd Y position?
        Yes

        If i get the X position will it draw a vertical line from the top of the chart to position 31768 or will it continu down to the bottom?
        It will draw what you specifically tell it to draw, you need 4 points total to draw a line. Where on the chart those point are located will be up to you. If you want to continue to the bottom, you need to supply a point which equate to the bottom.


        You were talking about supllying a bars index i suppose you mean barIndex. So
        float startX = chartControl.GetXByBarIndex(ChartBars, barIndex); or like in the tutorial
        floatstartX=chartControl.GetXByBarIndex(ChartBars, ChartBars.FromIndex);
        But its not working and not returning a vertical bar. There is a loop in the exemple, do i need a loop?

        If you are referring to one of the OnRender samples which includes ChartBars.FromIndex, you should read the description of ChartBars.FromIndex to see if that is what you want or if a loop is needed for what you are trying to do. ChartBars.FromIndex is an index, but this would not relate to what you have selected, FromIndex is a specific concept: https://ninjatrader.com/support/help...Bars.FromIndex

        I know its suppose to be advance stuff but the information is scattered and partial.
        Correct, The help guide does not provide much information here as noted this is for advanced developers who have a strong understanding of NinjaScript and C#. We expect that this area of the help guide will not cover all bases or provide walkthrough's on this topic. You can refer to the existing items which use OnRender for more in depth samples of specific concepts. I would suggest looking at the drawing tools and how they use OnRender, this can help in understanding the overall process happening with OnRender.

        If you feel that the help guide is not enough information or you are having trouble connecting the dots here, I can also suggest looking into third party C#/NinjaScript educators who can provide more hands on assistance.


        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          You said i needed 4 points to draw a line.

          i got my X and Y from my variable foundindex:

          int yByValue = chartScale.GetYByValue(foundIndex);
          int xCoordinate = chartControl.GetXByBarIndex(ChartBars, foundIndex);

          float startX = chartControl.GetXByBarIndex(ChartBars, yByValue);
          float endX = chartControl.GetXByBarIndex(ChartBars, xCoordinate);


          That gives me 2 floating point and now i need two more to connect my line between the two area.

          Somehow in rolloverindicator they use reuseLineVector2.Y = (float)ChartPanel.ActualHeight; to connect from top to bottom to generate a vertical line but that exemple is more complex that what i need. I wish they were a more obvious exemple.

          Is it possible to get a negative Y position? My float chartScaleYValue = chartScale.GetYByValue(foundIndex); returned -7838

          If X is really
          int xCoordinate = chartControl.GetXByBarIndex(ChartBars, foundIndex); 1463 Than it is also the same position 1463 for second X point?

          Than If my vertical line start at the top of the chart the Y position should be 0? So my top vertical second float point should be (1463, 0)?

          My variable (foundIndex bar) should be at (1463, -7838)?





          int yByValue = chartScale.GetYByValue(foundIndex);
          int xCoordinate = chartControl.GetXByBarIndex(ChartBars, foundIndex);
          float x = xCoordinate;
          float y = 0;

          float startX = chartControl.GetXByBarIndex(ChartBars, xCoordinate);
          float endX = chartControl.GetXByBarIndex(ChartBars, yByValue);

          SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, endX);
          SharpDX.Vector2 endPoint = new SharpDX.Vector2(x,y);

          I can see a blue line at the top of the chart starting at the right place but its not linking to the bar its doing a diagonal leaving the chart. What did i miss? I guess i have the wrong position.

          Is it
          chartControl.GetXByBarIndex to get the X?


          What i meant by lack of information was that they should of provided an exemple on how to make a vertical or horizontal line. The exemple is a diagonal (0,0) (x,y) who's using a diagonal in an indicator anyway? Vertical and horizontal are more common used.
          C#/NinjaScript educators probably another paying gamic? At least with stack overflow i get free answers even if they sometimes not useful.
          Last edited by frankduc; 07-18-2019, 12:19 PM.

          Comment


            #6
            Hello frankduc,

            Is it possible to get a negative Y position?
            Yes, if the value you supplied was not in the visible area or was not valid, it may be negative or a large number. GetYByValue takes a Price but it looks like you gave it an index which would not work.

            Than it is also the same position 1463 for second X point?
            If you wanted a line to be vertical, the points would need to be one above the other.


            Than If my vertical line start at the top of the chart the Y position should be 0? So my top vertical second float point should be (1463, 0)?

            My variable (foundIndex bar) should be at (1463, -7838)?
            Did you try this to observe the result? This would be a point to stop, test and observe the result.

            You may try Drawing a more simple object using X/Y such as an ellipse to further explore the coordinates in the chart.






















            JesseNinjaTrader Customer Service

            Comment


              #7
              Ellipse needs an X,Y from 2 float , 2 vectors its not very different. In fact it looks more like it needs position to draw a rectangle and the ellipse is trap inside. I find both as complicated but at least now i can see a blue line i just have to understand what's going wrong.

              Y must = 0 to keep the first point of the line at the top of the chart. Than X moves accordingly to the X,Y position of my second point which is my variable bar foundIndex.


              int yByValue = chartScale.GetYByValue(foundIndex);
              int xCoordinate = chartControl.GetXByBarIndex(ChartBars, foundIndex);
              float x = xCoordinate;
              float y = 0;

              float startX = chartControl.GetXByBarIndex(ChartBars, xCoordinate);
              float endX = chartControl.GetXByBarIndex(ChartBars, yByValue);

              float chartScaleYValue = chartScale.GetYByValue(foundIndex);



              SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, endX);
              SharpDX.Vector2 endPoint = new SharpDX.Vector2(x,y);


              But something is wrong the line starts at the top of the chart in line with foundIndex than it moves like a diagonal out of the chart. The position of the float are wrong but i cant figure out why.
              My vertical is tilting at the base on the left side. Maybe lack of solid base.

              Its strange if the scrollbar fill the entire chart the vertical line is near perfect straight but the more you add data on the chart the more the scrollbar get smaller the less vertical is the line, its tilting to the left a few degrees.

              thanks
              Last edited by frankduc; 07-19-2019, 07:16 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by thanajo, 05-04-2021, 02:11 AM
              3 responses
              467 views
              0 likes
              Last Post tradingnasdaqprueba  
              Started by Christopher_R, Today, 12:29 AM
              0 responses
              10 views
              0 likes
              Last Post Christopher_R  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              166 responses
              2,236 views
              0 likes
              Last Post sidlercom80  
              Started by thread, Yesterday, 11:58 PM
              0 responses
              4 views
              0 likes
              Last Post thread
              by thread
               
              Started by jclose, Yesterday, 09:37 PM
              0 responses
              9 views
              0 likes
              Last Post jclose
              by jclose
               
              Working...
              X