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

RenderTarget.FillRectangle() and DrawTextLayout() in a loop.

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

    RenderTarget.FillRectangle() and DrawTextLayout() in a loop.

    Win 10 and Ninja 8.0.17.2 64-bit
    I want to draw, within the visible bars window, rectangular boxes which represent a forex session (Start/End time and session high/low). To achieve this I use RenderTarget.FillRectangle() in a loop through painted bars (FromIndex – ToIndex) in the OnRender method. Example below the indicator is applied to GBPUSD in a 15-minute time frame, 6 March 2019. Works fine until I add opacity (line 248), I get the following visual effect:

    Later in the code I add the day of week above the rectangle with the RenderTarget.DrawTextLayout() instruction in OnRender.

    When scrolling the chart with the right arrow key older TextLayout result remain on the chart. How to erase previous textlayout? I think the 2 effect are linked, what is wrong with this coding? Creating the SharpDXbrush before the loop and dispose right after should be enough, correct?

    [ATTACH]n1051506[/ATTACH] Click image for larger version

Name:	Fill_Rect_Pics.png
Views:	591
Size:	23.6 KB
ID:	1051504Click image for larger version

Name:	DrawTextLayout_Pics.png
Views:	561
Size:	14.0 KB
ID:	1051505

    #2
    Hello jpraema,

    Thanks for your post.

    It looks like you are drawing multiple rectangles on top of each other in the same render pass. When I scroll the chart, I do not see the rendering persist from the last render pass but still see multiple rectangles and TextLayouts. The Draw calls cannot be cancelled, so I may suggest to modify the logic so you are building the criteria for what you want to draw in your loop instead of drawing there and then drawing that criteria after the loop.

    Whenever you scroll the chart and a new bar and new rectangle are drawn, the previous rectangles will look more opaque because another rectangle with transparency is drawn on top of it. When you are not using transparency, we can't tell that there are multiple rectangles and we would not see the effect.

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim, I agree with your analysis, this was my conclusion too that’s why I also tried to use a series bool to flag drawed bars but I did run into another problem. From OnRender I can read correct bar value with the GetValueAt(index) method however I didn’t found in the help something to write to, something like SetValueAt(index). What method does the job or is there another trick to use? Maybe there another way I’m not aware off to clear previous rendered drawings (something like tags in drawing tools)?

      Comment


        #4
        Hello jpraema,

        SharpDX drawings will only be seen in the render pass that they are drawn. If we do not draw anything for a rendering pass, or want to "clear" it on the next rendering pass, then we should simply not call anything for that rendering pass.

        I would not suggest attempting to write to a Series<bool> to signal that an object is visible in OnRender(). For using a Series<bool> with custom rendering, I would suggest setting it in OnBarUpdate(), checking that value in OnRender(), and then to calculate what needs to be drawn. Since this would have purpose for when one bar should have an object drawn, and the goal here is draw one rectangle that spans multiple bars, I may suggest a different approach.

        In this case, I would suggest to have your loop:

        1) Identify when a new rectangle needs to be drawn, add the rect to collection/list of rects.
        2) Update the rect bounds as you are looping through instead of calling RenderTarget.DrawRectangle in your loop

        Then after your loop, call RenderTarget.DrawRectangle for each rect in your collection.

        Although not completely related as the context is making figures instead of rectangles, you may wish to see how I have handled the drawing in my Ichimoku Cloud indicator to see how I build shapes in the loop first, and then draw those figures after I have processed them. The same idea would be taken except that you would be updating the rect bounds in your loop as opposed to drawing another rect.

        Ichimoku Cloud - https://ninjatraderecosystem.com/use...indicator-nt8/

        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

        Please let me know if I can be of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by warreng86, 11-10-2020, 02:04 PM
        7 responses
        1,360 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Perr0Grande, Today, 08:16 PM
        0 responses
        5 views
        0 likes
        Last Post Perr0Grande  
        Started by elderan, Today, 08:03 PM
        0 responses
        9 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
        14 views
        0 likes
        Last Post maybeimnotrader  
        Working...
        X