Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing Object Count Limit

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

    Drawing Object Count Limit

    Good Evening,

    When adding values to a drawing object names to get additional objects drawn, such as
    Code:
    "Name"+CurrentBar
    What would be the appropriate way to limit the amount of drawing objects drawn while ensuring they are the most recent ones? Say I want to draw only 5 objects, the most recent 5 out of the entire series that exists. Since Objects are draw from left to right in the sequence of bar loading, using a counter such as below, wouldnt work because it would draw the first 5, not the recent 5.
    Code:
    if (condition)
    draw object;
    nCount = nCount + 1;
    
    
    "Name"+nCount
    What other method would solve this?

    #2
    If you only want to keep the most recent 100, you could do something like "Name" + (CurrentBar % 100).

    You also could keep track of the ones you've added in a list so you can delete them later (or perhaps, just delete them one at a time e.g. if (DrawingCount > 100) RemoveDrawObject("Name" + (DrawingCount - 100)); but the modulus approach is a bit more compact.
    Last edited by QuantKey_Bruce; 04-25-2023, 04:53 AM.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hi ChrisR, thanks for your question. One way to do it would be to keep a counter and reset it once it gets to 5 e.g.

      Code:
      //class level
      private int myCounter = 0;
      
      //OnBarUpdate
      
      if(myCounter >= 5)
          myCounter = 0;
      
      if(condition to draw)
      {
           Draw("Tag "+ myCounter)
           myCounter++
      }

      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
      574 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