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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      129 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      74 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      116 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      111 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      89 views
      0 likes
      Last Post CarlTrading  
      Working...
      X