Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RemoveDrawObject Not Working

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

    RemoveDrawObject Not Working

    I am developing an indicator that looks for bars that have:

    Higher Highs, Higher Lows and Higher Closes or
    Lower Lows, Lower Highs and Lower Closes

    It mostly works, but on occasions it does not as highlighted in the attached image. It seems to initially mark the chart correctly but when the conditions change it should remove the indication until it becomes valid again.

    I've attached the code, but for the life of me can't figure out why its not removing the DrawObject when the conditions become invalid.

    Anyone have any ideas on how to fix this?

    tia

    taddypole...
    Attached Files

    #2
    Originally posted by Taddypole View Post
    I am developing an indicator that looks for bars that have:

    Higher Highs, Higher Lows and Higher Closes or
    Lower Lows, Lower Highs and Lower Closes

    It mostly works, but on occasions it does not as highlighted in the attached image. It seems to initially mark the chart correctly but when the conditions change it should remove the indication until it becomes valid again.

    I've attached the code, but for the life of me can't figure out why its not removing the DrawObject when the conditions become invalid.

    Anyone have any ideas on how to fix this?

    tia

    taddypole...
    Code:
    The draw object that you are removing is not the same as the draw object that you are creating. Taking you DownBar as a case in point, look at the [COLOR="Red"]red[/COLOR] text that I have highlighted.
    
    			if (Close[0] > Close[1] && Low[0] > Low[1] && High[0] > High[1])
    			{
    				DrawText([COLOR="red"]"ObviousDownBar" + CurrentBar[/COLOR], true, "M", 0, Low[0] - 1 * TickSize, 0, Color.White, ObviousBar, StringAlignment.Center, Color.Transparent, Color.Black, 0);
    			}
    			else
    			RemoveDrawObject([COLOR="red"]"ObviousDownBar"[/COLOR]);

    Comment


      #3
      taddypole, as koganam has observed, you are not removing the same draw object. You need to keep track of the bars the objects are on and then remove those draw objects from those bars. If you only want the most recent draw object shown, you can draw with "ObviousDownBar" minus the current bar and then it would be removed by your existing code.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Thank you both for that. It works as expected if I put:

        RemoveDrawObject("ObviousDownBar" + CurrentBar);

        But another question.

        I was doing research on the forum and found others used this:

        RemoveDrawObject("ObviousDownBar" + CurrentBar.ToString());

        Are they both correct? and do they yield the same results?
        If not, what is the difference?

        Thanks...

        taddypole...

        Comment


          #5
          Taddypole, they are both correct. CurrentBar is automatically converted to a string in the first instance, which would make it exactly the same as the second instance.
          AustinNinjaTrader Customer Service

          Comment


            #6
            Thank you Austin,

            But now I have to ask, are there others that are automatically converted to string? If so, is this documented somewhere?

            Comment


              #7
              Hi TaddyPole,

              Unfortunately, there's no documentation on this. This is a C# feature (or nuance). Using the + operator from string to a different type does the ToString() conversion automatically.
              Last edited by NinjaTrader_RyanM1; 08-07-2011, 06:31 PM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thank you Ryan,

                That is useful information.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                590 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                342 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
                555 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