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

Best practices to draw Region/cloud/area

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

    Best practices to draw Region/cloud/area

    Generally, to draw the region, like:

    Click image for larger version

Name:	MdMWdb4.png
Views:	463
Size:	9.9 KB
ID:	1077385

    I dont use "Draw" on each bar (which seems to make things slower and draws hundreds of drawing objects) , instead I use this approach, to draw it once on last bar:

    Code:
    if (CurrentBar >= Bars.Count-2)
          Draw.Region(this, "channel", Time[0], Time[CurrentBar - MinBars], UpperLine, LowerLine, Brushes.Aqua, Brushes.Aqua, 30);
    However, my question is - if indicator is set to "Calculate.OnEachTick" i suspect that will case much overload because it will try to re-draw for whole chart, right?
    if so, what are recommended approaches to draw clouds like this, so it could work with On EachTick too, but spent less resources.

    #2
    To answer my question theorerically, I suspect one of the solutions could be to draw one CURRENTBAR reaches the PREVIOUS OF REALTIME BAR, and after that draw second region from REALTIME BAR to the start-of-realtime bar.

    Comment


      #3
      Hello TazoTodua,

      Yes if you were using on each tick that would cause it to be called more assuming the condition was evaluating true for each tick. You could add IsFirstTickOfBar in that use case to only calculate this once per bar or use logic to only call this when a change is necessary. Another approach is making a variable to store the CurrentBar to and then compare if the current bar is different from the variable.

      I look forward to being of further assistance.

      JesseNinjaTrader Customer Service

      Comment


        #4
        the problem with OnFirstTick is that it will get the first tick values (of bar) of the TOP and BOTTOM lines, and thus will be quite incorrect after bar close, i.e. if we are on hourly chart and just draw it on first tick then till close the values will be quite different..so, OnFIrstTick is not good

        Comment


          #5
          Originally posted by TazoTodua View Post
          the problem with OnFirstTick is that it will get the first tick values (of bar) of the TOP and BOTTOM lines, and thus will be quite incorrect after bar close, i.e. if we are on hourly chart and just draw it on first tick then till close the values will be quite different..so, OnFIrstTick is not good
          1. On first tick of bar, store the high and low, and then draw the region.
          2. On each tick, check if the then current high or low is different from the stored values, then redraw with new values and update the stores.
          Simpler yet, and probably implemented that way under the covers, consider using Calculate.OnPriceChange instead of OnEachTick.

          Best yet, for best performance, junk the overhead from the internal methods, and custom render the region yourself with an OnRender() override. If you choose this route, you can examine Draw.Polygon, which has a complex render routine using indefinite size polygons. A better, simpler method, is to simply render using quadrilaterals. Interestingly enough where the series come to a vertex at a datapoint, and it would appear that one should render a triangle, you just have to remember that a triangle is the same as having a quadrilateral with 2 co-incident vertices, so there is no need to write a special routine to handle what look like triangles.

          Comment


            #6
            koganam, as always, nice answer thanks..
            I was also thinking about adding button for user to click to reload whenever he want to see an updated drawing, but your answer is better.. OnRender would be quite less resource-hungry in my case though, but my case is not for public-wide use,so i will go with Draw.Region
            Last edited by ttodua; 11-14-2019, 11:15 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samish18, Yesterday, 08:31 AM
            4 responses
            14 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by funk10101, Yesterday, 09:43 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            5 responses
            551 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by rtwave, 04-12-2024, 09:30 AM
            5 responses
            37 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by funk10101, Today, 12:02 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X