Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

On Render

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

    On Render

    Hi,

    could you please provide some examples on how to draw text from within the On Render Method.
    Please explain step by step what is needed for that, especially all required parameters. I had a look at the custom plot and bar timer examples, but I cannot really make sense of it.

    Thanks in advance.

    #2
    Hello,

    To do this, you can use the SharpDX.Direct2D1.DirectWrite library to draw text directly on your chart.

    Attached is a step-by-step example of how to accomplish this. The code in OnRender() can be conceptually separated into two steps: First, we instantiate a number of objects to be passed in as arguments to RenderTarget.DrawText(), and then we call DrawText() to perform the actual drawing. This should walk you through each of the parameters required to accomplish the goal.
    Attached Files
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Dave View Post
      Hello,

      To do this, you can use the SharpDX.Direct2D1.DirectWrite library to draw text directly on your chart.

      Attached is a step-by-step example of how to accomplish this. The code in OnRender() can be conceptually separated into two steps: First, we instantiate a number of objects to be passed in as arguments to RenderTarget.DrawText(), and then we call DrawText() to perform the actual drawing. This should walk you through each of the parameters required to accomplish the goal.
      Bravo! That could not have been more clearly written and explained! The official documents at SharpDX have been as clear as mud as I try to wade through them. Maybe it is just me?

      Comment


        #4
        Thanks so much, Dave.
        Thats exactly what I was looking for.

        Comment


          #5
          Originally posted by koganam View Post
          Bravo! That could not have been more clearly written and explained! The official documents at SharpDX have been as clear as mud as I try to wade through them. Maybe it is just me?
          +1

          In my experience and my personal opinion, we definitely cannot rely on pointing users to the SharpDX documentation alone and we hope to have more NinjaTrader specific documentation by open beta...
          MatthewNinjaTrader Product Management

          Comment


            #6
            Originally posted by NinjaTrader_Dave View Post
            Attached is a step-by-step example of how to accomplish this. The code in OnRender() can be conceptually separated into two steps: First, we instantiate a number of objects to be passed in as arguments to RenderTarget.DrawText(), and then we call DrawText() to perform the actual drawing. This should walk you through each of the parameters required to accomplish the goal.
            Shouldn't the factory and textBrush also be disposed? or no?

            Code:
             [COLOR=#080808]factory[/COLOR].[COLOR=#080808]Dispose[/COLOR]();
             [COLOR=#080808]textBrush[/COLOR].[COLOR=#080808]Dispose[/COLOR]();
            -=Edge=-
            NinjaTrader Ecosystem Vendor - High Tech Trading Analysis

            Comment


              #7
              Yes, I believe you are correct. Any unmanaged resources created from the SharpDX libraries should be disposed when they are no longer needed.
              Dave I.NinjaTrader Product Management

              Comment


                #8
                could please provide an additional example for drawing lines using on render method similar to the text example below.

                thanks

                Comment


                  #9
                  Hello,

                  It's a bit easier to use DrawLine than DrawText. I've modified the code and attached it to this post. All that is needed to use the specific overload in the example is two Vector2 objects and a SharpDX Brush (which we had already instantiated for DrawText).
                  Attached Files
                  Dave I.NinjaTrader Product Management

                  Comment


                    #10
                    Hello,

                    Is it posible to draw in an indicator's panel?

                    Thanks.

                    Comment


                      #11
                      When you are using SharpDX drawing methods such as these, you are drawing them on the Render Target referenced by the RenderTarget property, which covers the entire chart canvas, including all panels. However, we have intentionally adding clipping bounds to ensure that these methods can only be used to draw within the specific panel in which the calling object resides.

                      So if you are drawing from an indicator, the results will always be drawn in the same panel. But if you wanted to draw on Panel 2 from an object (indicator or strategy) in Panel 1, for example, you would not be able to do this. In that case, I would recommend calling the drawing methods from the indicator itself.
                      Dave I.NinjaTrader Product Management

                      Comment


                        #12
                        Originally posted by NinjaTrader_Dave View Post
                        ...

                        So if you are drawing from an indicator, the results will always be drawn in the same panel.
                        Really? Has DrawOnPricePanel been removed as a property.

                        Comment


                          #13
                          Originally posted by koganam View Post
                          Really? Has DrawOnPricePanel been removed as a property.
                          No, that is still there, but only works for Drawing Tool methods (Draw.Line())

                          What Dave refers to is the IndicatorBase RenderTarget with an indicator. You can only render custom shapes/text in the indicator panel configured on the chart if you're doing so from an indicator's OnRender(). You could however create your own custom drawing tool method, and then call that instead of overriding the indicator's OnRender() method.
                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            DrawOnPricePanel is still implemented, but it pertains to a different specific context. DrawOnPricePanel specifically governs drawing objects created via NinjaScript drawing-object methods (Draw.Text, Draw.Line, etc.). But in this context we're talking about using SharpDX drawing methods (DrawText, DrawLine, etc.), which rely on a RenderTarget passed in to the method.

                            When drawing directly with SharpDX, rather than using drawing methods in the NinjaScript namespace, the clipping bounds will prevent you from drawing across the panel. Without this clipping in place, SharpDX draw method coordinates (Vector2's) would relate to the entire chart canvas, so you could potentially have things drawn across multiple panels at once, as the coordinates would be based upon the entire canvas.
                            Dave I.NinjaTrader Product Management

                            Comment


                              #15
                              Originally posted by NinjaTrader_Dave View Post
                              DrawOnPricePanel is still implemented, but it pertains to a different specific context. DrawOnPricePanel specifically governs drawing objects created via NinjaScript drawing-object methods (Draw.Text, Draw.Line, etc.). But in this context we're talking about using SharpDX drawing methods (DrawText, DrawLine, etc.), which rely on a RenderTarget passed in to the method.

                              When drawing directly with SharpDX, rather than using drawing methods in the NinjaScript namespace, the clipping bounds will prevent you from drawing across the panel. Without this clipping in place, SharpDX draw method coordinates (Vector2's) would relate to the entire chart canvas, so you could potentially have things drawn across multiple panels at once, as the coordinates would be based upon the entire canvas.
                              To both you and Matthew, thanks for the explanation: my brain pooped, or I should have seen that without raising the issue.

                              It is pretty much analogous to NT7, where even a custom Plot could not draw on a different panel. At any rate, not without some serious graphics and C# shenanigans.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,603 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X