Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using tags with SharpDX objects

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

    Using tags with SharpDX objects

    I'm developing a custom indicator using RenderTarget.DrawLine which is working properly, except that the same line is being redrawn instead of a new line when new values are calculated. Is there an override I can use similar to draw.line with tags so that each RenderTarget.DrawLine object is unique?

    Thanks

    #2
    Hello mgin98,

    Thanks for your post.

    Rendering objects is not like calling a Drawing Tool such as Draw.Line(). Tags are part of Drawing Tools and not part of custom Rendering. Rendering a line using RenderTarget.DrawLine does not have an option for providing the DrawLine object with a unique tag name similar to calling the Drawing Tool Draw.Line().

    If you would like to have a second line drawn, you would need to call RenderTarget.DrawLine twice and supply values to draw the new line in the new location.

    See the help guide documentation for more information about working with SharpDX.
    Working with SharpDX for custom rendering: https://ninjatrader.com/support/help..._rendering.htm
    RenderTarget.DrawLine: https://ninjatrader.com/support/help...t_drawline.htm

    Let us know if we may assist further.


    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks for confirming Brandon. I'll store the x/y values in a dictionary and try referencing that to render.

      Comment


        #4
        I need the RemoveDrawObjects functionality but using RenderTarget. How would you achieve the same thing?

        Comment


          #5
          Originally posted by evnmck View Post
          I need the RemoveDrawObjects functionality but using RenderTarget. How would you achieve the same thing?
          Hello evnmck,

          Thank you for your post and welcome to the NinjaTrader forum community!

          I'm not sure I understand what you are referring to. SharpDX objects are rendered/drawn with each pass of OnRender and not an actual object that is added to or removed from the chart. If you do not want a SharpDX object to appear on the chart, then you could simply stop creating the resources and rendering it in OnRender. For example, if you wanted a line to be rendered only when the Close price IsRising and not render the object when the Close price IsFalling, you could create a bool to conditionally render the line like in the following snippet.

          Code:
          private bool renderLine;
                  protected override void OnBarUpdate()
                  {
                      if (CurrentBar < 10)
                          return;
                      if (IsRising(Close))
                          renderLine = true;
                      if (IsFalling(Close))
                          renderLine = false;
                  }
          
                  protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                  {
                      if (renderLine)
                      {
                          // create two vectors for the line to draw
                          SharpDX.Vector2 startPoint = new SharpDX.Vector2(ChartPanel.X, ChartPanel.Y);
                          SharpDX.Vector2 endPoint = new SharpDX.Vector2(ChartPanel.X + ChartPanel.W, ChartPanel.Y + ChartPanel.H);
                          // define the brush used in the line
                          SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue);
                          // execute the render target draw line with desired values
                          RenderTarget.DrawLine(startPoint, endPoint, customDXBrush, 2);  
                          // always dispose of a brush when finished
                          customDXBrush.Dispose();
                      }
                  }
          ​
          In that snippet, the logic that creates the resources and executes RenderTarget.DrawLine is only processed if the bool renderLine is true. That bool is set in OnBarUpdate() to help create a condition for when the object should be rendered or not.

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

          Comment


            #6
            Emily, THANK you so much for the quick response! What I originally was doing was drawing a small onBarUpdate line at the high and the low of the bar but because it has to be drawn from one bar to another i was using from CurrentBar to -1. So it drew a line between it and the next bar. But what I really want to do is draw a line that goes through the Current bar and just stick out a little on both sides of the width of the bar. My issue is that i need EVERY bar prior to have these lines just like the onBarUpdate displays them. Basically, as the bar grows it will re render a line at the new high and new low on every tick and when the next bar comes those 2 lines stay exactly where they are.

            Comment


              #7
              Hello evnmck,

              Thank you for your reply.

              I appreciate the additional information. Drawing lines on every bar could quickly become resource-intensive and have a performance impact. You could definitely look into using SharpDX for custom rendering in the OnRender() method instead to save resources and have a better performance experience. You could also likely have the line go on the current bar rather than drawing between two bars. I suggest reviewing the following resources to help you better understand what would be involved and how to achieve your desired outcome with OnRender():You may also review the indicator "SampleCustomRender" that comes with the platform by default to see an example of OnRender() in action. The script is available in the NinjaScript Editor so you may review the logic as well.

              Please let us know if we may be of further assistance.

              Comment


                #8
                Originally posted by NinjaTrader_Emily View Post
                Hello evnmck,

                Thank you for your reply.

                I appreciate the additional information. Drawing lines on every bar could quickly become resource-intensive and have a performance impact. You could definitely look into using SharpDX for custom rendering in the OnRender() method instead to save resources and have a better performance experience. You could also likely have the line go on the current bar rather than drawing between two bars. I suggest reviewing the following resources to help you better understand what would be involved and how to achieve your desired outcome with OnRender():You may also review the indicator "SampleCustomRender" that comes with the platform by default to see an example of OnRender() in action. The script is available in the NinjaScript Editor so you may review the logic as well.

                Please let us know if we may be of further assistance.
                Honestly i've already exhausted those resources but thank you anyway. ..

                Comment


                  #9
                  Hello evnmck,

                  Thank you for your reply.

                  Although we do not provide C# programming education services or one on one educational support in our NinjaScript Support department, you could contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services. Please let me know if this option interests you and I can get you more information.

                  Thank you for using NinjaTrader.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  648 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  369 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  573 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  575 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X