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 Brevo, Today, 01:45 AM
      0 responses
      2 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      3 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      238 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Started by oviejo, Today, 12:28 AM
      0 responses
      4 views
      0 likes
      Last Post oviejo
      by oviejo
       
      Working...
      X