Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RemoveDrawObject

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

    RemoveDrawObject

    My indicator draws a horizontal line ("DrawLine") when two conditions are fulfilled. The second part is that when either of these two conditions reverses within the same bar it is supposed to "RemoveDrawObject" i.e. remove the line. It does not do that. Only when I push F5 to refresh the chart does the line disappear.


    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < BarsRequired)
    return;

    if(BarsInProgress != 0) return;

    if (Rising (LinReg(BarsArray[0],4))
    && Rising (LinReg(BarsArray[0],9)))

    {
    DrawLine("SLup", false, 0, Low[0], 1, Low[0], upColor, DashStyle.Solid, 2);
    }

    if
    (
    (Falling(LinReg(BarsArray[0],4)))
    ||
    (Falling(LinReg(BarsArray[0],9)))
    )

    {
    RemoveDrawObject("SLup");
    }

    Do you have any advice?

    sandman

    #2
    Hello sandman,

    Thank you for writing in.

    RemoveDrawObject() will immediately remove the draw object when called.

    I do see that you have this within a condition. Have you added print statements to ensure that the condition is true?

    Additionally, as you want to check for these conditions intrabar, is your CalculateOnBarClose property set to false?

    As a test, are you able to see the diamond removed in the sample code below once a new bar closes?
    Code:
    protected override void Initialize()
    {
         CalculateOnBarClose = false;
    }
    
    private bool removed = false;
    
    protected override void OnBarUpdate()
    {
         if (Historical)
              return;
    
         if (!removed)
              DrawDiamond("diamond", true, 0, Close[0], Color.Blue);
    
         if (FirstTickOfBar)
         {
              RemoveDrawObject("diamond");
              removed = true;
         }
    }
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Resolved. Thank you Zachary.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X