• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:	44
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, 10:15 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by moyerchopra, Yesterday, 11:43 PM
            0 responses
            1 view
            0 likes
            Last Post moyerchopra  
            Started by ttodua, Yesterday, 11:40 PM
            0 responses
            1 view
            0 likes
            Last Post ttodua
            by ttodua
             
            Started by edmata1109, 12-04-2019, 09:19 PM
            8 responses
            28 views
            0 likes
            Last Post koganam
            by koganam
             
            Started by maindoor, 12-03-2019, 10:45 PM
            9 responses
            63 views
            0 likes
            Last Post koganam
            by koganam
             
            Started by w0lverine, Yesterday, 08:22 PM
            0 responses
            1 view
            0 likes
            Last Post w0lverine  
            Working...
            X