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

OnRender - SharpDX properties of Plots

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

    OnRender - SharpDX properties of Plots

    During OnRender for both chart styles and indicators, can NT support elaborate officially on whether or not we can rely that BrushDX, Stroke, StrokeStyle etc. are always set (not null) and are always valid and always configured for the correct RenderTarget (the one being rendered now)?

    Anecdotally, this seems to be true, and some of the chart styles appear to rely on this being true (there are no != null checks in the CandleStyle chart style, for instance, when referring to Stroke.BrushDX), however, there is no place in the documentation that says we can rely on this.

    I am fairly sure from looking at the provided examples that this must be the case, but I would just like to know formally from NT (and not just anecdotally that it appears to be true) that we can rely on this.
    Last edited by QuantKey_Bruce; 03-12-2017, 11:38 AM.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    #2
    Hi Bruce,

    The help guide does mention the RenderTarget will be destroyed occasionally and that resources should be maintained in OnRenderTargetChanged().
    "Note: A RenderTarget will be created and destroyed several times during the lifetime of a chart. For example, a user resizing the chart would cause the RenderTarget to be re-created as the chart is rendered to reflect the new dimensions. Another example is when a user clicks on the chart as a RenderTarget is used during hit testing. Since there are multiple RenderTargets, you MUST ensure the resource being used belongs to the destination target. In practice, all you need to understand is if you are using a device resource (e.g., custom SharpDX Brush) throughout different event methods, you should recreate these resource during OnRenderTargetChanged() which ensures the device resource is updated correctly as the devices context changes."


    And
    "Warning: There may be situations where a RenderTarget has not been set, and to prevent access violation exception before accessing the BrushDX or DashStyleDX properties, you should explicitly set the RenderTarget before attempting to access that property. Please see the example below."


    Do you feel that the warnings on these pages are inadequate or incorrect?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Do you feel that the warnings on these pages are inadequate or incorrect?
      Well, I would note that the CandleStyle chart style does none of these things you just listed, and uses the properties such as the stroke's SharpDX brush as is, which is one reason I asked, and also asked for a clarification regarding whether this applied to both chart styles and indicators or if the warning were only for indicators.

      Also, my understanding was that the need to do OnRenderTargetChanged() is only if we keep a reference to BrushDX and similar resources outside of OnRender (as a class-level variable, for instance). If we are within OnRender when .BrushDX is accessed on a plot, it would not appear this would be necessary, but I was seeking clarification to be certain, because the documentation does not say.

      It would appear, upon cursory examination, that all of the NT-provided code assumes they will be set correctly (for plots, at least, in indicators, and for the stroke, at least, in chart styles) upon arrival to OnRender() itself, but it never explicitly says in the documentation that this is true.

      What I would like is to hear from NT a clear statement that while in OnRender on an indicator, each Plot object's BrushDX and StrokeStyle are always set and set to the correct render target, and that while in OnRender on a chart style, the corresponding properties of brushes and strokes are always set and on the correct render target. In other words, that the whole OnRenderTargetChanged process is only necessary if keeping a class-level variable outside of the specific invocation of OnRender that has SharpDX resources such as brushes or stroke styles etc.
      Last edited by QuantKey_Bruce; 03-12-2017, 03:45 PM.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hello Bruce,

        From my understanding the RenderTarget will not change while OnRender() is running. If you are creating an object within the scope of OnRender and setting this to the RenderTarget, that RenderTarget would not be destroyed until that pass of OnRender() has completed. It would be expected that the RenderTarget for the object will not change during that one pass of OnRender().
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          My question was are the Plots' .BrushDX properties already guaranteed to be non-null and set for the right render target, and similarly for the brush and stroke involved in a chart style.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Hello Bruce,

            For any NinjaTrader object (such as a plot) in a script that is past the State.Configure State will have the .BrushDX property object updated to the new RenderTarget as this changes.

            However, if in a State of .Configure or above or State.Terminated, the .BrushDX object will be null.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you. Same for the Stroke property on chart styles?

              Also, are you waiting for OnRender to exit before setting .BrushDX to null during the process of setting the state to Terminated?
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Hello Bruce,

                Yes, the .BrushDX property of the Stroke and Stroke2 objects in ChartStyles are handled internally.

                Are you able to demonstrates issues with this?

                Regarding OnRender() and OnStateChange(), these are asynchronous methods, however, our development has let me know that OnStateChange() should wait until OnRender() is complete before setting any of these objects to null. If you are able to demonstrate behavior where this is causing issues, we can report this as a bug report.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  No, I do not have a specific trouble report about this - I was asking how it is officially supposed to work, and whether I needed to check for the RenderTarget changing myself. Since the answer is no, I won't worry about it unless/until there's an issue. Thank you for clarifying how it works, I appreciate it.
                  Bruce DeVault
                  QuantKey Trading Vendor Services
                  NinjaTrader Ecosystem Vendor - QuantKey

                  Comment


                    #10
                    Hi Bruce,

                    From my understanding you would not be able to control the brush property of a plot or the Stroke object in a ChartStyle even if you wanted to.

                    These are handled internally by NinjaTrader and all properties are generated, modified, and updated by the backend several times during the life of that object.

                    You will not be able to prevent or override the backend work NinjaTrader does for plots for or any other internally managed objects.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      By way of perspective, there are several times during the course of the discussion of the OnRender issues in other threads the last few weeks that NT support has suggested that it is important we always check for null, set our render targets, etc. which is why I was asking if in this case, when talking about the plot properties (and stroke properties, in the case of chart styles) we can rely on them already being handled. Fortunately, it sounds like the answer is yes, and we only need to worry about this for our own resources we created that are kept outside of the scope of OnRender.
                      Bruce DeVault
                      QuantKey Trading Vendor Services
                      NinjaTrader Ecosystem Vendor - QuantKey

                      Comment


                        #12
                        Hello Bruce,

                        This is absolutely true for any objects that you create.

                        This would not apply to any objects that NinjaTrader creates and manages internally.
                        Last edited by NinjaTrader_ChelseaB; 03-15-2017, 04:00 PM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Perr0Grande, Today, 08:16 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Perr0Grande  
                        Started by elderan, Today, 08:03 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post elderan
                        by elderan
                         
                        Started by algospoke, Today, 06:40 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post algospoke  
                        Started by maybeimnotrader, Today, 05:46 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post maybeimnotrader  
                        Started by quantismo, Today, 05:13 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post quantismo  
                        Working...
                        X