Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

draw vertical line

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

    #31
    I get that ChartControl belong to OR. You have to check for Null with :

    if(ChartControl != null)
    {
    cursorPointX = ChartingExtensions.ConvertToHorizontalPixels(Chart Control.MouseDownPoint.X, ChartControl);
    }

    else ??

    {
    // some code?
    }

    I mean once ChartControl is null it cant be used? It has to be replaced by something else, but by what?

    What about
    MouseDownPoint.X,
    Low.GetValueAt, ChartBars.GetBarIdxByX,
    ChartBars.ToIndex
    do they belong to OR too? Do they need to be also tested for null?

    What about:

    int bar = Math.Abs(ChartBars.GetBarIdxByX(ChartControl, cursorPointX) - ChartBars.ToIndex);

    Do i have to create a private int bar = 0; or can i keep the actual syntax? If i declare a variable can it be done in OBU or it must be done at class level?

    I am starting to see the big picture. OBU dont provide as much freedom as OR. Draw that line OBU or OR comes to how strong is your C# knowledge.

    Comment


      #32
      Hello frankduc,

      I get that ChartControl belong to OR.
      ChartControl does not belong to OnRender, it is just passed in there. ChartControl is owned by the chart, your script only knows about it because it is a property of your script after you apply it to a chart. OnRender knows about it because it is one of the parameters of OnRender. ChartControl does not belong to OnRender or OnBarUpdate or your script really, it is just the instance of the ChartControl in the chart being used. This means there are multiple ways to access this control.


      I mean once ChartControl is null it cant be used? It has to be replaced by something else, but by what?
      Correct there is no else here, if its null it cannot be used. There is no other replacement for what you are using when it is null, you just cant use it then. The methods you are using to convert values require specific objects and those objects also have specific requirements when they are created.

      ChartControl can only be used when it is present, in an indicator this is only when it is applied to a chart. It is null when called from a strategy. Generally you only see ChartControl used in Onrender for its conversion methods to access BarData for rendering. If you choose to try and use ChartControl from OnBarUpdate, you now have to account for that because it is expected that it will be null for some parts of the scripts processing. You can Print(ChartControl == null) to see when this is or is not null.

      I am starting to see the big picture. OBU dont provide as much freedom as OR. Draw that line OBU or OR comes to how strong is your C# knowledge.
      I don't believe this would be a correct statement, OBU and OnRender are for two different purposes. Neither gives you more freedoms than the other, they are for different use cases. OnBarUpdate is for processing bar data at fixed bar intervals or in relation to a series of data. OnRender is for custom rendering.

      Manual programming in NinjaTrader assumes that you already have some base C# knowledge or manual programming knowledge prior to starting with NinjaScript. Our support does not provide C# education so if you want to manually program, you would need to invest time in learning C# from external resources. NinjaScript is only a C# API which can be accessed through C# code. Having a strong understanding of C# before diving into complex NinjaScript items goes a long way.




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

      Comment


        #33
        I am still in quest to find an easy way to draw an object in the chart. Instead of a vertical line i thought maybe a blue dot like the one in MouseXYtoTimePriceExample.

        Would it be possible to transfer a part of the script and use it to draw the blue dot at a specific position using the same methods?

        The way i see it i need:

        private System.Windows.Media.Brush ellipseBrush;
        private SharpDX.Direct2D1.Brush ellipseBrushDX;

        ellipseBrush = Brushes.Blue.Clone();

        and

        SharpDX.Vector2 ellipseVector = clickPoint.ToVector2();
        newEllipses.Add(new SharpDX.Direct2D1.Ellipse(ellipseVector, 10f, 10f));


        I suppose the (=) part lead to the positioning of the object but i wonder if its possible to use the x and y as we spoke before about the vertical line https://ninjatrader.com/support/help...etybyvalue.htm

        Maybe more easy than the vertical line.

        TY
        Attached Files

        Comment


          #34
          Hello frankduc,

          This would be no different than the vertical line, you are still working with X/Y coordinates and using sharpDX for the drawing in this sample. This is very similar to what we have been speaking about already. Changing from a vertical line to an ellipse will not change the remainder of what you are doing, just how you use the X/Y values you created so really this is no simpler.

          If drawing the vertical line is still evading you, I would suggest to continue working toward that to fully understand how to do that before moving to a different unrelated sample.


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X