Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnRender draw grackground with one brush - sample values per pixel?

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

    OnRender draw grackground with one brush - sample values per pixel?

    Hey, I'm making a volume heatmap and drawing it using onRender. At the moment I'm using RenderTarget.FillRectangle() per bar, per tick which is of course horribly slow to draw. So I 'm thinking there must be more elegant way of doing this, any ideas?

    Click image for larger version

Name:	image.png
Views:	137
Size:	125.8 KB
ID:	1245398

    #2
    Hello Magzor,

    Thank you for your post.

    If you have not already, I suggest reviewing the "Best Practices for SharpDX Resources" found here:You will want to make sure you are optimizing your script by handling resources in an efficient manner. For example, you will need to make sure you create and dispose of brushes efficiently. There is a snippet from the OnRender() page that shows "Using a static SharpDX Brush to render a rectangle on the chart panel" that recreates and disposes of the brush on each render pass:


    My colleague has also created an example that shows how to reuse DX brushes which may be found here:


    We have additional performance-related best practices that may be found here that could help to improve and optimize your script:


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

    Comment


      #3
      Hi Emily, thanks for the reply, and thank s for the resources. I think I maybe wasn't clear enough with my question, let me try to rephrase. Is there a was to draw the whole background with a single draw call? So first rasterize it, then draw it in a single object?

      Comment


        #4
        You can bitblt an image you have pre-drawn or you can draw around or fill inside a path, in addition to drawing it one operation at a time. That's getting pretty far afield though of NinjaTrader-specific programming and more a question of how, philosophically, you go about drawing graphics. What you portray in that screenshot though will always be inherently inefficient because it has a large number of potentially different things. One of the best things you could do would be to make an array in advance with all of the different brushes you need (all the gradients or opacities) and then the next thing would likely be to see where you can combine adjacent rectangles into one wider rectangle. But, at some point, it becomes "premature optimization is the root of all evil" - you should only do what you must at some level.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Hello Magzor,

          Thank you for clarifying your question.

          I am not aware of any way to rasterize the chart background and then work with it pixel-by-pixel or draw it in a single draw call. What you aim to achieve with a volume heatmap is a resource-intensive script by nature and the suggestions I offered are the only ways I can think of to try and optimize performance. This thread will remain open for members of the forum community to offer their thoughts and suggestions, such as Bruce's post. Otherwise, feel free to reach out with any additional questions or concerns.

          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
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 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
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X