Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Showing specific number of drawings only.

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

    Showing specific number of drawings only.

    Hello. I wonder if someone can help me. Assume I have an indicator that draws arrows under bars that are greater than 20 ticks.

    I know I can only show the most recent arrows by keeping the tag the same in the draw.uparrow object.

    I know I can show all arrows by adding CurrentBar[0] or something to the tag to make each arrow a unique name.

    But what if I wanted to show only the last 4 arrows? or only the last 10 arrows. How would I achieve something like that?

    #2
    Hello several,

    Thank you for your post.

    One idea is to keep track of the drawing objects you've created by adding their tag names to a list or series so you can delete them later. Once the last is greater than 4 elements, call RemoveDrawObject on the 5th element which will contain the tag name for the 5th drawing.

    Comment


      #3
      A simple way is to use a counter: int ArrowCtr
      Include the counter in the arrow object, something like this: "MyArrow" + ArrowCtr
      Have a parameter for kept arrows: int ArrowsToKeep = 4
      Draw your new arrow, then remove an arrow: RemoveDrawObject("MyArrow" + (ArrowCtr - ArrowsToKeep));
      Then increment your counter: ArrowCtr ++;

      Edit: I see Gaby already responded too. My example will use less memory but both would work.
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Thanks guys!! Will try it.

        Comment


          #5
          Another approach is letting the math processor do the work for you using the modulo operator.

          private string const string UNIQUE_TAG_PREFIX = "myUniquePrefix"; // to avoid naming collisions
          private int arrowCounter = 0;

          [NinjaScriptProperty]
          [Range(1, 100)]
          [Display(GroupName = "Parameters", Order = 1, Name = "Number of Arrows", Description = "How many arrows to display. Max 100")]
          public int NumberArrows { get; set; }

          ​In the looping logic within OnBarUpdate()

          arrowCounter = ++arrowCounter % NumberArrows;
          string myRotatingTag = UNIQUE_TAG_PREFIX + arrowCounter;
          // Use the myRotatingTag in the Draw method.

          If you understand the modulo operator, you'll see that code will rotate through NumberArrows tags. By repeating the tags on a rotating basis, the old is automatically replaced with the new by the NT8 rendering engine.

          Hope that helps!
          Matt

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X