Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 proptrade13, Today, 11:06 AM
      0 responses
      1 view
      0 likes
      Last Post proptrade13  
      Started by kulwinder73, Today, 10:31 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by RookieTrader, Today, 09:37 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by terofs, Yesterday, 04:18 PM
      1 response
      24 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by CommonWhale, Today, 09:55 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X